pros/
lib.rs

1//! # Pros
2//! Opinionated bindings for the PROS library and kernel.
3//! Not everything in this library is one to one with the PROS API.
4//!
5//! Advantages over similar libraries or PROS itself:
6//! - Pros-rs has an [`Async executor`](async_runtime) which allows for easy and performant asynchronous code.
7//! - Simulation support with [`pros-simulator`](https://crates.io/crates/pros-simulator) and any interface with it (e.g. [`pros-simulator-gui`](https://github.com/pros-rs/pros-simulator-gui))
8//! - Active development. Pros-rs is actively developed and maintained.
9//! - Pros-rs is a real crate on crates.io instead of a template, or similar. This allows for dependency management with cargo.
10//!
11//! # Usage
12//!
13//! When using pros, you have a few options for how you want to get started.
14//! You have two options: `async` and `sync`.
15//! When using async, an async executor is started and you can use it to run code asynchronously without any FreeRTOS tasks.
16//! When using sync, if you want to run code asynchronously you must create a FreeRTOS task.
17//!
18//! Here are some examples of both:
19//!
20//! ```rust
21//! // Async
22//! use pros::prelude::*;
23//!
24//! #[derive(Default)]
25//! struct Robot;
26//! impl AsyncRobot for Robot {
27//!    async fn opcontrol(&mut self) -> Result {
28//!       loop {
29//!         // Do something
30//!        sleep(Duration::from_millis(20)).await;
31//!       }
32//!    }
33//! }
34//! async_robot!(Robot);
35//! ```
36//!
37//!```rust
38//! // Sync
39//! use pros::prelude::*;
40//!
41//! #[derive(Default)]
42//! struct Robot;
43//! impl SyncRobot for Robot {
44//!   fn opcontrol(&mut self) -> Result {
45//!      loop {
46//!       // Do something
47//!      delay(Duration::from_millis(20));
48//!      }
49//!    }
50//! }
51//! sync_robot!(Robot);
52//! ```
53//!
54//! You may have noticed the `#[derive(Default)]` attribute on these Robot structs.
55//! If you want to learn why, look at the docs for [`pros_async::async_robot`] or [`pros_sync::sync_robot`].
56#![no_std]
57
58#[cfg(feature = "async")]
59pub use pros_async as async_runtime;
60#[cfg(feature = "core")]
61pub use pros_core as core;
62#[cfg(feature = "devices")]
63pub use pros_devices as devices;
64#[cfg(feature = "math")]
65pub use pros_math as math;
66#[cfg(feature = "panic")]
67pub use pros_panic as panic;
68#[cfg(feature = "sync")]
69pub use pros_sync as sync;
70pub use pros_sys as sys;
71
72/// Commonly used features of pros-rs.
73/// This module is meant to be glob imported.
74pub mod prelude {
75    #[cfg(feature = "async")]
76    pub use pros_async::{async_robot, block_on, sleep, spawn, AsyncRobot};
77    #[cfg(feature = "core")]
78    pub use pros_core::{
79        dbg, eprint, eprintln,
80        error::{PortError, Result},
81        io::{BufRead, Read, Seek, Write},
82        print, println,
83        task::delay,
84    };
85    #[cfg(feature = "devices")]
86    pub use pros_devices::{
87        adi::{
88            analog::AdiAnalogIn,
89            digital::{AdiDigitalIn, AdiDigitalOut},
90            encoder::AdiEncoder,
91            gyro::AdiGyro,
92            motor::AdiMotor,
93            potentiometer::{AdiPotentiometer, AdiPotentiometerType},
94            pwm::AdiPwmOut,
95            solenoid::AdiSolenoid,
96            ultrasonic::AdiUltrasonic,
97            AdiDevice, AdiPort,
98        },
99        color::Rgb,
100        controller::Controller,
101        peripherals::{DynamicPeripherals, Peripherals},
102        position::Position,
103        screen::{Circle, Line, Rect, Screen, Text, TextFormat, TextPosition, TouchState},
104        smart::{
105            distance::DistanceSensor,
106            expander::AdiExpander,
107            gps::GpsSensor,
108            imu::InertialSensor,
109            link::{Link, RxLink, TxLink},
110            motor::{BrakeMode, Direction, Gearset, Motor, MotorControl},
111            optical::OpticalSensor,
112            rotation::RotationSensor,
113            vision::VisionSensor,
114            SmartDevice, SmartPort,
115        },
116    };
117    #[cfg(feature = "math")]
118    pub use pros_math::{feedforward::MotorFeedforwardController, pid::PidController};
119    #[cfg(feature = "sync")]
120    pub use pros_sync::{sync_robot, SyncRobot};
121}