[wpilib] Add isTestEnabled and minor docs cleanup (#5172)

This commit is contained in:
Ryan Blue
2023-03-10 22:23:57 -05:00
committed by GitHub
parent e5c4c6b1a7
commit 32ec5b3f75
6 changed files with 69 additions and 19 deletions

View File

@@ -484,6 +484,12 @@ bool DriverStation::IsTest() {
return controlWord.test;
}
bool DriverStation::IsTestEnabled() {
HAL_ControlWord controlWord;
HAL_GetControlWord(&controlWord);
return controlWord.test && controlWord.enabled;
}
bool DriverStation::IsDSAttached() {
HAL_ControlWord controlWord;
HAL_GetControlWord(&controlWord);

View File

@@ -210,6 +210,10 @@ bool RobotBase::IsTest() const {
return DriverStation::IsTest();
}
bool RobotBase::IsTestEnabled() const {
return DriverStation::IsTestEnabled();
}
std::thread::id RobotBase::GetThreadId() {
return m_threadId;
}

View File

@@ -209,6 +209,14 @@ class DriverStation final {
*/
static bool IsTest();
/**
* Check if the DS is commanding Test mode and if it has enabled the robot.
*
* @return True if the robot is being commanded to be in Test mode and
* enabled.
*/
static bool IsTestEnabled();
/**
* Check if the DS is attached.
*

View File

@@ -129,14 +129,14 @@ class RobotBase {
/**
* Determine if the Robot is currently enabled.
*
* @return True if the Robot is currently enabled by the field controls.
* @return True if the Robot is currently enabled by the Driver Station.
*/
bool IsEnabled() const;
/**
* Determine if the Robot is currently disabled.
*
* @return True if the Robot is currently disabled by the field controls.
* @return True if the Robot is currently disabled by the Driver Station.
*/
bool IsDisabled() const;
@@ -144,7 +144,7 @@ class RobotBase {
* Determine if the robot is currently in Autonomous mode.
*
* @return True if the robot is currently operating Autonomously as determined
* by the field controls.
* by the Driver Station.
*/
bool IsAutonomous() const;
@@ -152,7 +152,7 @@ class RobotBase {
* 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.
* as determined by the Driver Station.
*/
bool IsAutonomousEnabled() const;
@@ -160,7 +160,7 @@ class RobotBase {
* Determine if the robot is currently in Operator Control mode.
*
* @return True if the robot is currently operating in Tele-Op mode as
* determined by the field controls.
* determined by the Driver Station.
*/
bool IsTeleop() const;
@@ -168,18 +168,26 @@ class RobotBase {
* 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.
* enabled as determined by the Driver Station.
*/
bool IsTeleopEnabled() const;
/**
* Determine if the robot is currently in Test mode.
*
* @return True if the robot is currently running tests as determined by the
* field controls.
* @return True if the robot is currently running in Test mode as determined
* by the Driver Station.
*/
bool IsTest() const;
/**
* Determine if the robot is current in Test mode and enabled.
*
* @return True if the robot is currently operating in Test mode while
* enabled as determined by the Driver Station.
*/
bool IsTestEnabled() const;
/**
* Gets the ID of the main robot thread.
*/

View File

@@ -927,7 +927,7 @@ public final class DriverStation {
}
/**
* Gets a value indicating whether the Driver Station requires the robot to be running in test
* Gets a value indicating whether the Driver Station requires the robot to be running in Test
* mode.
*
* @return True if test mode should be enabled, false otherwise.
@@ -941,6 +941,21 @@ public final class DriverStation {
}
}
/**
* Gets a value indicating whether the Driver Station requires the robot to be running in Test
* mode and enabled.
*
* @return True if test mode should be set and the robot should be enabled.
*/
public static boolean isTestEnabled() {
m_cacheDataMutex.lock();
try {
return m_controlWord.getTest() && m_controlWord.getEnabled();
} finally {
m_cacheDataMutex.unlock();
}
}
/**
* Gets a value indicating whether the Driver Station is attached.
*

View File

@@ -216,7 +216,7 @@ public abstract class RobotBase implements AutoCloseable {
/**
* Determine if the Robot is currently disabled.
*
* @return True if the Robot is currently disabled by the field controls.
* @return True if the Robot is currently disabled by the Driver Station.
*/
public boolean isDisabled() {
return DriverStation.isDisabled();
@@ -225,14 +225,14 @@ public abstract class RobotBase implements AutoCloseable {
/**
* Determine if the Robot is currently enabled.
*
* @return True if the Robot is currently enabled by the field controls.
* @return True if the Robot is currently enabled by the Driver Station.
*/
public boolean isEnabled() {
return DriverStation.isEnabled();
}
/**
* Determine if the robot is currently in Autonomous mode as determined by the field controls.
* Determine if the robot is currently in Autonomous mode as determined by the Driver Station.
*
* @return True if the robot is currently operating Autonomously.
*/
@@ -241,8 +241,8 @@ public abstract class RobotBase implements AutoCloseable {
}
/**
* Determine if the robot is current in Autonomous mode and enabled as determined by the field
* controls.
* Determine if the robot is currently in Autonomous mode and enabled as determined by the Driver
* Station.
*
* @return True if the robot is currently operating autonomously while enabled.
*/
@@ -251,7 +251,7 @@ public abstract class RobotBase implements AutoCloseable {
}
/**
* Determine if the robot is currently in Test mode as determined by the driver station.
* Determine if the robot is currently in Test mode as determined by the Driver Station.
*
* @return True if the robot is currently operating in Test mode.
*/
@@ -260,8 +260,17 @@ public abstract class RobotBase implements AutoCloseable {
}
/**
* Determine if the robot is currently in Operator Control mode as determined by the field
* controls.
* Determine if the robot is current in Test mode and enabled as determined by the Driver Station.
*
* @return True if the robot is currently operating in Test mode while enabled.
*/
public boolean isTestEnabled() {
return DriverStation.isTestEnabled();
}
/**
* Determine if the robot is currently in Operator Control mode as determined by the Driver
* Station.
*
* @return True if the robot is currently operating in Tele-Op mode.
*/
@@ -270,8 +279,8 @@ public abstract class RobotBase implements AutoCloseable {
}
/**
* Determine if the robot is current in Operator Control mode and enabled as determined by the
* field controls.
* Determine if the robot is currently in Operator Control mode and enabled as determined by the
* Driver Station.
*
* @return True if the robot is currently operating in Tele-Op mode while enabled.
*/