The tick loop and its stages, components, competition modes and rz::start: how robot code runs, on the V5 brain or in tests.
More...
|
| template<class T = void> |
| using | rz::Task = corral::Task<T> |
| | Lazy: nothing runs until it is co_awaited.
|
|
| Task | rz::robot (RobotConfig config) |
| | The whole robot program as one task. Never returns.
|
| TickAwaiter | rz::tickStarted (std::source_location location=std::source_location::current()) noexcept |
| | Resumes at the start of the next tick, before anything else runs. For device loops.
|
| TickAwaiter | rz::sensorsUpdated (std::source_location location=std::source_location::current()) noexcept |
| | Resumes in the next tick once every device has been polled. For estimators, and for code that only reacts to hardware. Estimates read here may still be from the previous tick.
|
| TickAwaiter | rz::estimatorsUpdated (std::source_location location=std::source_location::current()) noexcept |
| | Resumes in the next tick once every estimator has run. For user code and mechanisms.
|
| TickAwaiter | rz::componentsUpdated (std::source_location location=std::source_location::current()) noexcept |
| | Resumes in the next tick once every component that writes has run. For logging and telemetry.
|
| SleepAwaiter | rz::sleepFor (Duration duration, std::source_location location=std::source_location::current()) noexcept |
| | Resumes at estimatorsUpdated in the first tick whose start time is at least duration from now.
|
| template<std::predicate P> |
| Task< void > | rz::until (P pred) |
| | Waits until pred() is true, checking once per tick at estimatorsUpdated. Returns at once if already true.
|
| Time | rz::now () |
| | Time at the start of the current tick of the current runtime.
|
| Duration | rz::dt () |
| | Duration of the current tick of the current runtime.
|
| void | rz::start (RobotConfig config) |
| | Starts RaidZeroLib on the brain. Call once from initialize().
|
The tick loop and its stages, components, competition modes and rz::start: how robot code runs, on the V5 brain or in tests.
◆ Task
Lazy: nothing runs until it is co_awaited.
◆ CompetitionMode
What field control (or a competition switch) currently allows the robot to do.
| Enumerator |
|---|
| Disabled | |
| Autonomous | |
| Driver | |
◆ TickStage
Where in a tick a waiter is resumed, named after what has just finished. Ticks run the stages in this order.
| Enumerator |
|---|
| TickStarted | Nothing has run yet. Devices wait here to poll their hardware.
|
| SensorsUpdated | Every device polled. Estimators, and code that only reacts to hardware, wait here.
|
| EstimatorsUpdated | Every estimator ran. User code and mechanisms wait here.
|
| ComponentsUpdated | Every component that writes ran. Logging and telemetry wait here.
|
◆ componentsUpdated()
| TickAwaiter rz::componentsUpdated |
( |
std::source_location | location = std::source_location::current() | ) |
|
|
inlinenodiscardnoexcept |
Resumes in the next tick once every component that writes has run. For logging and telemetry.
◆ dt()
Duration of the current tick of the current runtime.
◆ estimatorsUpdated()
| TickAwaiter rz::estimatorsUpdated |
( |
std::source_location | location = std::source_location::current() | ) |
|
|
inlinenodiscardnoexcept |
Resumes in the next tick once every estimator has run. For user code and mechanisms.
◆ now()
Time at the start of the current tick of the current runtime.
◆ robot()
The whole robot program as one task. Never returns.
- Validates device ports (throws std::runtime_error if two devices share one).
- Runs the loop of every constructed component (devices, estimators, mechanisms, ...) for the whole program, across all competition modes. Components constructed after it starts are not run.
- Runs the coroutine for whichever mode field control is in. The mode is read at the start of every tick; when it changes, the running mode's coroutine is cancelled (its RAII cleanup runs) and the new mode's starts. A mode coroutine that finishes early is not restarted. Any mode may be left empty.
rz::start runs this on the brain; tests and simulations run it with runtime.run(robot(config)).
◆ sensorsUpdated()
| TickAwaiter rz::sensorsUpdated |
( |
std::source_location | location = std::source_location::current() | ) |
|
|
inlinenodiscardnoexcept |
Resumes in the next tick once every device has been polled. For estimators, and for code that only reacts to hardware. Estimates read here may still be from the previous tick.
◆ sleepFor()
| SleepAwaiter rz::sleepFor |
( |
Duration | duration, |
|
|
std::source_location | location = std::source_location::current() ) |
|
inlinenodiscardnoexcept |
Resumes at estimatorsUpdated in the first tick whose start time is at least duration from now.
◆ start()
Starts RaidZeroLib on the brain. Call once from initialize().
Runs robot(config) on its own PROS task and returns immediately. If anything escapes the robot program (a configuration error, a bug), the error is logged and the program ends, which stops the hardware; restart the program to try again.
A watchdog task also checks that the runtime keeps ticking. If no tick starts for config.watchdogTimeout (something is blocking the loop), it logs where the last resumed coroutine was waiting and ends the program.
Only initialize() needs defining: PROS provides empty defaults for autonomous(), opcontrol(), disabled() and competition_initialize(), and the runtime reads the competition mode from field control.
◆ tickStarted()
| TickAwaiter rz::tickStarted |
( |
std::source_location | location = std::source_location::current() | ) |
|
|
inlinenodiscardnoexcept |
Resumes at the start of the next tick, before anything else runs. For device loops.
◆ until()
template<std::predicate P>
| Task< void > rz::until |
( |
P | pred | ) |
|
|
nodiscard |
Waits until pred() is true, checking once per tick at estimatorsUpdated. Returns at once if already true.