mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Change opmodes to purely periodic (#8652)
1. Make the OpMode interface itself periodic; this means the only differences between `OpMode` and `PeriodicOpMode` are the latter's methods to add sideloaded periodic callbacks 2. Make OpModeRobot process callbacks in a similar fashion to TimedRobot and 3. Add some lifecycle functions (discussed below) 4. Pull the callback priority queue from TimedRobot to a new class called `PeriodicPriorityQueue` so that `TimedRobot` and `OpModeRobot` have less duplication 5. Fix a typo in the DriverStationJNI class that causes a memory leak when certain driver station sim calls 6. Port the C++ OpModeRobot tests to Java `OpModeRobot` now possesses some `IterativeRobotBase`-stye lifecycle functions; these functions 1. `robotPeriodic` 2. `simulationInit` and `simulationPeriodic` 3. `disabledInit`, `disabledPeriodic`, and `disabledExit` (note that `simulationInit` and `disabledInit` may be renamed to match wpilibsuite#8719) `OpModeRobot` also now processes `OpMode` changes (by the Driver Station) in its `loopFunc` method, similar to `IterativeRobotBase.loopFunc` processing game mode changes; `loopFunc` is, similarly to `TimedRobot`, provided as a default `Callback` --------- Signed-off-by: Zach Harel <zach@zharel.me> Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
This commit is contained in:
@@ -197,6 +197,7 @@ Encoder = "wpi/hardware/rotation/Encoder.hpp"
|
||||
|
||||
# wpi/internal
|
||||
DriverStationModeThread = "wpi/internal/DriverStationModeThread.hpp"
|
||||
PeriodicPriorityQueue = "wpi/internal/PeriodicPriorityQueue.hpp"
|
||||
|
||||
# wpi/opmode
|
||||
OpMode = "wpi/opmode/OpMode.hpp"
|
||||
|
||||
@@ -2,5 +2,7 @@ classes:
|
||||
wpi::OpMode:
|
||||
methods:
|
||||
DisabledPeriodic:
|
||||
OpModeRun:
|
||||
OpModeStop:
|
||||
Start:
|
||||
Periodic:
|
||||
End:
|
||||
GetCallbacks:
|
||||
|
||||
@@ -5,8 +5,10 @@ classes:
|
||||
wpi::OpModeRobotBase:
|
||||
methods:
|
||||
StartCompetition:
|
||||
EndCompetition:
|
||||
OpModeRobotBase:
|
||||
overloads:
|
||||
wpi::units::second_t:
|
||||
"":
|
||||
DriverStationConnected:
|
||||
NonePeriodic:
|
||||
AddOpModeFactory:
|
||||
@@ -17,5 +19,26 @@ classes:
|
||||
RemoveOpMode:
|
||||
PublishOpModes:
|
||||
ClearOpModes:
|
||||
EndCompetition:
|
||||
RobotPeriodic:
|
||||
SimulationInit:
|
||||
SimulationPeriodic:
|
||||
DisabledInit:
|
||||
DisabledPeriodic:
|
||||
DisabledExit:
|
||||
AddPeriodic:
|
||||
GetLoopStartTime:
|
||||
LoopFunc:
|
||||
attributes:
|
||||
DEFAULT_PERIOD:
|
||||
wpi::OpModeRobot:
|
||||
ignore: true
|
||||
methods:
|
||||
OpModeRobot:
|
||||
overloads:
|
||||
wpi::units::second_t:
|
||||
"":
|
||||
AddOpMode:
|
||||
overloads:
|
||||
RobotMode, std::string_view, std::string_view, std::string_view, const wpi::util::Color&, const wpi::util::Color&:
|
||||
RobotMode, std::string_view, std::string_view, std::string_view:
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
classes:
|
||||
wpi::PeriodicOpMode:
|
||||
attributes:
|
||||
DEFAULT_PERIOD:
|
||||
methods:
|
||||
DisabledPeriodic:
|
||||
Start:
|
||||
Periodic:
|
||||
End:
|
||||
GetLoopStartTime:
|
||||
AddPeriodic:
|
||||
GetPeriod:
|
||||
PrintWatchdogEpochs:
|
||||
OpModeRun:
|
||||
OpModeStop:
|
||||
overloads:
|
||||
std::function<void ()>, wpi::units::second_t:
|
||||
std::function<void ()>, wpi::units::second_t, wpi::units::second_t:
|
||||
PeriodicOpMode:
|
||||
LoopFunc:
|
||||
GetCallbacks:
|
||||
|
||||
28
wpilibc/src/main/python/semiwrap/PeriodicPriorityQueue.yml
Normal file
28
wpilibc/src/main/python/semiwrap/PeriodicPriorityQueue.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
classes:
|
||||
wpi::internal::PeriodicPriorityQueue:
|
||||
methods:
|
||||
Add:
|
||||
overloads:
|
||||
std::function<void ()>, std::chrono::microseconds, std::chrono::microseconds:
|
||||
std::function<void ()>, std::chrono::microseconds, std::chrono::microseconds, std::chrono::microseconds:
|
||||
std::function<void ()>, std::chrono::microseconds, wpi::units::second_t:
|
||||
std::function<void ()>, std::chrono::microseconds, wpi::units::second_t, wpi::units::second_t:
|
||||
Callback:
|
||||
Remove:
|
||||
Clear:
|
||||
RunCallbacks:
|
||||
GetQueue:
|
||||
GetLoopStartTime:
|
||||
wpi::internal::PeriodicPriorityQueue::Callback:
|
||||
attributes:
|
||||
func:
|
||||
period:
|
||||
expirationTime:
|
||||
methods:
|
||||
Callback:
|
||||
overloads:
|
||||
std::function<void ()>, std::chrono::microseconds, std::chrono::microseconds, std::chrono::microseconds:
|
||||
std::function<void ()>, std::chrono::microseconds, wpi::units::second_t, wpi::units::second_t:
|
||||
std::function<void ()>, std::chrono::microseconds, wpi::units::second_t:
|
||||
operator>:
|
||||
operator==:
|
||||
@@ -2,6 +2,8 @@ classes:
|
||||
wpi::TimedRobot:
|
||||
attributes:
|
||||
DEFAULT_PERIOD:
|
||||
m_notifier:
|
||||
m_startTime:
|
||||
methods:
|
||||
StartCompetition:
|
||||
EndCompetition:
|
||||
|
||||
Reference in New Issue
Block a user