Skip to main content

mecha10_drivers_motor/
lib.rs

1//! Motor Drivers for Mecha10
2//!
3//! This crate provides drivers for common motor types used in robotics:
4//! - **Dynamixel**: Smart servo motors (XL, XM, XH, XC series)
5//! - **ODrive**: High-power BLDC motor controller
6//! - **Stepper**: Stepper motors via Step/Dir interface
7//!
8//! # Features
9//!
10//! - Unified MotorDriver trait for all motor types
11//! - Position, velocity, and torque control modes
12//! - Multi-motor synchronized control
13//! - Calibration data persistence
14//! - Hardware error detection and reporting
15//! - Configurable PID gains
16//! - Temperature and current monitoring
17//!
18//! # Example
19//!
20//! ```rust,no_run
21//! use mecha10_drivers_motor::dynamixel::{DynamixelDriver, DynamixelConfig};
22//! use mecha10_drivers_motor::common::{MotorDriver, MotorCommand, ControlMode};
23//!
24//! #[tokio::main]
25//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
26//!     let config = DynamixelConfig {
27//!         port: "/dev/ttyUSB0".to_string(),
28//!         baud_rate: 1_000_000,
29//!         motor_ids: vec![1, 2, 3],
30//!         control_mode: ControlMode::Position,
31//!         update_rate_hz: 100.0,
32//!         calibration_file: None,
33//!         position_pid: None,
34//!         velocity_pid: None,
35//!     };
36//!
37//!     let mut driver = DynamixelDriver::new(config);
38//!     driver.init().await?;
39//!
40//!     // Send position command
41//!     let cmd = MotorCommand {
42//!         motor_id: 1,
43//!         mode: ControlMode::Position,
44//!         target: 1.57, // 90 degrees in radians
45//!         velocity_limit: None,
46//!         torque_limit: None,
47//!         profile_velocity: None,
48//!         profile_acceleration: None,
49//!     };
50//!
51//!     driver.send_command(&cmd).await?;
52//!
53//!     Ok(())
54//! }
55//! ```
56//!
57//! # Hardware Setup
58//!
59//! ## Dynamixel Wiring
60//! ```text
61//! Dynamixel Chain:
62//! USB2Dynamixel or U2D2 → Dynamixel servo(s) in daisy chain
63//!
64//! Power: 12V (XL series) or 12-24V (XM/XH series)
65//! Communication: TTL (3-pin) or RS-485 (4-pin)
66//! ```
67//!
68//! ## ODrive Wiring
69//! ```text
70//! ODrive Controller:
71//! - Motor phase wires (3-phase)
72//! - Encoder wires (Hall or quadrature)
73//! - Power: 12-56V DC
74//! - USB or UART for communication
75//! ```
76//!
77//! ## Stepper Wiring
78//! ```text
79//! Stepper Driver (DRV8825/A4988):
80//! - Step, Dir, Enable pins
81//! - Motor coil wires (typically 4-wire bipolar)
82//! - Power: depends on motor voltage rating
83//! ```
84
85pub mod common;
86pub mod dynamixel;
87pub mod l298n;
88pub mod odrive;
89pub mod stepper;
90
91pub use common::{
92    ControlMode, MotorCalibration, MotorCommand, MotorDriver, MotorError, MotorInfo, MotorState, MultiMotorCommand,
93    PIDGains,
94};
95
96pub use dynamixel::{DynamixelConfig, DynamixelDriver};
97pub use l298n::{L298NConfig, L298NDriver, L298NMotorPins};
98pub use odrive::{ODriveConfig, ODriveDriver};
99pub use stepper::{StepperConfig, StepperDriver, StepperInterface, StepperMotorConfig};