mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilibc] Change DriverStationSim to use wpi::hal::RobotMode (#8988)
The `RobotState::GetRobotMode()` API returns this enum class, but `DriverStationSim` was using the `HAL_RobotMode` enum instead. This commonizes the two APIs to return the same `RobotMode` enum class. This difference in the APIs also affected Python, as the `hal.RobotMode` and `hal._wpiHal._RobotMode` types are not compatible with each other.
This commit is contained in:
@@ -15,7 +15,7 @@ class RobotModeTriggersTest : public CommandTestBase {};
|
|||||||
|
|
||||||
TEST(RobotModeTriggersTest, Autonomous) {
|
TEST(RobotModeTriggersTest, Autonomous) {
|
||||||
DriverStationSim::ResetData();
|
DriverStationSim::ResetData();
|
||||||
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
|
DriverStationSim::SetRobotMode(wpi::hal::RobotMode::AUTONOMOUS);
|
||||||
DriverStationSim::SetEnabled(true);
|
DriverStationSim::SetEnabled(true);
|
||||||
DriverStationSim::NotifyNewData();
|
DriverStationSim::NotifyNewData();
|
||||||
Trigger autonomous = RobotModeTriggers::Autonomous();
|
Trigger autonomous = RobotModeTriggers::Autonomous();
|
||||||
@@ -24,7 +24,7 @@ TEST(RobotModeTriggersTest, Autonomous) {
|
|||||||
|
|
||||||
TEST(RobotModeTriggersTest, Teleop) {
|
TEST(RobotModeTriggersTest, Teleop) {
|
||||||
DriverStationSim::ResetData();
|
DriverStationSim::ResetData();
|
||||||
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
|
DriverStationSim::SetRobotMode(wpi::hal::RobotMode::TELEOPERATED);
|
||||||
DriverStationSim::SetEnabled(true);
|
DriverStationSim::SetEnabled(true);
|
||||||
DriverStationSim::NotifyNewData();
|
DriverStationSim::NotifyNewData();
|
||||||
Trigger teleop = RobotModeTriggers::Teleop();
|
Trigger teleop = RobotModeTriggers::Teleop();
|
||||||
@@ -41,7 +41,7 @@ TEST(RobotModeTriggersTest, Disabled) {
|
|||||||
|
|
||||||
TEST(RobotModeTriggersTest, UtilityMode) {
|
TEST(RobotModeTriggersTest, UtilityMode) {
|
||||||
DriverStationSim::ResetData();
|
DriverStationSim::ResetData();
|
||||||
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_UTILITY);
|
DriverStationSim::SetRobotMode(wpi::hal::RobotMode::UTILITY);
|
||||||
DriverStationSim::SetEnabled(true);
|
DriverStationSim::SetEnabled(true);
|
||||||
DriverStationSim::NotifyNewData();
|
DriverStationSim::NotifyNewData();
|
||||||
Trigger test = RobotModeTriggers::Utility();
|
Trigger test = RobotModeTriggers::Utility();
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ std::unique_ptr<CallbackStore> DriverStationSim::RegisterRobotModeCallback(
|
|||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_RobotMode DriverStationSim::GetRobotMode() {
|
hal::RobotMode DriverStationSim::GetRobotMode() {
|
||||||
return HALSIM_GetDriverStationRobotMode();
|
return static_cast<hal::RobotMode>(HALSIM_GetDriverStationRobotMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriverStationSim::SetRobotMode(HAL_RobotMode robotMode) {
|
void DriverStationSim::SetRobotMode(hal::RobotMode robotMode) {
|
||||||
HALSIM_SetDriverStationRobotMode(robotMode);
|
HALSIM_SetDriverStationRobotMode(static_cast<HAL_RobotMode>(robotMode));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CallbackStore> DriverStationSim::RegisterEStopCallback(
|
std::unique_ptr<CallbackStore> DriverStationSim::RegisterEStopCallback(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
|
#include "wpi/driverstation/internal/DriverStationBackend.hpp"
|
||||||
#include "wpi/hal/DriverStationTypes.h"
|
#include "wpi/hal/DriverStationTypes.hpp"
|
||||||
#include "wpi/hal/simulation/DriverStationData.h"
|
#include "wpi/hal/simulation/DriverStationData.h"
|
||||||
#include "wpi/simulation/CallbackStore.hpp"
|
#include "wpi/simulation/CallbackStore.hpp"
|
||||||
|
|
||||||
@@ -91,14 +91,14 @@ class DriverStationSim {
|
|||||||
*
|
*
|
||||||
* @return robot mode
|
* @return robot mode
|
||||||
*/
|
*/
|
||||||
static HAL_RobotMode GetRobotMode();
|
static hal::RobotMode GetRobotMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the robot mode set by the DS.
|
* Change the robot mode set by the DS.
|
||||||
*
|
*
|
||||||
* @param robotMode the new value
|
* @param robotMode the new value
|
||||||
*/
|
*/
|
||||||
static void SetRobotMode(HAL_RobotMode robotMode);
|
static void SetRobotMode(hal::RobotMode robotMode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a callback on the eStop state.
|
* Register a callback on the eStop state.
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from ..simulation import (
|
|||||||
stepTimingAsync,
|
stepTimingAsync,
|
||||||
getProgramStarted,
|
getProgramStarted,
|
||||||
)
|
)
|
||||||
from hal._wpiHal import _RobotMode as RobotMode
|
from hal import RobotMode
|
||||||
|
|
||||||
|
|
||||||
class RobotTestController:
|
class RobotTestController:
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import weakref
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from hal import RobotMode
|
||||||
import hal
|
import hal
|
||||||
import hal.simulation
|
import hal.simulation
|
||||||
from hal._wpiHal import _RobotMode as RobotMode
|
|
||||||
import ntcore
|
import ntcore
|
||||||
import wpilib
|
import wpilib
|
||||||
from wpilib.simulation import DriverStationSim, pauseTiming, restartTiming
|
from wpilib.simulation import DriverStationSim, pauseTiming, restartTiming
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ TEST_F(TimedRobotTest, AutonomousMode) {
|
|||||||
wpi::sim::WaitForProgramStart();
|
wpi::sim::WaitForProgramStart();
|
||||||
|
|
||||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
|
wpi::sim::DriverStationSim::SetRobotMode(hal::RobotMode::AUTONOMOUS);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
EXPECT_EQ(1u, robot.m_simulationInitCount);
|
EXPECT_EQ(1u, robot.m_simulationInitCount);
|
||||||
@@ -237,7 +237,7 @@ TEST_F(TimedRobotTest, TeleopMode) {
|
|||||||
wpi::sim::WaitForProgramStart();
|
wpi::sim::WaitForProgramStart();
|
||||||
|
|
||||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
|
wpi::sim::DriverStationSim::SetRobotMode(hal::RobotMode::TELEOPERATED);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
EXPECT_EQ(1u, robot.m_simulationInitCount);
|
EXPECT_EQ(1u, robot.m_simulationInitCount);
|
||||||
@@ -308,7 +308,7 @@ TEST_F(TimedRobotTest, UtilityMode) {
|
|||||||
wpi::sim::WaitForProgramStart();
|
wpi::sim::WaitForProgramStart();
|
||||||
|
|
||||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_UTILITY);
|
wpi::sim::DriverStationSim::SetRobotMode(hal::RobotMode::UTILITY);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
EXPECT_EQ(1u, robot.m_simulationInitCount);
|
EXPECT_EQ(1u, robot.m_simulationInitCount);
|
||||||
@@ -429,7 +429,7 @@ TEST_F(TimedRobotTest, ModeChange) {
|
|||||||
|
|
||||||
// Transition to autonomous
|
// Transition to autonomous
|
||||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
|
wpi::sim::DriverStationSim::SetRobotMode(hal::RobotMode::AUTONOMOUS);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
wpi::sim::StepTiming(kPeriod);
|
wpi::sim::StepTiming(kPeriod);
|
||||||
@@ -446,7 +446,7 @@ TEST_F(TimedRobotTest, ModeChange) {
|
|||||||
|
|
||||||
// Transition to teleop
|
// Transition to teleop
|
||||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
|
wpi::sim::DriverStationSim::SetRobotMode(hal::RobotMode::TELEOPERATED);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
wpi::sim::StepTiming(kPeriod);
|
wpi::sim::StepTiming(kPeriod);
|
||||||
@@ -463,7 +463,7 @@ TEST_F(TimedRobotTest, ModeChange) {
|
|||||||
|
|
||||||
// Transition to utility
|
// Transition to utility
|
||||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_UTILITY);
|
wpi::sim::DriverStationSim::SetRobotMode(hal::RobotMode::UTILITY);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
wpi::sim::StepTiming(kPeriod);
|
wpi::sim::StepTiming(kPeriod);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ TEST(DriverStationTest, Enabled) {
|
|||||||
BooleanCallback callback;
|
BooleanCallback callback;
|
||||||
auto cb =
|
auto cb =
|
||||||
DriverStationSim::RegisterEnabledCallback(callback.GetCallback(), false);
|
DriverStationSim::RegisterEnabledCallback(callback.GetCallback(), false);
|
||||||
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
|
DriverStationSim::SetRobotMode(RobotMode::TELEOPERATED);
|
||||||
DriverStationSim::SetEnabled(true);
|
DriverStationSim::SetEnabled(true);
|
||||||
DriverStationSim::NotifyNewData();
|
DriverStationSim::NotifyNewData();
|
||||||
EXPECT_TRUE(DriverStationSim::GetEnabled());
|
EXPECT_TRUE(DriverStationSim::GetEnabled());
|
||||||
@@ -41,9 +41,9 @@ TEST(DriverStationTest, AutonomousMode) {
|
|||||||
EnumCallback callback;
|
EnumCallback callback;
|
||||||
auto cb = DriverStationSim::RegisterRobotModeCallback(callback.GetCallback(),
|
auto cb = DriverStationSim::RegisterRobotModeCallback(callback.GetCallback(),
|
||||||
false);
|
false);
|
||||||
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS);
|
DriverStationSim::SetRobotMode(RobotMode::AUTONOMOUS);
|
||||||
DriverStationSim::NotifyNewData();
|
DriverStationSim::NotifyNewData();
|
||||||
EXPECT_EQ(DriverStationSim::GetRobotMode(), HAL_ROBOT_MODE_AUTONOMOUS);
|
EXPECT_EQ(DriverStationSim::GetRobotMode(), RobotMode::AUTONOMOUS);
|
||||||
EXPECT_TRUE(RobotState::IsAutonomous());
|
EXPECT_TRUE(RobotState::IsAutonomous());
|
||||||
EXPECT_EQ(RobotState::GetRobotMode(), RobotMode::AUTONOMOUS);
|
EXPECT_EQ(RobotState::GetRobotMode(), RobotMode::AUTONOMOUS);
|
||||||
EXPECT_TRUE(callback.WasTriggered());
|
EXPECT_TRUE(callback.WasTriggered());
|
||||||
@@ -58,9 +58,9 @@ TEST(DriverStationTest, Mode) {
|
|||||||
EnumCallback callback;
|
EnumCallback callback;
|
||||||
auto cb = DriverStationSim::RegisterRobotModeCallback(callback.GetCallback(),
|
auto cb = DriverStationSim::RegisterRobotModeCallback(callback.GetCallback(),
|
||||||
false);
|
false);
|
||||||
DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_UTILITY);
|
DriverStationSim::SetRobotMode(RobotMode::UTILITY);
|
||||||
DriverStationSim::NotifyNewData();
|
DriverStationSim::NotifyNewData();
|
||||||
EXPECT_EQ(DriverStationSim::GetRobotMode(), HAL_ROBOT_MODE_UTILITY);
|
EXPECT_EQ(DriverStationSim::GetRobotMode(), RobotMode::UTILITY);
|
||||||
EXPECT_TRUE(RobotState::IsUtility());
|
EXPECT_TRUE(RobotState::IsUtility());
|
||||||
EXPECT_EQ(RobotState::GetRobotMode(), RobotMode::UTILITY);
|
EXPECT_EQ(RobotState::GetRobotMode(), RobotMode::UTILITY);
|
||||||
EXPECT_TRUE(callback.WasTriggered());
|
EXPECT_TRUE(callback.WasTriggered());
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ TEST_P(ArmSimulationTest, Teleop) {
|
|||||||
|
|
||||||
// teleop init
|
// teleop init
|
||||||
{
|
{
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
|
wpi::sim::DriverStationSim::SetRobotMode(wpi::hal::RobotMode::TELEOPERATED);
|
||||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class ElevatorSimulationTest : public testing::Test {
|
|||||||
TEST_F(ElevatorSimulationTest, Teleop) {
|
TEST_F(ElevatorSimulationTest, Teleop) {
|
||||||
// teleop init
|
// teleop init
|
||||||
{
|
{
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED);
|
wpi::sim::DriverStationSim::SetRobotMode(wpi::hal::RobotMode::TELEOPERATED);
|
||||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ class AutonomousTest : public DigitalCommunicationTest<bool> {};
|
|||||||
TEST_P(AutonomousTest, Autonomous) {
|
TEST_P(AutonomousTest, Autonomous) {
|
||||||
auto autonomous = GetParam();
|
auto autonomous = GetParam();
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(
|
wpi::sim::DriverStationSim::SetRobotMode(
|
||||||
autonomous ? HAL_ROBOT_MODE_AUTONOMOUS : HAL_ROBOT_MODE_TELEOPERATED);
|
autonomous ? wpi::hal::RobotMode::AUTONOMOUS
|
||||||
|
: wpi::hal::RobotMode::TELEOPERATED);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
EXPECT_TRUE(autonomousOutput.GetInitialized());
|
EXPECT_TRUE(autonomousOutput.GetInitialized());
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ class AutonomousTest : public I2CCommunicationTest<bool> {};
|
|||||||
TEST_P(AutonomousTest, Autonomous) {
|
TEST_P(AutonomousTest, Autonomous) {
|
||||||
auto autonomous = GetParam();
|
auto autonomous = GetParam();
|
||||||
wpi::sim::DriverStationSim::SetRobotMode(
|
wpi::sim::DriverStationSim::SetRobotMode(
|
||||||
autonomous ? HAL_ROBOT_MODE_AUTONOMOUS : HAL_ROBOT_MODE_TELEOPERATED);
|
autonomous ? wpi::hal::RobotMode::AUTONOMOUS
|
||||||
|
: wpi::hal::RobotMode::TELEOPERATED);
|
||||||
wpi::sim::DriverStationSim::NotifyNewData();
|
wpi::sim::DriverStationSim::NotifyNewData();
|
||||||
|
|
||||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(port));
|
EXPECT_TRUE(HALSIM_GetI2CInitialized(port));
|
||||||
|
|||||||
Reference in New Issue
Block a user