ev3_drivebase/lib.rs
1//! # ev3-drivebase
2//!
3//! A high-level `DriveBase` abstraction for LEGO Mindstorms EV3 robots running ev3dev.
4//!
5//! This crate provides an easy-to-use interface for controlling a two-wheeled robot,
6//! similar to the `DriveBase` classes found in the Python and `MicroPython` ev3dev libraries.
7//!
8//! ## Features
9//!
10//! - **Simple movement control**: Drive forward/backward and turn with precise distance and angle control
11//! - **Configurable brake modes**: Choose between Coast, Brake, and Hold modes
12//! - **Acceleration control**: Set custom acceleration and deceleration rates
13//! - **Color sensor support**: Optional integration with color sensors for line following
14//! - **Type-safe API**: Leverage Rust's type system for safer robot control
15//!
16//! ## Quick Start
17//!
18//! ```no_run
19//! use ev3_drivebase::{DriveBase, Motor, Direction, BrakeMode};
20//! use ev3_drivebase::ev3dev_lang_rust::{Ev3Error, motors::MotorPort};
21//!
22//! fn main() -> Result<(), Ev3Error> {
23//! // Define motor configuration
24//! let left = Motor::new(MotorPort::OutA, Direction::Clockwise);
25//! let right = Motor::new(MotorPort::OutB, Direction::CounterClockwise);
26//!
27//! // Create drivebase with wheel diameter (43.2mm) and axle track (185mm)
28//! let mut drivebase = DriveBase::new(left, right, 43.2, 185.0)?;
29//!
30//! // Configure behavior
31//! drivebase
32//! .set_brake_mode(BrakeMode::Hold)?
33//! .set_acceleration(4000)?
34//! .set_deceleration(4000)?;
35//!
36//! // Drive 500mm forward at 100 deg/s
37//! drivebase.drive(100, 500, true)?;
38//!
39//! // Turn 90 degrees in place
40//! drivebase.turn(200, 90, None)?;
41//!
42//! Ok(())
43//! }
44//! ```
45//!
46//! ## Motor Direction
47//!
48//! When creating a `DriveBase`, you need to specify the direction each motor should turn
49//! to make the robot move forward. This depends on how your motors are mounted:
50//!
51//! - If the motor shaft points toward the front of the robot, use `Direction::Clockwise`
52//! - If the motor shaft points toward the back of the robot, use `Direction::CounterClockwise`
53//!
54//! ## Units
55//!
56//! - **Distances**: millimeters (mm)
57//! - **Speeds**: degrees per second (deg/s)
58//! - **Angles**: degrees
59//! - **Acceleration/Deceleration**: degrees per second squared (deg/s²)
60//!
61//! ## Color Sensors
62//!
63//! You can optionally add color sensors to the drivebase for line following applications:
64//!
65//! ```no_run
66//! # use ev3_drivebase::{DriveBase, Motor, Direction};
67//! # use ev3_drivebase::ev3dev_lang_rust::{Ev3Error, motors::MotorPort};
68//! use ev3_drivebase::ev3dev_lang_rust::sensors::{ColorSensor, SensorPort};
69//!
70//! # fn main() -> Result<(), Ev3Error> {
71//! # let left = Motor::new(MotorPort::OutA, Direction::Clockwise);
72//! # let right = Motor::new(MotorPort::OutB, Direction::CounterClockwise);
73//! # let mut drivebase = DriveBase::new(left, right, 43.2, 185.0)?;
74//! let left_sensor = ColorSensor::get(SensorPort::In1)?;
75//! let right_sensor = ColorSensor::get(SensorPort::In2)?;
76//!
77//! drivebase.add_colorsensor(left_sensor, right_sensor);
78//! # Ok(())
79//! # }
80//! ```
81
82mod drivebase;
83mod motor;
84
85pub use drivebase::{BrakeMode, DriveBase};
86pub use ev3dev_lang_rust;
87pub use motor::{Direction, Motor};