[wpilib] Add methods to check game and enabled state together (#2661)

This avoids users having to call both IsOperatorControl() and IsEnabled() to figure out if their robot is
enabled and in the teleop state. The expression above involves calling two methods that each have their
own lock.

These new methods should only involve locking one mutex, since only one call is made to HAL_GetControlWord().
This commit is contained in:
Prateek Machiraju
2020-08-29 16:32:19 -04:00
committed by GitHub
parent 5d1220e629
commit 526f26685d
8 changed files with 106 additions and 6 deletions

View File

@@ -211,6 +211,15 @@ class DriverStation : public ErrorBase {
*/
bool IsAutonomous() const;
/**
* Check if the DS is commanding autonomous mode and if it has enabled the
* robot.
*
* @return True if the robot is being commanded to be in autonomous mode and
* enabled.
*/
bool IsAutonomousEnabled() const;
/**
* Check if the DS is commanding teleop mode.
*
@@ -218,6 +227,14 @@ class DriverStation : public ErrorBase {
*/
bool IsOperatorControl() const;
/**
* Check if the DS is commanding teleop mode and if it has enabled the robot.
*
* @return True if the robot is being commanded to be in teleop mode and
* enabled.
*/
bool IsOperatorControlEnabled() const;
/**
* Check if the DS is commanding test mode.
*

View File

@@ -133,6 +133,14 @@ class RobotBase {
*/
bool IsAutonomous() const;
/**
* Determine if the robot is currently in Autonomous mode and enabled.
*
* @return True if the robot us currently operating Autonomously while enabled
* as determined by the field controls.
*/
bool IsAutonomousEnabled() const;
/**
* Determine if the robot is currently in Operator Control mode.
*
@@ -141,6 +149,14 @@ class RobotBase {
*/
bool IsOperatorControl() const;
/**
* Determine if the robot is current in Operator Control mode and enabled.
*
* @return True if the robot is currently operating in Tele-Op mode while
* wnabled as determined by the field-controls.
*/
bool IsOperatorControlEnabled() const;
/**
* Determine if the robot is currently in Test mode.
*