[hal,wpilib] Rename "Test" robot mode to "Utility" (#8782)

The "Utility" name better matches its intended generic use case and
avoids overloaded terminology with unit testing (e.g. the need to name
the opmode annotation `@TestOpMode`).

The driver station will also be updated to reflect this change.
This commit is contained in:
Peter Johnson
2026-04-20 20:29:25 -07:00
committed by GitHub
parent 14d14e4ebc
commit ab00aac960
111 changed files with 487 additions and 488 deletions

View File

@@ -29,7 +29,7 @@ void IterativeRobotBase::AutonomousInit() {}
void IterativeRobotBase::TeleopInit() {}
void IterativeRobotBase::TestInit() {}
void IterativeRobotBase::UtilityInit() {}
void IterativeRobotBase::RobotPeriodic() {
static bool firstRun = true;
@@ -71,7 +71,7 @@ void IterativeRobotBase::TeleopPeriodic() {
}
}
void IterativeRobotBase::TestPeriodic() {
void IterativeRobotBase::UtilityPeriodic() {
static bool firstRun = true;
if (firstRun) {
wpi::util::print("Default {}() method... Override me!\n", __FUNCTION__);
@@ -85,7 +85,7 @@ void IterativeRobotBase::AutonomousExit() {}
void IterativeRobotBase::TeleopExit() {}
void IterativeRobotBase::TestExit() {}
void IterativeRobotBase::UtilityExit() {}
wpi::units::second_t IterativeRobotBase::GetPeriod() const {
return m_period;
@@ -114,8 +114,8 @@ void IterativeRobotBase::LoopFunc() {
AutonomousExit();
} else if (m_lastMode == static_cast<int>(RobotMode::TELEOPERATED)) {
TeleopExit();
} else if (m_lastMode == static_cast<int>(RobotMode::TEST)) {
TestExit();
} else if (m_lastMode == static_cast<int>(RobotMode::UTILITY)) {
UtilityExit();
}
// Call current mode's entry function
@@ -128,9 +128,9 @@ void IterativeRobotBase::LoopFunc() {
} else if (mode == RobotMode::TELEOPERATED) {
TeleopInit();
m_watchdog.AddEpoch("TeleopInit()");
} else if (mode == RobotMode::TEST) {
TestInit();
m_watchdog.AddEpoch("TestInit()");
} else if (mode == RobotMode::UTILITY) {
UtilityInit();
m_watchdog.AddEpoch("UtilityInit()");
}
m_lastMode = static_cast<int>(mode);
@@ -147,9 +147,9 @@ void IterativeRobotBase::LoopFunc() {
} else if (mode == RobotMode::TELEOPERATED) {
TeleopPeriodic();
m_watchdog.AddEpoch("TeleopPeriodic()");
} else if (mode == RobotMode::TEST) {
TestPeriodic();
m_watchdog.AddEpoch("TestPeriodic()");
} else if (mode == RobotMode::UTILITY) {
UtilityPeriodic();
m_watchdog.AddEpoch("UtilityPeriodic()");
}
RobotPeriodic();

View File

@@ -153,7 +153,7 @@ void MotorSafety::Check() {
stopTime = m_stopTime;
}
if (!enabled || RobotState::IsDisabled() || RobotState::IsTest()) {
if (!enabled || RobotState::IsDisabled() || RobotState::IsUtility()) {
return;
}

View File

@@ -158,12 +158,12 @@ bool RobotBase::IsTeleopEnabled() {
return RobotState::IsTeleopEnabled();
}
bool RobotBase::IsTest() {
return RobotState::IsTest();
bool RobotBase::IsUtility() {
return RobotState::IsUtility();
}
bool RobotBase::IsTestEnabled() {
return RobotState::IsTestEnabled();
bool RobotBase::IsUtilityEnabled() {
return RobotState::IsUtilityEnabled();
}
int64_t RobotBase::GetOpModeId() {

View File

@@ -99,20 +99,22 @@ class RobotState final {
}
/**
* Check if the DS is commanding test mode.
* Check if the DS is commanding utility mode.
*
* @return True if the robot is being commanded to be in test mode
* @return True if the robot is being commanded to be in utility mode
*/
static bool IsTest() { return wpi::internal::DriverStationBackend::IsTest(); }
static bool IsUtility() {
return wpi::internal::DriverStationBackend::IsUtility();
}
/**
* Check if the DS is commanding Test mode and if it has enabled the robot.
* Check if the DS is commanding Utility mode and if it has enabled the robot.
*
* @return True if the robot is being commanded to be in Test mode and
* @return True if the robot is being commanded to be in Utility mode and
* enabled.
*/
static bool IsTestEnabled() {
return wpi::internal::DriverStationBackend::IsTestEnabled();
static bool IsUtilityEnabled() {
return wpi::internal::DriverStationBackend::IsUtilityEnabled();
}
/**

View File

@@ -303,19 +303,19 @@ class DriverStationBackend final {
static bool IsTeleopEnabled() { return GetControlWord().IsTeleopEnabled(); }
/**
* Check if the DS is commanding test mode.
* Check if the DS is commanding utility mode.
*
* @return True if the robot is being commanded to be in test mode
* @return True if the robot is being commanded to be in utility mode
*/
static bool IsTest() { return GetControlWord().IsTest(); }
static bool IsUtility() { return GetControlWord().IsUtility(); }
/**
* Check if the DS is commanding Test mode and if it has enabled the robot.
* Check if the DS is commanding Utility mode and if it has enabled the robot.
*
* @return True if the robot is being commanded to be in Test mode and
* @return True if the robot is being commanded to be in Utility mode and
* enabled.
*/
static bool IsTestEnabled() { return GetControlWord().IsTestEnabled(); }
static bool IsUtilityEnabled() { return GetControlWord().IsUtilityEnabled(); }
/**
* Adds an operating mode option. It's necessary to call PublishOpModes() to

View File

@@ -32,8 +32,8 @@ namespace wpi {
* another mode
* \li TeleopInit() -- called each and every time teleop is entered from another
* mode
* \li TestInit() -- called each and every time test is entered from another
* mode
* \li UtilityInit() -- called each and every time utility is entered from
* another mode
*
* Periodic() functions -- each of these functions is called on an interval:
*
@@ -41,7 +41,7 @@ namespace wpi {
* \li DisabledPeriodic()
* \li AutonomousPeriodic()
* \li TeleopPeriodic()
* \li TestPeriodic()
* \li UtilityPeriodic()
*
* Exit() functions -- each of the following functions is called once when the
* appropriate mode is exited:
@@ -49,7 +49,7 @@ namespace wpi {
* \li DisabledExit() -- called each and every time disabled is exited
* \li AutonomousExit() -- called each and every time autonomous is exited
* \li TeleopExit() -- called each and every time teleop is exited
* \li TestExit() -- called each and every time test is exited
* \li UtilityExit() -- called each and every time utility is exited
*/
class IterativeRobotBase : public RobotBase {
public:
@@ -97,12 +97,12 @@ class IterativeRobotBase : public RobotBase {
virtual void TeleopInit();
/**
* Initialization code for test mode should go here.
* Initialization code for utility mode should go here.
*
* Users should override this method for initialization code which will be
* called each time the robot enters test mode.
* called each time the robot enters utility mode.
*/
virtual void TestInit();
virtual void UtilityInit();
/**
* Periodic code for all modes should go here.
@@ -147,13 +147,13 @@ class IterativeRobotBase : public RobotBase {
virtual void TeleopPeriodic();
/**
* Periodic code for test mode should go here.
* Periodic code for utility mode should go here.
*
* Users should override this method for code which will be called each time a
* new packet is received from the driver station and the robot is in test
* new packet is received from the driver station and the robot is in utility
* mode.
*/
virtual void TestPeriodic();
virtual void UtilityPeriodic();
/**
* Exit code for disabled mode should go here.
@@ -180,12 +180,12 @@ class IterativeRobotBase : public RobotBase {
virtual void TeleopExit();
/**
* Exit code for test mode should go here.
* Exit code for utility mode should go here.
*
* Users should override this method for code which will be called each time
* the robot exits test mode.
* the robot exits utility mode.
*/
virtual void TestExit();
virtual void UtilityExit();
/**
* Gets time period between calls to Periodic() functions.

View File

@@ -13,14 +13,11 @@
#include "wpi/driverstation/Alert.hpp"
#include "wpi/framework/RobotBase.hpp"
#include "wpi/hal/DriverStationTypes.hpp"
#include "wpi/hal/Notifier.h"
#include "wpi/internal/PeriodicPriorityQueue.hpp"
#include "wpi/opmode/OpMode.hpp"
#include "wpi/system/Watchdog.hpp"
#include "wpi/units/time.hpp"
#include "wpi/util/DenseMap.hpp"
#include "wpi/util/SafeThread.hpp"
#include "wpi/util/Synchronization.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi::util {

View File

@@ -191,20 +191,20 @@ class RobotBase {
static bool IsTeleopEnabled();
/**
* Determine if the robot is currently in Test mode.
* Determine if the robot is currently in Utility mode.
*
* @return True if the robot is currently running in Test mode as determined
* by the Driver Station.
* @return True if the robot is currently running in Utility mode as
* determined by the Driver Station.
*/
static bool IsTest();
static bool IsUtility();
/**
* Determine if the robot is current in Test mode and enabled.
* Determine if the robot is currently in Utility mode and enabled.
*
* @return True if the robot is currently operating in Test mode while
* @return True if the robot is currently operating in Utility mode while
* enabled as determined by the Driver Station.
*/
static bool IsTestEnabled();
static bool IsUtilityEnabled();
/**
* Gets the currently selected operating mode of the driver station. Note this

View File

@@ -36,8 +36,8 @@ classes:
IsAutonomousEnabled:
IsTeleop:
IsTeleopEnabled:
IsTest:
IsTestEnabled:
IsUtility:
IsUtilityEnabled:
AddOpMode:
overloads:
RobotMode, std::string_view, std::string_view, std::string_view, const wpi::util::Color&, const wpi::util::Color&:

View File

@@ -5,12 +5,12 @@ classes:
DisabledInit:
AutonomousInit:
TeleopInit:
TestInit:
UtilityInit:
RobotPeriodic:
DisabledPeriodic:
AutonomousPeriodic:
TeleopPeriodic:
TestPeriodic:
UtilityPeriodic:
IterativeRobotBase:
overloads:
double:
@@ -22,7 +22,7 @@ classes:
DisabledExit:
AutonomousExit:
TeleopExit:
TestExit:
UtilityExit:
GetPeriod:
PrintWatchdogEpochs:
doc: |
@@ -44,7 +44,7 @@ classes:
- DisabledInit() -- called each and every time disabled is entered from another mode
- AutonomousInit() -- called each and every time autonomous is entered from another mode
- TeleopInit() -- called each and every time teleop is entered from another mode
- TestInit() -- called each and every time test is entered from another mode
- UtilityInit() -- called each and every time utility is entered from another mode
Periodic() functions -- each of these functions is called on an interval:
@@ -52,7 +52,7 @@ classes:
- DisabledPeriodic()
- AutonomousPeriodic()
- TeleopPeriodic()
- TestPeriodic()
- UtilityPeriodic()
Exit() functions -- each of the following functions is called once when the
appropriate mode is exited:
@@ -60,4 +60,4 @@ classes:
- DisabledExit() -- called each and every time disabled is exited
- AutonomousExit() -- called each and every time autonomous is exited
- TeleopExit() -- called each and every time teleop is exited
- TestExit() -- called each and every time test is exited
- UtilityExit() -- called each and every time utility is exited

View File

@@ -25,8 +25,8 @@ classes:
IsAutonomousEnabled:
IsTeleop:
IsTeleopEnabled:
IsTest:
IsTestEnabled:
IsUtility:
IsUtilityEnabled:
GetThreadId:
ignore: true
StartCompetition:

View File

@@ -12,8 +12,8 @@ classes:
IsAutonomousEnabled:
IsTeleop:
IsTeleopEnabled:
IsTest:
IsTestEnabled:
IsUtility:
IsUtilityEnabled:
AddOpMode:
overloads:
RobotMode, std::string_view, std::string_view, std::string_view, const wpi::util::Color&, const wpi::util::Color&:

View File

@@ -78,7 +78,7 @@ TEST_F(OpModeRobotTest, AddOpMode) {
AddOpMode<MockOpMode>(wpi::RobotMode::AUTONOMOUS, "NoArgOpMode-Auto",
"Group", "Description", wpi::util::Color::WHITE,
wpi::util::Color::BLACK);
AddOpMode<OneArgOpMode>(wpi::RobotMode::TEST, "OneArgOpMode-Test",
AddOpMode<OneArgOpMode>(wpi::RobotMode::UTILITY, "OneArgOpMode-Test",
"Group", "Description", wpi::util::Color::WHITE,
wpi::util::Color::BLACK);
AddOpMode<MockOpMode>(wpi::RobotMode::TELEOPERATED, "NoArgOpMode");

View File

@@ -60,7 +60,7 @@ class MockRobot : public TimedRobot {
void TeleopInit() override { m_teleopInitCount++; }
void TestInit() override { m_testInitCount++; }
void UtilityInit() override { m_testInitCount++; }
void RobotPeriodic() override { m_robotPeriodicCount++; }
@@ -72,7 +72,7 @@ class MockRobot : public TimedRobot {
void TeleopPeriodic() override { m_teleopPeriodicCount++; }
void TestPeriodic() override { m_testPeriodicCount++; }
void UtilityPeriodic() override { m_testPeriodicCount++; }
void DisabledExit() override { m_disabledExitCount++; }
@@ -80,7 +80,7 @@ class MockRobot : public TimedRobot {
void TeleopExit() override { m_teleopExitCount++; }
void TestExit() override { m_testExitCount++; }
void UtilityExit() override { m_testExitCount++; }
};
} // namespace
@@ -305,7 +305,7 @@ TEST_F(TimedRobotTest, TestMode) {
wpi::sim::WaitForProgramStart();
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TEST);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_UTILITY);
wpi::sim::DriverStationSim::NotifyNewData();
EXPECT_EQ(1u, robot.m_simulationInitCount);
@@ -460,7 +460,7 @@ TEST_F(TimedRobotTest, ModeChange) {
// Transition to test
wpi::sim::DriverStationSim::SetEnabled(true);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TEST);
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_UTILITY);
wpi::sim::DriverStationSim::NotifyNewData();
wpi::sim::StepTiming(kPeriod);

View File

@@ -54,17 +54,17 @@ TEST(DriverStationTest, Mode) {
HAL_Initialize(500, 0);
DriverStationSim::ResetData();
EXPECT_FALSE(RobotState::IsTest());
EXPECT_FALSE(RobotState::IsUtility());
EnumCallback callback;
auto cb = DriverStationSim::RegisterRobotModeCallback(callback.GetCallback(),
false);
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TEST);
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_UTILITY);
DriverStationSim::NotifyNewData();
EXPECT_EQ(DriverStationSim::GetRobotMode(), HAL_ROBOT_MODE_TEST);
EXPECT_TRUE(RobotState::IsTest());
EXPECT_EQ(RobotState::GetRobotMode(), RobotMode::TEST);
EXPECT_EQ(DriverStationSim::GetRobotMode(), HAL_ROBOT_MODE_UTILITY);
EXPECT_TRUE(RobotState::IsUtility());
EXPECT_EQ(RobotState::GetRobotMode(), RobotMode::UTILITY);
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(callback.GetLastValue(), HAL_ROBOT_MODE_TEST);
EXPECT_EQ(callback.GetLastValue(), HAL_ROBOT_MODE_UTILITY);
}
TEST(DriverStationTest, Estop) {

View File

@@ -73,8 +73,8 @@ def test_add_op_mode():
)
self.addOpMode(
OneArgOpMode,
RobotMode.TEST,
"OneArgOpMode-Test",
RobotMode.UTILITY,
"OneArgOpMode-Utility",
"Group",
"Description",
Color.WHITE,