Expand description
Motor Drivers for Mecha10
This crate provides drivers for common motor types used in robotics:
- Dynamixel: Smart servo motors (XL, XM, XH, XC series)
- ODrive: High-power BLDC motor controller
- Stepper: Stepper motors via Step/Dir interface
§Features
- Unified MotorDriver trait for all motor types
- Position, velocity, and torque control modes
- Multi-motor synchronized control
- Calibration data persistence
- Hardware error detection and reporting
- Configurable PID gains
- Temperature and current monitoring
§Example
use mecha10_drivers_motor::dynamixel::{DynamixelDriver, DynamixelConfig};
use mecha10_drivers_motor::common::{MotorDriver, MotorCommand, ControlMode};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = DynamixelConfig {
port: "/dev/ttyUSB0".to_string(),
baud_rate: 1_000_000,
motor_ids: vec![1, 2, 3],
control_mode: ControlMode::Position,
update_rate_hz: 100.0,
calibration_file: None,
position_pid: None,
velocity_pid: None,
};
let mut driver = DynamixelDriver::new(config);
driver.init().await?;
// Send position command
let cmd = MotorCommand {
motor_id: 1,
mode: ControlMode::Position,
target: 1.57, // 90 degrees in radians
velocity_limit: None,
torque_limit: None,
profile_velocity: None,
profile_acceleration: None,
};
driver.send_command(&cmd).await?;
Ok(())
}§Hardware Setup
§Dynamixel Wiring
Dynamixel Chain:
USB2Dynamixel or U2D2 → Dynamixel servo(s) in daisy chain
Power: 12V (XL series) or 12-24V (XM/XH series)
Communication: TTL (3-pin) or RS-485 (4-pin)§ODrive Wiring
ODrive Controller:
- Motor phase wires (3-phase)
- Encoder wires (Hall or quadrature)
- Power: 12-56V DC
- USB or UART for communication§Stepper Wiring
Stepper Driver (DRV8825/A4988):
- Step, Dir, Enable pins
- Motor coil wires (typically 4-wire bipolar)
- Power: depends on motor voltage ratingRe-exports§
pub use common::ControlMode;pub use common::MotorCalibration;pub use common::MotorCommand;pub use common::MotorDriver;pub use common::MotorError;pub use common::MotorInfo;pub use common::MotorState;pub use common::MultiMotorCommand;pub use common::PIDGains;pub use dynamixel::DynamixelConfig;pub use dynamixel::DynamixelDriver;pub use l298n::L298NConfig;pub use l298n::L298NDriver;pub use l298n::L298NMotorPins;pub use odrive::ODriveConfig;pub use odrive::ODriveDriver;pub use stepper::StepperConfig;pub use stepper::StepperDriver;pub use stepper::StepperInterface;pub use stepper::StepperMotorConfig;