From 32ec5b3f75be11ba9c6ddb1607bad3a398909a9c Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Fri, 10 Mar 2023 22:23:57 -0500 Subject: [PATCH] [wpilib] Add isTestEnabled and minor docs cleanup (#5172) --- wpilibc/src/main/native/cpp/DriverStation.cpp | 6 ++++ wpilibc/src/main/native/cppcs/RobotBase.cpp | 4 +++ .../main/native/include/frc/DriverStation.h | 8 +++++ .../src/main/native/include/frc/RobotBase.h | 24 ++++++++++----- .../edu/wpi/first/wpilibj/DriverStation.java | 17 ++++++++++- .../java/edu/wpi/first/wpilibj/RobotBase.java | 29 ++++++++++++------- 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/wpilibc/src/main/native/cpp/DriverStation.cpp b/wpilibc/src/main/native/cpp/DriverStation.cpp index aead3439af..daa57c956f 100644 --- a/wpilibc/src/main/native/cpp/DriverStation.cpp +++ b/wpilibc/src/main/native/cpp/DriverStation.cpp @@ -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); diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index 257c6e00fc..458aba6365 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -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; } diff --git a/wpilibc/src/main/native/include/frc/DriverStation.h b/wpilibc/src/main/native/include/frc/DriverStation.h index 99723d2335..28b1cce17a 100644 --- a/wpilibc/src/main/native/include/frc/DriverStation.h +++ b/wpilibc/src/main/native/include/frc/DriverStation.h @@ -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. * diff --git a/wpilibc/src/main/native/include/frc/RobotBase.h b/wpilibc/src/main/native/include/frc/RobotBase.h index 3ff4617f78..ca8b36e02c 100644 --- a/wpilibc/src/main/native/include/frc/RobotBase.h +++ b/wpilibc/src/main/native/include/frc/RobotBase.h @@ -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. */ diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index 035c754edd..abf0438ef9 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -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. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index 7a8d3bfb16..8b95f090db 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -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. */