ev3dev_rs/lib.rs
1#![deny(missing_docs)]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4//! # Basic usage
5//!
6//! ```no_run
7//! extern crate ev3dev_rs;
8//! extern crate tokio;
9//!
10//! use ev3dev_rs::Ev3Result;
11//! use ev3dev_rs::pupdevices::{GyroSensor, Motor, ColorSensor};
12//! use ev3dev_rs::robotics::DriveBase;
13//! use ev3dev_rs::parameters::{MotorPort, MotorPort, Direction}
14//!
15//! #[tokio::main]
16//! async fn main() -> Ev3Result<()> {
17//!
18//! use ev3dev_rs::parameters::{Direction, SensorPort};
19//! let left_motor = Motor::new(MotorPort::OutA, Direction::Clockwise)?;
20//! let right_motor = Motor::new(MotorPort::OutD, Direction::Clockwise)?;
21//!
22//! let gyro_sensor = GyroSensor::new(SensorPort::In1)?;
23//! let color_sensor = ColorSensor::new(SensorPort::In4)?;
24//!
25//! println!("Detected color: {}", color_sensor.color()?);
26//!
27//! let drive = DriveBase::new(&left_motor, &right_motor, 62.4, 130.5)?.with_gyro(&gyro_sensor)?;
28//!
29//! drive.use_gyro(true)?;
30//!
31//! drive.straight(500).await?;
32//! drive.turn(90).await?;
33//! drive.curve(600, 90).await?;
34//! drive.veer(600, 500).await?;
35//!
36//! Ok(())
37//! }
38//! ```
39//!
40//! # `DriveBase` calibration
41//!
42//! ```no_run
43//! extern crate ev3dev_rs;
44//! extern crate tokio;
45//!
46//! use ev3dev_rs::pupdevices::{GyroSensor, Motor, ColorSensor};
47//! use ev3dev_rs::robotics::DriveBase;
48//! use ev3dev_rs::parameters::{MotorPort, MotorPort}
49//!
50//! #[tokio::main]
51//! async fn main() -> Ev3Result<()> {
52//!
53//! use ev3dev_rs::parameters::{Direction, SensorPort};
54//! let left_motor = Motor::new(MotorPort::OutA, Direction::Clockwise)?;
55//! let right_motor = Motor::new(MotorPort::OutD, Direction::Clockwise)?;
56//!
57//! // A gyro sensor is required for calibration.
58//! let gyro_sensor = GyroSensor::new(SensorPort::In1)?;
59//!
60//! // find_calibrated_axle_track requires a mutable reference
61//! let mut drive = DriveBase::new(&left, &right, 62.4, 130.5)?.with_gyro(&gyro)?;
62//!
63//! drive.use_gyro(true)?;
64//!
65//! // This will test a bunch of axle tracks, compare them with the gyro, and report the optimal value.
66//! // Note that it is highly experimental and different surfaces may heavily affect the reported value.
67//! // If you have issues with drive wheel slippage, please see "set_ramp_up_setpoint".
68//! // Even if you perfectly dial this in, using the gyro is still highly recommended to get the most accurate readings.
69//! drive.find_calibrated_axle_track(50).await?;
70//!
71//! Ok(())
72//! }
73//! ```
74
75mod attribute;
76mod enum_string;
77mod error;
78mod motor_driver;
79/// Parameters used in the ev3dev_rs crate.
80pub mod parameters;
81mod pid;
82/// Devices that can connect to the robot.
83pub mod pupdevices;
84/// Higher level abstractions.
85pub mod robotics;
86mod sensor_driver;
87/// Additional tools.
88pub mod tools;
89
90pub use error::{Ev3Error, Ev3Result};