Skip to main content

robot_control/
lib.rs

1//! # Robot Control
2//!
3//! A Rust library for controlling DC motor robots via PWM motor driver boards.
4//!
5//! This crate provides a hardware-abstracted [`MotorDriver`] trait, allowing you to
6//! control robots in production (with real I2C hardware) and in tests (with a mock driver).
7//!
8//! ## Features
9//!
10//! - **`pca9685`** — Enables the `Pca9685MotorBoard`
11//!   implementation for PCA9685 PWM boards over I2C. Only available on Linux with I2C support.
12//!
13//! ## Quick Start
14//!
15//! ```rust,no_run
16//! use robot_control::{Motor, MotorDriver, Robot, RobotConfig};
17//! use std::sync::Arc;
18//! use tokio::sync::Mutex;
19//!
20//! # async fn example() -> Result<(), robot_control::RobotError> {
21//! // Use any MotorDriver implementation (mock for testing, Pca9685 for real hardware)
22//! let driver: Arc<Mutex<dyn MotorDriver>> = todo!("create your driver");
23//! let robot = Robot::new(driver, RobotConfig::default())?;
24//! robot.drive(0.5, 0.5).await?;
25//! robot.stop().await?;
26//! robot.shutdown().await;
27//! # Ok(())
28//! # }
29//! ```
30
31#![forbid(unsafe_code)]
32
33pub mod error;
34pub mod motor;
35#[cfg(feature = "pca9685")]
36pub mod pca9685;
37pub mod robot;
38
39pub use error::{MotorError, RobotError};
40pub use motor::{Motor, MotorDriver};
41#[cfg(feature = "pca9685")]
42pub use pca9685::Pca9685MotorBoard;
43pub use robot::{Robot, RobotConfig, RobotOutputState, RobotPhase, RobotStatus};
44
45#[cfg(test)]
46pub mod mock;