RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
Runtime

The tick loop and its stages, components, competition modes and rz::start: how robot code runs, on the V5 brain or in tests. More...

Classes

class  rz::Component
 Anything with a loop that runs for the whole program: devices, estimators, mechanisms, loggers. More...
class  rz::Platform
 What the runtime needs from the outside world: a clock, a way to wait, and the competition mode. More...
struct  rz::RobotConfig
 Everything that makes up a robot program. More...
class  rz::TickAwaiter
 Awaiter for the next occurrence of a tick stage. Always suspends. More...
class  rz::SleepAwaiter
 Awaiter that resumes at the first tick at or after a deadline. More...
class  rz::Runtime
 The single-threaded tick loop that drives every coroutine. More...
class  rz::Watchdog
 Detects when the runtime stops ticking because a coroutine is blocking the loop. More...
class  rz::ProsPlatform
 Platform backed by the PROS clock, scheduler and competition status. More...
class  rz::SimulationPlatform
 Fake clock for host tests: sleeping jumps time forward, so runs are instant and deterministic. More...

Typedefs

template<class T = void>
using rz::Task = corral::Task<T>
 Lazy: nothing runs until it is co_awaited.

Enumerations

enum class  rz::CompetitionMode { rz::CompetitionMode::Disabled , rz::CompetitionMode::Autonomous , rz::CompetitionMode::Driver }
 What field control (or a competition switch) currently allows the robot to do. More...
enum class  rz::TickStage : std::uint8_t { rz::TickStage::TickStarted , rz::TickStage::SensorsUpdated , rz::TickStage::EstimatorsUpdated , rz::TickStage::ComponentsUpdated }
 Where in a tick a waiter is resumed, named after what has just finished. Ticks run the stages in this order. More...

Functions

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().

Detailed Description

The tick loop and its stages, components, competition modes and rz::start: how robot code runs, on the V5 brain or in tests.

Typedef Documentation

◆ Task

template<class T = void>
using rz::Task = corral::Task<T>

Lazy: nothing runs until it is co_awaited.

Enumeration Type Documentation

◆ CompetitionMode

enum class rz::CompetitionMode
strong

What field control (or a competition switch) currently allows the robot to do.

Enumerator
Disabled 
Autonomous 
Driver 

◆ TickStage

enum class rz::TickStage : std::uint8_t
strong

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.

Function Documentation

◆ 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 rz::dt ( )
inlinenodiscard

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 rz::now ( )
inlinenodiscard

Time at the start of the current tick of the current runtime.

◆ robot()

Task rz::robot ( RobotConfig config)
nodiscard

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()

void rz::start ( RobotConfig config)

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.