[wpilib] Rename DriverStation::IsOperatorControl() to IsTeleop() (#3505)

This commit is contained in:
Tyler Veness
2021-08-11 23:04:43 -07:00
committed by GitHub
parent e80f09f849
commit 25f6f478a5
12 changed files with 162 additions and 18 deletions

View File

@@ -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;
}

View File

@@ -21,7 +21,11 @@ bool RobotState::IsEStopped() {
}
bool RobotState::IsOperatorControl() {
return DriverStation::IsOperatorControl();
return IsTeleop();
}
bool RobotState::IsTeleop() {
return DriverStation::IsTeleop();
}
bool RobotState::IsAutonomous() {

View File

@@ -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 {

View File

@@ -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.

View File

@@ -11,6 +11,7 @@
#include <hal/HALBase.h>
#include <hal/Main.h>
#include <wpi/condition_variable.h>
#include <wpi/deprecated.h>
#include <wpi/mutex.h>
#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.

View File

@@ -4,6 +4,8 @@
#pragma once
#include <wpi/deprecated.h>
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();
};

View File

@@ -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();
}
}

View File

@@ -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.

View File

@@ -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();
}
/**

View File

@@ -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() {

View File

@@ -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();
}
}

View File

@@ -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();
}
}