[hal, wpilib] Add OpMode support (#7744)

User code:
- OpModeRobot used as the robot base class
- LinearOpMode and PeriodicOpMode are provided opmode base classes
- In Java, annotations can be used to automatically register opmode classes

Additional user code functionality:
- OpMode (string) is available in addition to the overall
auto/teleop/test robot mode
- OpMode does not indicate enable (enable/disable is still separate)
- The HAL API uses integer UIDs; these are exposed at the user API level
as well for faster checks
- User code creates opmodes on startup (these have name, category,
description, etc).

DS:
- DS will present opmode selection lists for auto and teleop for
match/practice. During a match, the DS will automatically activate the
selected opmode in the corresponding match period.
- For testing, an overall mode is selected (e.g. teleop/auto/test) and a
single opmode is selected

Future work:
- Command framework support/integration
- Python annotation support
- Unit tests (needs race-free DS sim updates)
- Porting of examples

Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
This commit is contained in:
Peter Johnson
2025-12-12 21:25:57 -07:00
committed by GitHub
parent 2a41b80e00
commit dacded37e5
163 changed files with 7454 additions and 2175 deletions

View File

@@ -90,6 +90,7 @@ CANAPITypes = "wpi/hal/CANAPITypes.h"
CTREPCM = "wpi/hal/CTREPCM.h"
Constants = "wpi/hal/Constants.h"
Counter = "wpi/hal/Counter.h"
DashboardOpMode = "wpi/hal/DashboardOpMode.hpp"
DIO = "wpi/hal/DIO.h"
# DMA = "hal/DMA.h"
DriverStation = "wpi/hal/DriverStation.h"

View File

@@ -0,0 +1,6 @@
functions:
InitializeDashboardOpMode:
SetDashboardOpModeOptions:
StartDashboardOpMode:
EnableDashboardOpMode:
GetDashboardSelectedOpMode:

View File

@@ -36,9 +36,12 @@ functions:
HAL_ProvideNewDataEventHandle:
HAL_RemoveNewDataEventHandle:
HAL_ObserveUserProgramStarting:
HAL_ObserveUserProgramDisabled:
HAL_ObserveUserProgramAutonomous:
HAL_ObserveUserProgramTeleop:
HAL_ObserveUserProgramTest:
HAL_GetJoystickIsGamepad:
HAL_GetJoystickTouchpads:
HAL_GetUncachedControlWord:
HAL_SetOpModeOptions:
HAL_ObserveUserProgram:
GetControlWord:
ignore: true
GetUncachedControlWord:
ignore: true

View File

@@ -11,17 +11,12 @@ enums:
value_prefix: HAL_JoystickPOV
HAL_MatchType:
value_prefix: HAL_kMatchType
HAL_RobotMode:
ignore: true
RobotMode:
classes:
HAL_ControlWord:
attributes:
enabled:
autonomous:
test:
eStop:
fmsAttached:
dsAttached:
control_reserved:
watchdogEnabled:
ignore: true
HAL_JoystickAxes:
attributes:
axes:
@@ -62,3 +57,49 @@ classes:
attributes:
count:
touchpads:
HAL_OpModeOption:
attributes:
id:
name:
group:
description:
textColor:
backgroundColor:
wpi::hal::ControlWord:
methods:
ControlWord:
overloads:
"":
int64_t, RobotMode, bool, bool, bool, bool:
HAL_ControlWord:
Update:
overloads:
int64_t, RobotMode, bool, bool, bool, bool:
HAL_ControlWord:
IsEnabled:
GetRobotMode:
GetOpModeId:
SetOpModeId:
IsEStopped:
IsFMSAttached:
IsDSAttached:
IsAutonomous:
IsAutonomousEnabled:
IsTeleop:
IsTeleopEnabled:
IsTest:
IsTestEnabled:
GetValue:
functions:
HAL_MakeControlWord:
HAL_ControlWord_GetOpModeHash:
HAL_ControlWord_GetOpModeId:
HAL_ControlWord_SetOpModeId:
HAL_ControlWord_GetRobotMode:
HAL_ControlWord_IsEnabled:
HAL_ControlWord_IsEStopped:
HAL_ControlWord_IsFMSAttached:
HAL_ControlWord_IsDSAttached:
HAL_MakeOpModeId:
HAL_OpMode_GetRobotMode:
HAL_OpMode_GetHash:

View File

@@ -8,16 +8,6 @@ functions:
HALSIM_CancelDriverStationEnabledCallback:
HALSIM_GetDriverStationEnabled:
HALSIM_SetDriverStationEnabled:
HALSIM_RegisterDriverStationAutonomousCallback:
ignore: true
HALSIM_CancelDriverStationAutonomousCallback:
HALSIM_GetDriverStationAutonomous:
HALSIM_SetDriverStationAutonomous:
HALSIM_RegisterDriverStationTestCallback:
ignore: true
HALSIM_CancelDriverStationTestCallback:
HALSIM_GetDriverStationTest:
HALSIM_SetDriverStationTest:
HALSIM_RegisterDriverStationEStopCallback:
ignore: true
HALSIM_CancelDriverStationEStopCallback:
@@ -123,3 +113,20 @@ functions:
HALSIM_SetJoystickTouchpads:
HALSIM_SetJoystickTouchpadCounts:
HALSIM_SetJoystickTouchpadFinger:
HALSIM_RegisterDriverStationRobotModeCallback:
ignore: true
HALSIM_CancelDriverStationRobotModeCallback:
HALSIM_GetDriverStationRobotMode:
HALSIM_SetDriverStationRobotMode:
HALSIM_RegisterDriverStationOpModeCallback:
ignore: true
HALSIM_CancelDriverStationOpModeCallback:
HALSIM_GetDriverStationOpMode:
HALSIM_SetDriverStationOpMode:
HALSIM_RegisterOpModeOptionsCallback:
ignore: true
HALSIM_CancelOpModeOptionsCallback:
HALSIM_GetOpModeOptions:
ignore: true
HALSIM_FreeOpModeOptionsArray:
ignore: true

View File

@@ -10,6 +10,12 @@ functions:
HALSIM_WaitForProgramStart:
HALSIM_SetProgramStarted:
HALSIM_GetProgramStarted:
HALSIM_SetProgramState:
ignore: true
HALSIM_GetProgramState:
ignore: true
SetProgramState:
GetProgramState:
HALSIM_RestartTiming:
HALSIM_PauseTiming:
HALSIM_ResumeTiming: