cargo add moteus

moteus has long supported python and C++ client side libraries for commanding and monitoring controllers over a variety of CAN-FD transports. Given that I’m not completely behind the times, it is about time to add rust support to that list.

If you’re reading this, you probably don’t need to hear an elevator pitch for rust. If you have been under a rock for the last 5 years, it is a systems level language with a strong type system and focus on safety, i.e. many classes of memory errors or threading race conditions are hard if not impossible to make.

Now, you can interact with moteus controllers from your rust projects in the same way and with similar APIs as from python and C++, while gaining all the benefits of rust.

Usage

To get started:

cargo add moteus

Then, the most basic thing you could do would be to command a single device. Doing so looks like:

using moteus::{Blockingcontroller, command::PositionCommand}

// ...

let mut c = BlockingController::new(1)?;
c.set_stop()?;

loop {
  let result = ctrl.set_position(
    PositionCommand::new()
      .position(f32::NAN)
      .velocity(1.0)
      .accel_limit(0.5)
  )?;

  println!("Position: {}", result.position);

  thread::sleep(Duration::from_millis(10));
}

pi3hat

There is also a moteus-pi3hat crate, which allows the pi3hat to be used in a similar manner as with the python library. To use it, you just need to register the appropriate transport before performing any operations.

moteus_pi3hat::transport::register();

Documentation

You can use the rust client library to do nearly anything that you can do with the python or C++ library. If you want to find documentation, the moteus integration guide is a fine place to start:

Additionally, complete documentation can be found at docs.rs at the following URLs:

And a shorthand top level API reference can be found in the moteus documentation: