RobotContext — the composition root / DI container: "the one object that differs across robot / sim / test".
This header declares 2 types (21 members).
Extracted from include/shulib/chassis/robot_context.hpp — this page is that header's documentation, reformatted, so it cannot disagree with the code. Prose about how to think about the API lives in How it works; worked recipes live in Recipes; this page is the complete, mechanical list of what exists.
struct RobotContextConfigThe HAL handles a robot is built from. Pointers so fields are NAMED at the call site (designated initializers) and so the RobotContext can validate them non-null.
struct, declared at include/shulib/chassis/robot_context.hpp:64.
hal::IClock* clock = nullptrthe single source of now; seconds, monotonic
field, declared at include/shulib/chassis/robot_context.hpp:65.
std::span<hal::IMotor* const> driveMotorsThe drive motors, in kinematic wheel order: element i is commanded with wheel speed i of the installed IKinematics, so a wrong order drives the robot the wrong way in silence. ONE entry per kinematic wheel — N physical motors on a side go behind one hal::MotorGroup (R3b Part 1). This context checks only that the span is non-empty and all-non-null; motion::MotionDeps::validate() is where the count is checked, and it demands EQUALITY with the kinematics' wheel count. This is a non-owning VIEW: the pointer ARRAY must outlive the context.
field, declared at include/shulib/chassis/robot_context.hpp:73.
hal::IImu* imu = nullptrheading and yaw rate, canonical CCW radians
field, declared at include/shulib/chassis/robot_context.hpp:74.
hal::IGps* gps = nullptrabsolute fix; off-strip its hasFix() reads false
field, declared at include/shulib/chassis/robot_context.hpp:75.
hal::IBattery* battery = nullptrvolts: the pipeline's ceiling, and the run bookends
field, declared at include/shulib/chassis/robot_context.hpp:76.
hal::ITelemetrySink* telemetry = nullptrevery log line and DebugRecord; NullSink = off
field, declared at include/shulib/chassis/robot_context.hpp:77.
hal::ITagSource* tags = nullptrAprilTags as body-frame poses (the M3 corrector)
field, declared at include/shulib/chassis/robot_context.hpp:78.
hal::IVision* vision = nullptrobject bearings for M4 manipulation targeting
field, declared at include/shulib/chassis/robot_context.hpp:79.
localization::WallSensors* walls = nullptrOPTIONAL (L6-A2, appended): the robot's side distance sensors, their limits and the reset log — nullptr = this robot declares no wall sensors, and the wall reset refuses NO SENSOR. The ONE slot the constructor does NOT require. Non-const: the everyday wall reset files its outcome in the slot's log. Must outlive the context when set.
field, declared at include/shulib/chassis/robot_context.hpp:84.
vision::ToggleCamera* toggleCamera = nullptrOPTIONAL (AF1S-A2, appended): the robot's Toggle camera — one feed over the camera, the model of its measured mount, the team's tracker numbers (vision/toggle_camera.hpp); nullptr = this robot file declares no Toggle block, and the everyday Toggle step says NO CAMERA. Not required by the constructor, like walls. Non-const: the step ticks its feed. Must outlive the context when set.
field, declared at include/shulib/chassis/robot_context.hpp:89.
class RobotContextThe composition root: the ONE object that differs between the real robot, the simulator and a host test. Every layer above the HAL reaches hardware only through it, so exchanging the HAL implementations exchanges the whole robot without touching a line of motion code. NON-OWNING throughout. It copies the config's pointers and span; it never adopts, allocates or destroys anything, so every pointee — and the array the driveMotors span views — must outlive the context. It also caches nothing: each accessor hands back the live handle, so a reading is only ever as fresh as the caller's own call.
class, declared at include/shulib/chassis/robot_context.hpp:100.
explicit RobotContext(const RobotContextConfig& cfg)Validates the whole config up front — every REQUIRED handle non-null and driveMotors non-empty (walls and toggleCamera are optional and never checked) — through SHULIB_PRECONDITION, so a mis-wired robot fails at construction naming the handle it is missing, instead of dereferencing null halfway through an auton. The count of drive motors is checked here only for emptiness; motion::MotionDeps::validate() checks it for EQUALITY against the kinematics' wheel count (the context never sees the kinematics).
function, declared at include/shulib/chassis/robot_context.hpp:107.
[[nodiscard]] hal::IClock& clock() constThe run's clock. A reference, never null — the constructor already proved that, which is why consumers write ctx.clock().now() and never test a pointer.
function, declared at include/shulib/chassis/robot_context.hpp:123.
[[nodiscard]] std::span<hal::IMotor* const> driveMotors() constThe drive motors, in kinematic wheel order. A VIEW of the caller's array, so it is only as alive as that array; guaranteed non-empty here, and guaranteed to EQUAL the wheel count of the installed kinematics once a motion::MotionDeps has validated the pairing.
function, declared at include/shulib/chassis/robot_context.hpp:127.
[[nodiscard]] hal::IImu& imu() constThe IMU, already canonical: CCW-positive radians, +X = 0. Nothing above this call converts an angle. Gate trust on isReady() at boot — a calibrating IMU reports garbage that moves.
function, declared at include/shulib/chassis/robot_context.hpp:130.
[[nodiscard]] hal::IGps& gps() constThe GPS. Check hasFix() before believing pose(): off-strip the pose is unspecified (still finite), and Driving Skills has no strip at all, so this seam is silent for a whole run.
function, declared at include/shulib/chassis/robot_context.hpp:133.
[[nodiscard]] hal::IBattery& battery() constThe battery. Read live at each use — the command pipeline takes its voltage ceiling from it every tick and the run summary samples it at both ends; nothing here caches a volt.
function, declared at include/shulib/chassis/robot_context.hpp:136.
[[nodiscard]] hal::ITelemetrySink& telemetry() constThe one diagnostics sink for this robot. Which sink is installed is what decides whether tracing costs anything: with NullSink the per-tick record is never even populated.
function, declared at include/shulib/chassis/robot_context.hpp:139.
[[nodiscard]] hal::ITagSource& tags() constThe AprilTag source — V5 AI Vision or a coprocessor, indistinguishable from here. Tags arrive as body-frame poses with no timestamp; staleness is the corrector's problem.
function, declared at include/shulib/chassis/robot_context.hpp:142.
[[nodiscard]] hal::IVision& vision() constThe object/colour detection source. A separate seam from tags() so one adapter can serve both, or either alone, without a consumer of one depending on the other.
function, declared at include/shulib/chassis/robot_context.hpp:145.
[[nodiscard]] localization::WallSensors* wallSensors() const noexceptThe robot's side distance sensors (L6-A2) — nullptr when this robot declares none (the one OPTIONAL slot; the wall reset then refuses NO SENSOR). A pointer, as handed in: this context never dereferences it.
function, declared at include/shulib/chassis/robot_context.hpp:149.
[[nodiscard]] vision::ToggleCamera* toggleCamera() const noexceptThe robot's Toggle camera (AF1S-A2) — nullptr when this robot file declares no Toggle block (the second OPTIONAL slot; the everyday Toggle step then says NO CAMERA). A declared slot may still be NOT READY (its camera absent, its mount unmeasured — its own absence sentence says which). A pointer, as handed in: this context never dereferences it.
function, declared at include/shulib/chassis/robot_context.hpp:154.
The header opens with the reasoning behind these shapes. It is reproduced here in full because a reference that only lists signatures teaches nobody why.
The header’s own reasoning — 34 lines
RobotContext — the composition root / DI container: "the one object that differs across
robot / sim / test" (master plan §5). Every layer above L0 (Chassis, Localizer, motion,
skills) reads hardware ONLY through here, so swapping the HAL implementations
(hal/fake ↔ hal/pros ↔ hal/sim) swaps the whole robot without touching a line of motion
code — which is exactly the M1 Definition of Done.
L3, PROS-free: it sees only the L0 interfaces. NOT part of the F4 freeze — it grows
additively as M3/M4 consumers need more sensors (distance / optical / tracking-wheel
arrays), so adding fields here later is safe.
Built from a RobotContextConfig of NAMED pointers (designated initializers at the call
site); the constructor validates every REQUIRED one non-null, then the accessors hand out
references so consumers write `ctx.clock().now()` rather than juggling pointers.
── The first OPTIONAL slot: the wall sensors (chunk L6-A2, 2026-11-03) ─────────────
`walls` is the one slot the constructor does NOT require: nullptr means "this robot declares no
wall sensors", and the wall reset then refuses NO SENSOR — so every existing caller (the host
harness, the rigs, the Robot before L6-A2) compiles and runs unchanged. It is a pointer handed
out as a pointer (`wallSensors()`), never a reference, because null is a real answer here. This
context only FORWARD-DECLARES its type and never dereferences it (it sees only the L0 interfaces;
the type lives in localization/wall_reset.hpp). The pointer is NON-CONST: the everyday wall reset
files each outcome in the slot's log. motion::MotionScheduler's shadow context carries it field by
field like every other slot — a slot not carried there is nullptr in every `chassis.deps().ctx`.
── The second OPTIONAL slot: the Toggle camera (chunk AF1S-A2, 2026-11-15) ──────────────
`toggleCamera` is the robot's camera answer for the skills Toggle step: one feed over the camera, the
model of its measured mount and the team's tracker numbers (vision/toggle_camera.hpp). Exactly the
wall slot's rules: nullptr means "this robot file declares no Toggle block" — the everyday step then
says NO CAMERA — and every existing caller compiles and runs unchanged; a pointer handed out as a
pointer (`toggleCamera()`), forward-declared and never dereferenced here; NON-CONST (the step ticks
its feed); carried field by field by the motion scheduler's shadow context. A DECLARED block whose
camera could not be built is a present slot that is not READY (its own absence sentence) — the
pointer is decided by the config before the camera exists (vision/toggle_camera.hpp's banner says why).