piglet_client 0.1.0

A bare-bones client for controlling IP-based Hamilton robots
Documentation

piglet

piglet is a Rust library designed to control IP-based Hamilton robots.

Compatibility

While piglet has been primarily tested with a Nimbus HD (2021), it is easily extendable to the ML Prep and other variants of the Nimbus platform. STAR and Vantage robots are significantly different and fall outside the current scope of this project.

Current state

  • Test extensively and flesh out the missing pieces
  • Add support for other Nimbuses
  • Add support for ML Prep
  • Add support for discovering robots on the network
  • Learn Rust

Example usage

use piglet::RobotClient;
use piglet::nimbus_hd_1_0::{
    nimbus_core::NimbusCore, nimbus_core_door_lock::NimbusCoreDoorLock,
    nimbus_core_hd_deck::NimbusCoreHdDeck, nimbus_core_pipette::NimbusCorePipette,
};
use std::env;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        anyhow::bail!("Usage: {} <ip>", args[0]);
    }

    println!("Connecting to {}...", args[1]);
    let robot = Arc::new(RobotClient::connect(&args[1]).await?);
    let core = NimbusCore::new(&robot);
    let deck = NimbusCoreHdDeck::new(&robot);
    let pipette = NimbusCorePipette::new(&robot);
    let lock = NimbusCoreDoorLock::new(&robot);

    lock.lock_door().await?;
    core.method_begin().await?;
    println!("{:?}", deck.get_track_sensor_states().await?);
    println!("{:?}", pipette.get_tip_and_needle_types().await?);
    for channel in range 1..9 {
        pipette
            .set_channel_configuration(channel, vec![1, 3, 4], vec![true, false, false])
            .await?;
    }
    pipette
        .move_to_position(
            vec![1, 1, 1, 1, 1, 1, 1, 1],
            -5849,
            vec![-161, -4558, -8955, -13352, -17749, -22146, -26543, -30940],
            vec![14600, 14600, 14600, 14600, 14600, 14600, 14600, 14600],
        )
        .await?;
    lock.unlock_door().await?;
    Ok(())
}

Generating robot APIs

Hamilton robots offer an introspection API that allows for dynamic discovery of all available calls. The piglet_codegen tool leverages this to generate type-safe Rust code for any robot it's pointed at.

For example, the piglet_generated/src/nimbus_hd_1_0 folder was generated by pointing the generator at our Nimbus's IP address.

To generate API bindings:

  1. Build piglet_codegen:
    cargo build --release --bin piglet_codegen
    
  2. Run the generator: Point it to your robot's IP address and specify a module name
    ./target/release/piglet_codegen <robot ip and port> <module name>
    

As an example, the piglet_generated/src/nimbus_hd_1_0 folder in this repository was generated from our Nimbus HD by running piglet_codegen 172.31.255.3:2000 nimbus_hd_1_0