This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from pros-rs/state
feat: add functions for checking robot state
- Loading branch information
Showing
5 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// Get the robot's battery capacity. | ||
pub fn get_capacity() -> f64 { | ||
unsafe { pros_sys::misc::battery_get_capacity() } | ||
} | ||
|
||
/// Get the electric current of the robot's battery. | ||
pub fn get_current() -> i32 { | ||
unsafe { pros_sys::misc::battery_get_current() } | ||
} | ||
|
||
/// Get the current temperature of the robot's battery. | ||
pub fn get_temperature() -> f64 { | ||
unsafe { pros_sys::misc::battery_get_temperature() } | ||
} | ||
|
||
/// Get the robot's battery voltage. | ||
pub fn get_voltage() -> i32 { | ||
unsafe { pros_sys::misc::battery_get_voltage() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// The current status of the robot, allowing checks to be made | ||
/// for autonomous, disabled, and connected states. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct CompetitionStatus(pub u8); | ||
|
||
impl CompetitionStatus { | ||
pub const fn autonomous(&self) -> bool { | ||
self.0 & pros_sys::misc::COMPETITION_AUTONOMOUS != 0 | ||
} | ||
pub const fn disabled(&self) -> bool { | ||
self.0 & pros_sys::misc::COMPETITION_DISABLED != 0 | ||
} | ||
pub const fn connected(&self) -> bool { | ||
self.0 & pros_sys::misc::COMPETITION_CONNECTED != 0 | ||
} | ||
} | ||
|
||
/// Get the current status of the robot. | ||
pub fn get_status() -> CompetitionStatus { | ||
CompetitionStatus(unsafe { pros_sys::misc::competition_get_status() }) | ||
} | ||
|
||
/// Check if the robot is in autonomous mode. | ||
pub fn is_autonomous() -> bool { | ||
unsafe { pros_sys::misc::competition_is_autonomous() } | ||
} | ||
|
||
/// Check if the robot is disabled. | ||
pub fn is_disabled() -> bool { | ||
unsafe { pros_sys::misc::competition_is_disabled() } | ||
} | ||
|
||
/// Check if the robot is connected to a VEX field or competition switch. | ||
pub fn is_connected() -> bool { | ||
unsafe { pros_sys::misc::competition_is_connected() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// Checks if an SD card is installed. | ||
pub fn usd_installed() -> bool { | ||
unsafe { pros_sys::misc::usd_is_installed() == 1 } | ||
} |