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, SensorPort, 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).await?;
20//! let right_motor = Motor::new(MotorPort::OutD, Direction::Clockwise).await?;
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().await?);
26//!
27//! let drive = DriveBase::new(&left_motor, &right_motor, 62.4, 130.5).await?.with_gyro(&gyro_sensor).await?;
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::Ev3Result;
47//! use ev3dev_rs::pupdevices::{GyroSensor, Motor};
48//! use ev3dev_rs::robotics::DriveBase;
49//! use ev3dev_rs::parameters::{Direction, MotorPort, SensorPort };
50//!
51//! #[tokio::main]
52//! async fn main() -> Ev3Result<()> {
53//!
54//! let left_motor = Motor::new(MotorPort::OutA, Direction::Clockwise).await?;
55//! let right_motor = Motor::new(MotorPort::OutD, Direction::Clockwise).await?;
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_motor, &right_motor, 62.4, 130.5).await?.with_gyro(&gyro_sensor).await?;
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//! # Async functions
75//!
76//! Because all the `Motor` and `DriveBase` actions are async, you can run them simultaneously.
77//!
78//! ```no_run
79//! extern crate ev3dev_rs;
80//! extern crate tokio;
81//!
82//! use ev3dev_rs::pupdevices::{GyroSensor, Motor, ColorSensor};
83//! use ev3dev_rs::robotics::DriveBase;
84//! use ev3dev_rs::parameters::{MotorPort, SensorPort, Direction};
85//! use ev3dev_rs::{join, select, Ev3Result};
86//!
87//! #[tokio::main]
88//! async fn main() -> Ev3Result<()> {
89//!
90//! let left_motor = Motor::new(MotorPort::OutA, Direction::Clockwise).await?;
91//! let right_motor = Motor::new(MotorPort::OutD, Direction::Clockwise).await?;
92//!
93//! let attachment_motor = Motor::new(MotorPort::OutB, Direction::Clockwise).await?;
94//!
95//! let gyro_sensor = GyroSensor::new(SensorPort::In1)?;
96//!
97//! // find_calibrated_axle_track requires a mutable reference
98//! let drive = DriveBase::new(&left_motor, &right_motor, 62.4, 130.5).await?.with_gyro(&gyro_sensor).await?;
99//!
100//! drive.use_gyro(true)?;
101//!
102//! // join is like pybricks' non-racing multitask
103//! // it will wait for all actions to complete before moving on
104//! // if any task returns an error, join will return that error
105//! join!(drive.straight(100), attachment_motor.run_until_stalled(-45))?;
106//!
107//! // select is like pybricks' racing multitask
108//! // once one action completes, the other(s) will be canceled
109//! select!(drive.turn(90), attachment_motor.run_until_stalled(45))?;
110//!
111//! Ok(())
112//! }
113//! ```
114
115mod attribute;
116mod enum_string;
117mod error;
118mod motor_driver;
119/// Parameters used in the ev3dev_rs crate.
120pub mod parameters;
121mod pid;
122/// Devices that can connect to the robot.
123pub mod pupdevices;
124/// Higher level abstractions.
125pub mod robotics;
126mod sensor_driver;
127/// Additional tools.
128pub mod tools;
129
130pub use error::{Ev3Error, Ev3Result};
131
132#[doc(hidden)]
133pub use futures_concurrency::future::Race;