diff --git a/wpilibc/src/main/native/cpp/DriverStation.cpp b/wpilibc/src/main/native/cpp/DriverStation.cpp index f5939b0b89..078428341c 100644 --- a/wpilibc/src/main/native/cpp/DriverStation.cpp +++ b/wpilibc/src/main/native/cpp/DriverStation.cpp @@ -462,12 +462,20 @@ bool DriverStation::IsAutonomousEnabled() { } bool DriverStation::IsOperatorControl() { + return IsTeleop(); +} + +bool DriverStation::IsTeleop() { HAL_ControlWord controlWord; HAL_GetControlWord(&controlWord); return !(controlWord.autonomous || controlWord.test); } bool DriverStation::IsOperatorControlEnabled() { + return IsTeleopEnabled(); +} + +bool DriverStation::IsTeleopEnabled() { HAL_ControlWord controlWord; HAL_GetControlWord(&controlWord); return !controlWord.autonomous && !controlWord.test && controlWord.enabled; @@ -621,6 +629,10 @@ void DriverStation::InAutonomous(bool entering) { } void DriverStation::InOperatorControl(bool entering) { + InTeleop(entering); +} + +void DriverStation::InTeleop(bool entering) { ::GetInstance().userInTeleop = entering; } diff --git a/wpilibc/src/main/native/cpp/RobotState.cpp b/wpilibc/src/main/native/cpp/RobotState.cpp index c2d251b627..651a6445fe 100644 --- a/wpilibc/src/main/native/cpp/RobotState.cpp +++ b/wpilibc/src/main/native/cpp/RobotState.cpp @@ -21,7 +21,11 @@ bool RobotState::IsEStopped() { } bool RobotState::IsOperatorControl() { - return DriverStation::IsOperatorControl(); + return IsTeleop(); +} + +bool RobotState::IsTeleop() { + return DriverStation::IsTeleop(); } bool RobotState::IsAutonomous() { diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index 6d09fbdb56..5471277c3a 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -179,11 +179,19 @@ bool RobotBase::IsAutonomousEnabled() const { } bool RobotBase::IsOperatorControl() const { - return DriverStation::IsOperatorControl(); + return DriverStation::IsTeleop(); +} + +bool RobotBase::IsTeleop() const { + return DriverStation::IsTeleop(); } bool RobotBase::IsOperatorControlEnabled() const { - return DriverStation::IsOperatorControlEnabled(); + return DriverStation::IsTeleopEnabled(); +} + +bool RobotBase::IsTeleopEnabled() const { + return DriverStation::IsTeleopEnabled(); } bool RobotBase::IsTest() const { diff --git a/wpilibc/src/main/native/include/frc/DriverStation.h b/wpilibc/src/main/native/include/frc/DriverStation.h index 08f4cda302..d82175b9d7 100644 --- a/wpilibc/src/main/native/include/frc/DriverStation.h +++ b/wpilibc/src/main/native/include/frc/DriverStation.h @@ -195,16 +195,35 @@ class DriverStation { * Check if the DS is commanding teleop mode. * * @return True if the robot is being commanded to be in teleop mode + * @deprecated Use IsTeleop() instead. */ + WPI_DEPRECATED("Use IsTeleop() instead") static bool IsOperatorControl(); + /** + * Check if the DS is commanding teleop mode. + * + * @return True if the robot is being commanded to be in teleop mode + */ + static bool IsTeleop(); + + /** + * 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. + * @deprecated Use IsTeleopEnabled() instead. + */ + WPI_DEPRECATED("Use IsTeleopEnabled() instead") + static bool IsOperatorControlEnabled(); + /** * 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. */ - static bool IsOperatorControlEnabled(); + static bool IsTeleopEnabled(); /** * Check if the DS is commanding test mode. @@ -377,9 +396,20 @@ class DriverStation { * * @param entering If true, starting teleop code; if false, leaving teleop * code. + * @deprecated Use InTeleop() instead. */ + WPI_DEPRECATED("Use InTeleop() instead") static void InOperatorControl(bool entering); + /** + * Only to be used to tell the Driver Station what code you claim to be + * executing for diagnostic purposes only. + * + * @param entering If true, starting teleop code; if false, leaving teleop + * code. + */ + static void InTeleop(bool entering); + /** * Only to be used to tell the Driver Station what code you claim to be * executing for diagnostic purposes only. diff --git a/wpilibc/src/main/native/include/frc/RobotBase.h b/wpilibc/src/main/native/include/frc/RobotBase.h index e3a366cbdf..b1fe4c8272 100644 --- a/wpilibc/src/main/native/include/frc/RobotBase.h +++ b/wpilibc/src/main/native/include/frc/RobotBase.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "frc/Errors.h" @@ -154,16 +155,36 @@ class RobotBase { * * @return True if the robot is currently operating in Tele-Op mode as * determined by the field controls. + * @deprecated Use IsTeleop() instead. */ + WPI_DEPRECATED("Use IsTeleop() instead") bool IsOperatorControl() const; + /** + * 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. + */ + bool IsTeleop() 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 + * enabled as determined by the field-controls. + * @deprecated Use IsTeleopEnabled() instead. + */ + WPI_DEPRECATED("Use IsTeleopEnabled() instead") + bool IsOperatorControlEnabled() 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; + bool IsTeleopEnabled() const; /** * Determine if the robot is currently in Test mode. diff --git a/wpilibc/src/main/native/include/frc/RobotState.h b/wpilibc/src/main/native/include/frc/RobotState.h index c1f9458078..cb97b133b1 100644 --- a/wpilibc/src/main/native/include/frc/RobotState.h +++ b/wpilibc/src/main/native/include/frc/RobotState.h @@ -4,6 +4,8 @@ #pragma once +#include + namespace frc { class RobotState { @@ -13,7 +15,9 @@ class RobotState { static bool IsDisabled(); static bool IsEnabled(); static bool IsEStopped(); + WPI_DEPRECATED("Use IsTeleop() instead") static bool IsOperatorControl(); + static bool IsTeleop(); static bool IsAutonomous(); static bool IsTest(); }; diff --git a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp index 12307ecb1f..29bae0bf1d 100644 --- a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp @@ -53,10 +53,10 @@ void Robot::StartCompetition() { frc::LiveWindow::SetEnabled(false); frc::Shuffleboard::DisableActuatorWidgets(); } else { - frc::DriverStation::InOperatorControl(true); + frc::DriverStation::InTeleop(true); Teleop(); - frc::DriverStation::InOperatorControl(false); - while (IsOperatorControlEnabled()) { + frc::DriverStation::InTeleop(false); + while (IsTeleopEnabled()) { frc::DriverStation::WaitForData(); } } 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 ea14fd1aee..afd2393185 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -812,8 +812,20 @@ public class DriverStation { * operator-controlled mode. * * @return True if operator-controlled mode should be enabled, false otherwise. + * @deprecated Use isTeleop() instead. */ + @Deprecated(since = "2022", forRemoval = true) public static boolean isOperatorControl() { + return isTeleop(); + } + + /** + * Gets a value indicating whether the Driver Station requires the robot to be running in + * operator-controlled mode. + * + * @return True if operator-controlled mode should be enabled, false otherwise. + */ + public static boolean isTeleop() { return !(isAutonomous() || isTest()); } @@ -822,8 +834,20 @@ public class DriverStation { * operator-controller mode and enabled. * * @return True if operator-controlled mode should be set and the robot should be enabled. + * @deprecated Use isTeleopEnabled() instead. */ + @Deprecated(since = "2022", forRemoval = true) public static boolean isOperatorControlEnabled() { + return isTeleopEnabled(); + } + + /** + * Gets a value indicating whether the Driver Station requires the robot to be running in + * operator-controller mode and enabled. + * + * @return True if operator-controlled mode should be set and the robot should be enabled. + */ + public static boolean isTeleopEnabled() { synchronized (m_controlWordMutex) { updateControlWord(false); return !m_controlWordCache.getAutonomous() @@ -1124,11 +1148,23 @@ public class DriverStation { * purposes only. * * @param entering If true, starting teleop code; if false, leaving teleop code + * @deprecated Use {@link #inTeleop(boolean)} instead. */ + @Deprecated(since = "2022", forRemoval = true) public static void inOperatorControl(boolean entering) { m_userInTeleop = entering; } + /** + * Only to be used to tell the Driver Station what code you claim to be executing for diagnostic + * purposes only. + * + * @param entering If true, starting teleop code; if false, leaving teleop code + */ + public static void inTeleop(boolean entering) { + m_userInTeleop = entering; + } + /** * Only to be used to tell the Driver Station what code you claim to be executing for diagnostic * purposes only. 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 96f55b6d32..6c4b39815d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -229,9 +229,33 @@ public abstract class RobotBase implements AutoCloseable { * controls. * * @return True if the robot is currently operating in Tele-Op mode. + * @deprecated Use isTeleop() instead. */ + @Deprecated(since = "2022", forRemoval = true) public boolean isOperatorControl() { - return DriverStation.isOperatorControl(); + return DriverStation.isTeleop(); + } + + /** + * Determine if the robot is currently in Operator Control mode as determined by the field + * controls. + * + * @return True if the robot is currently operating in Tele-Op mode. + */ + public boolean isTeleop() { + return DriverStation.isTeleop(); + } + + /** + * Determine if the robot is current in Operator Control mode and enabled as determined by the + * field controls. + * + * @return True if the robot is currently operating in Tele-Op mode while enabled. + * @deprecated Use isTeleopEnabled() instead. + */ + @Deprecated(since = "2022", forRemoval = true) + public boolean isOperatorControlEnabled() { + return DriverStation.isTeleopEnabled(); } /** @@ -240,8 +264,8 @@ public abstract class RobotBase implements AutoCloseable { * * @return True if the robot is currently operating in Tele-Op mode while enabled. */ - public boolean isOperatorControlEnabled() { - return DriverStation.isOperatorControlEnabled(); + public boolean isTeleopEnabled() { + return DriverStation.isTeleopEnabled(); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java index d11e5bc977..462051a444 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotState.java @@ -18,8 +18,13 @@ public final class RobotState { return DriverStation.isEStopped(); } + @Deprecated public static boolean isOperatorControl() { - return DriverStation.isOperatorControl(); + return isTeleop(); + } + + public static boolean isTeleop() { + return DriverStation.isTeleop(); } public static boolean isAutonomous() { diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/educational/EducationalRobot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/educational/EducationalRobot.java index 61a4552ac8..76d13a4a89 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/educational/EducationalRobot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/educational/EducationalRobot.java @@ -60,10 +60,10 @@ public class EducationalRobot extends RobotBase { DriverStation.waitForData(); } } else { - DriverStation.inOperatorControl(true); + DriverStation.inTeleop(true); teleop(); - DriverStation.inOperatorControl(false); - while (isOperatorControlEnabled()) { + DriverStation.inTeleop(false); + while (isTeleopEnabled()) { DriverStation.waitForData(); } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java index 52b4657202..787395c941 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/robotbaseskeleton/Robot.java @@ -61,10 +61,10 @@ public class Robot extends RobotBase { LiveWindow.setEnabled(false); Shuffleboard.disableActuatorWidgets(); } else { - DriverStation.inOperatorControl(true); + DriverStation.inTeleop(true); teleop(); - DriverStation.inOperatorControl(false); - while (isOperatorControlEnabled()) { + DriverStation.inTeleop(false); + while (isTeleopEnabled()) { DriverStation.waitForData(); } }