moteus
Rust client library for moteus brushless motor controllers.
This crate provides a high-level API for communicating with moteus controllers over CAN-FD. It supports multiple transport backends and automatic device discovery.
Crate Structure
This library is split into two crates:
- moteus-protocol: Low-level protocol encoding/decoding.
no_stdcompatible for embedded use. - moteus: High-level API with transport implementations for FdCanUSB and SocketCAN.
Quick Start - Auto-Discovery (Recommended)
The simplest way to use moteus is with automatic transport discovery:
use ;
Builder Pattern API
Commands are built using the builder pattern for clear, self-documenting code:
use PositionCommand;
// Simple position command
let cmd = new.position;
// Position with velocity
let cmd = new
.position
.velocity;
// Full control over all parameters
let cmd = new
.position
.velocity
.feedforward_torque
.kp_scale
.kd_scale
.maximum_torque;
Explicit Transport
For more control, you can specify a transport explicitly:
use ;
You can also build a [Router] over one or more explicit devices:
use ;
use SocketCanDevice;
Transport Options
Configure transport auto-detection with options:
use ;
use Duration;
Low-Level Protocol Access
For embedded or custom transport use cases, the moteus-protocol crate
can be used directly to construct and parse CAN-FD frames:
use ;
// Create a position command frame using builder pattern
let mut frame = new;
frame.arbitration_id = 0x8001; // dest=1, source=0
let cmd = new
.position
.velocity;
cmd.serialize;
// frame.data and frame.size now contain the encoded command
Controller Configuration
Use the builder pattern to configure controller settings:
use ;
use QueryFormat;
Query Format Overrides
You can override the query format on a per-call basis:
use CommandExt;
use PositionCommand;
use QueryFormat;
// Override query format for this specific call
let cmd = new
.position
.with_query;
Resolution Configuration
Control the resolution of commands and queries to optimize bandwidth:
use ;
use QueryFormat;
let mut ctrl = new;
// Customize query resolution
ctrl.query_format.position = Float;
ctrl.query_format.velocity = Float;
ctrl.query_format.torque = Int16;
Features
tokio: Async I/O transports andAsyncController(optional)clap: CLI argument parsing support (optional)
Supported Transports
- fdcanusb: USB-to-CAN adapter (serial CDC)
- SocketCAN: Linux kernel CAN interface
Building with Bazel
Versions prior to 0.5.0
Versions of this crate prior to 0.5.0 were developed independently by Omelia Iliffe. The source for those versions can be found at: https://github.com/omelia-iliffe/moteus-rs