Skip to main content

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