Skip to main content

Crate rustypot

Crate rustypot 

Source
Expand description

A low-level communication library for servo (Dynamixel and Feetech motors).

§Feature Overview

  • Relies on serialport for serial communication
  • Support for dynamixel protocol v1 and v2 (both can be used on the same io)
  • Support for sync read and sync write operations, plus fast sync read (protocol v2)
  • Easy support for new type of motors (register definition through macros)
  • Pure Rust

§APIs

It exposes three APIs, from the wire up:

  • DynamixelProtocolHandler: low-level API. It handles the serial communication and the Dynamixel protocol parsing. It can be used for fine-grained control of the shared bus with other communication.
  • Controller: one per servo model, with a typed accessor for each register. Simpler and cleaner API but it takes full ownership of the io (it can still be shared if wrapped with a mutex for instance).
  • bus::Bus and servo::ServoDefinition: a higher-level, family-agnostic API, designed mostly for the LeRobot library. Motors of several models and of both protocols on one port, registers by name, the facts about each servo, finding and setting up motors, and the torque of a whole bus. Some of its choices are LeRobot conventions rather than vendor rules; the controllers stay the per-servo API underneath.

See the examples below for usage.

§Examples

§With the low-level API

use rustypot::{DynamixelProtocolHandler, servo::dynamixel::mx};
use std::time::Duration;

let mut serial_port = serialport::new("/dev/ttyACM0", 1_000_000)
    .timeout(Duration::from_millis(10))
    .open()
    .expect("Failed to open port");

let dph = DynamixelProtocolHandler::v1();

let raw_pos: i16 = mx::read_raw_present_position(&dph, serial_port.as_mut(), 11).expect("Communication error");
let pos: f64 =
    mx::read_present_position(&dph, serial_port.as_mut(), 11).expect("Communication error");
println!("Motor 11 present position: {:?}rads (raw: {:?})", pos, raw_pos);

§With the high-level API

use rustypot::servo::feetech::sts3215::Sts3215Controller;
use std::time::Duration;

let serial_port = serialport::new("/dev/ttyUSB0", 1_000_000)
    .timeout(Duration::from_millis(1000))
    .open()
    .unwrap();

let mut c = Sts3215Controller::new()
        .with_protocol_v1()
        .with_serial_port(serial_port);

let pos = c.sync_read_present_position(&vec![1, 2]).unwrap();
println!("Motors present position: {:?}", pos);

c.sync_write_goal_position(&vec![1, 2], &vec![0.0, 90.0_f64.to_radians()]).unwrap();

Modules§

bus
Motors of several definitions, and of both protocols, on one serial port.
servo

Macros§

generate_addr_read_write
generate_protocol_constructor
generate_reg_access
generate_reg_read
generate_reg_write
generate_reg_write_fb
Generates write and sync_write functions with feedback for given register
generate_register_access
Integer access to registers chosen by name, for code that picks them at runtime.
generate_scan
A sweep of the bus: which ids answer, and what they are.
generate_servo
generate_special_instructions
register_access
Maps the access ident of a servo definition (r, w, rw) to a RegisterAccess.
register_encoding
Maps an encoding: entry of a servo definition (unsigned, twos_complement, sign_magnitude(bit)) to an Encoding.
register_servo

Structs§

DynamixelProtocolHandler
Raw dynamixel communication messages controller (protocol v1 or v2)
StatusError
The error field of a status packet.
StatusPacketError
A motor answered, and its status packet says it refused the instruction (see ServoDefinition::refuses): what it was asked to do did not happen. The status is kept raw, as in StatusError.
SyncReadError
A sync read that failed at one motor’s answer: which motor, and why.

Enums§

CommunicationErrorKind
Dynamixel Communication Error
DynamixelErrorV1