calibrate_program — THE STANDARD "shulib Calibrate" (chunk CAL1, Part A2a, 2026-10-18): the robot measures its own drivetrain, for ANY team, from the few facts only a person can state.
This header declares 8 types (40 members), 8 free functions, and 4 constants.
Extracted from include/shulib/calibration/calibrate_program.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 MechanismPortkMaxMechanismPorts— constantstruct TypedDrivePortsstruct CalibrateFactsenum class FactsListstruct FactsProblemhasTypedDrive— free functionfactsProblem— free functiontypedDriveDescription— free functiontypedDrivePortsFrom— free functiondeclaredMechanism— free functionkCompetitionDisabled— constantkCompetitionAutonomous— constantkCompetitionConnected— constantclass CalibrateIocompetitionWords— free functionstruct CalibrateDevicesclass CalibrateProgramcalibrateBootBanner— free functioncalibrateStateScreen— free function
struct MechanismPortA motor Calibrate must never power: a mechanism's smart port, and what to call it in the log. LIST EVERY MOTOR THAT IS NOT A DRIVE MOTOR: a motor not listed is a drive CANDIDATE, and one that turns with the push is POWERED (3, 6, 9, then 12 V) like a drive motor. A 3-wire solenoid is not a motor and is never a candidate.
struct, declared at include/shulib/calibration/calibrate_program.hpp:145.
std::uint8_t port = 01..21; 0 = an unused entry (only if name is null too)
field, declared at include/shulib/calibration/calibrate_program.hpp:146.
const char* name = nullptrwhat the log and the screen call it; null prints "a mechanism"
field, declared at include/shulib/calibration/calibrate_program.hpp:147.
inline constexpr std::size_t kMaxMechanismPorts = hal::kMaxSmartPortsThe most mechanism motors a team can declare: every smart port, so a robot is never refused for counting.
constant, declared at include/shulib/calibration/calibrate_program.hpp:152.
struct TypedDrivePortsThe drive ports a team ALREADY TYPES for its drive program (CAL1 D6 (a), the team lead 2026-10-08) — OPTIONAL: leave them out and nothing changes. When the card holds no usable record, the front check compares this run with THESE instead of with nothing (header). The spelling is the one a typed table already uses (src/robots/chassis_table.hpp's .left = {-11, 12, -13, 14, -15}, carried unchanged into hal::DriveSideDescription::signedPorts by the boot's tableToDescription()): a SIGNED port per motor on the side it drives, -11 = port 11 reversed once in the adapter. So "SAME FRONT as the typed ports" means exactly "a drive built from them turns every motor the way this push measured". 0 = an unused slot (skipped, the order kept). They are compared, never calibrated from.
struct, declared at include/shulib/calibration/calibrate_program.hpp:163.
std::int8_t left[hal::kMaxSmartPorts]{}the LEFT side's drive ports, signed; 0 = unused
field, declared at include/shulib/calibration/calibrate_program.hpp:164.
std::int8_t right[hal::kMaxSmartPorts]{}the RIGHT side's drive ports, signed; 0 = unused
field, declared at include/shulib/calibration/calibrate_program.hpp:165.
struct CalibrateFactsThe facts only a person can state (header). The optional members are UNSET until stated: a value is never invented, and an unset kind or cartridge REFUSES before anything is made or powered. Every member has a default, so a team names only what it states (designated initializers, in this order — typedDrive is LAST, so a file that names the others still compiles).
struct, declared at include/shulib/calibration/calibrate_program.hpp:173.
std::optional<config::DrivetrainKind> drive{}the kind the team HAS; only Tank is measured
field, declared at include/shulib/calibration/calibrate_program.hpp:174.
std::optional<hal::MotorCartridge> cartridge{}the DRIVE motors' cartridge (insert colour)
field, declared at include/shulib/calibration/calibrate_program.hpp:175.
MechanismPort mechanisms[kMaxMechanismPorts]{}EVERY motor that is not a drive motor
field, declared at include/shulib/calibration/calibrate_program.hpp:176.
const char* robot = nullptroptional: the robot's name, for the log
field, declared at include/shulib/calibration/calibrate_program.hpp:177.
std::uint8_t imuPortStated = 0optional cross-check (the registry decides); 0 = none
field, declared at include/shulib/calibration/calibrate_program.hpp:178.
TypedDrivePorts typedDrive{}optional (D6 (a)): the drive ports the team types — the front check's reference when the card holds no usable record; empty = none
field, declared at include/shulib/calibration/calibrate_program.hpp:181.
CalibratorConfig calibrator{}optional: the calibrator's thresholds for THIS robot (default: CalibratorConfig's). A drive with many motors per side turns the robot less per pulsed member (robot one, 2026-11-16: one member of five turned it ~1.0 deg at 9 V), so its robot file may lower pulseYawFloor — and with it restYawRateFloor, so a drift during a pulse stays under the floor (factsProblem() checks).
field, declared at include/shulib/calibration/calibrate_program.hpp:186.
const char* recordName = nullptroptional (chunk ROB1-BT): THIS robot's name for its record (calibration::isRecordName). Stated, the record's provenance starts robot=<name> <stamp>, so the boot can refuse a card from its twin; unset (nullptr), it is "shulib Calibrate " as before. LAST, so older facts still compile.
field, declared at include/shulib/calibration/calibrate_program.hpp:190.
enum class FactsList : std::uint8_tWhich list of CalibrateFacts a FactsProblem's entry indexes.
enum class, declared at include/shulib/calibration/calibrate_program.hpp:194.
MechanismsCalibrateFacts::mechanisms
enumerator, declared at include/shulib/calibration/calibrate_program.hpp:195.
TypedLeftCalibrateFacts::typedDrive.left
enumerator, declared at include/shulib/calibration/calibrate_program.hpp:196.
TypedRightCalibrateFacts::typedDrive.right
enumerator, declared at include/shulib/calibration/calibrate_program.hpp:197.
RecordNameCalibrateFacts::recordName (no list: entry is 0)
enumerator, declared at include/shulib/calibration/calibrate_program.hpp:198.
struct FactsProblemWhy a team's facts cannot be used: why is null when they can; entry is the index of the entry it names, in the list list names.
struct, declared at include/shulib/calibration/calibrate_program.hpp:203.
const char* why = nullptrnull = usable
field, declared at include/shulib/calibration/calibrate_program.hpp:204.
std::size_t entry = 0the entry it is about
field, declared at include/shulib/calibration/calibrate_program.hpp:205.
FactsList list = FactsList::Mechanismsthe list entry indexes
field, declared at include/shulib/calibration/calibrate_program.hpp:206.
[[nodiscard]] constexpr bool hasTypedDrive(const CalibrateFacts& f) noexceptTrue when f states typed drive ports: any non-zero entry on EITHER side (a list with one side only is then refused by factsProblem(), never run as untyped).
free function, declared at include/shulib/calibration/calibrate_program.hpp:211.
[[nodiscard]] constexpr FactsProblem factsProblem(const CalibrateFacts& f) noexceptThe first reason f cannot be used. A stated record name that is not one (isRecordName) first; then the mechanism list: an entry NAMED but with no port (a placeholder {0, "intake"} would silently leave that motor a drive candidate), a port outside 1..21, or a port listed twice (the SECOND entry is named). Then, when it states typed drive ports (D6 (a)): a port outside 1..21, a port listed twice — on one side, or once on each, by |port| (the description's own rule) — or only ONE side typed. constexpr, so a build can static_assert its own facts.
free function, declared at include/shulib/calibration/calibrate_program.hpp:227.
[[nodiscard]] constexpr hal::DrivetrainDescription typedDriveDescription( const CalibrateFacts& f) noexceptThe typed drive ports as a description's two sides — the reference compareFronts() reads when the card holds no usable record (header). Only the two sides are filled (the check reads nothing else); zero slots are skipped and the order kept. Assumes factsProblem(f) passed.
free function, declared at include/shulib/calibration/calibrate_program.hpp:296.
[[nodiscard]] constexpr TypedDrivePorts typedDrivePortsFrom( const hal::DrivetrainDescription& d) noexceptA description's two sides as typed drive ports — for a team whose drive program is a config::RobotConfig: .typedDrive = typedDrivePortsFrom(kRobot.drivetrain.tank.description) (the inverse of typedDriveDescription(); the kRobot must be a constant expression when the facts are constexpr).
free function, declared at include/shulib/calibration/calibrate_program.hpp:316.
[[nodiscard]] constexpr const MechanismPort* declaredMechanism(const CalibrateFacts& f, int port) noexceptThe declared mechanism entry for physical port, or null.
free function, declared at include/shulib/calibration/calibrate_program.hpp:329.
inline constexpr std::uint8_t kCompetitionDisabled = 0x01The competition status bit "disabled" (PROS's competition_get_status(); hal/pros/calibrate.hpp checks the three against PROS's own values at compile time). Written in hex: the API reference tool reads << as a bracket.
constant, declared at include/shulib/calibration/calibrate_program.hpp:344.
inline constexpr std::uint8_t kCompetitionAutonomous = 0x02The competition status bit "autonomous" — see kCompetitionDisabled.
constant, declared at include/shulib/calibration/calibrate_program.hpp:346.
inline constexpr std::uint8_t kCompetitionConnected = 0x04The competition status bit "field or switch connected" — see kCompetitionDisabled.
constant, declared at include/shulib/calibration/calibrate_program.hpp:348.
class CalibrateIoEverything the program reaches outside the library's seams — four calls. On the brain: hal::pros::ProsCalibrateIo (hal/pros/calibrate.hpp); on the host: a test's fake.
class, declared at include/shulib/calibration/calibrate_program.hpp:352.
virtual ~CalibrateIo() = defaultPolymorphic-base boilerplate: a virtual destructor, the copy/move set re-defaulted (the base holds no state).
function, declared at include/shulib/calibration/calibrate_program.hpp:356.
CalibrateIo() = defaultPolymorphic-base boilerplate: a virtual destructor, the copy/move set re-defaulted (the base holds no state). Default-constructible.
function, declared at include/shulib/calibration/calibrate_program.hpp:358.
CalibrateIo(const CalibrateIo&) = defaultPolymorphic-base boilerplate: a virtual destructor, the copy/move set re-defaulted (the base holds no state). Default-constructible. Copyable at the base.
function, declared at include/shulib/calibration/calibrate_program.hpp:360.
CalibrateIo(CalibrateIo&&) = defaultPolymorphic-base boilerplate: a virtual destructor, the copy/move set re-defaulted (the base holds no state). Default-constructible. Copyable at the base. Movable at the base.
function, declared at include/shulib/calibration/calibrate_program.hpp:362.
CalibrateIo& operator=(const CalibrateIo&) = defaultPolymorphic-base boilerplate: a virtual destructor, the copy/move set re-defaulted (the base holds no state). Default-constructible. Copyable at the base. Movable at the base. Copy-assignable at the base.
function, declared at include/shulib/calibration/calibrate_program.hpp:364.
CalibrateIo& operator=(CalibrateIo&&) = defaultPolymorphic-base boilerplate: a virtual destructor, the copy/move set re-defaulted (the base holds no state). Default-constructible. Copyable at the base. Movable at the base. Copy-assignable at the base. Move-assignable at the base.
function, declared at include/shulib/calibration/calibrate_program.hpp:366.
virtual void line(const char* text) = 0Polymorphic-base boilerplate: a virtual destructor, the copy/move set re-defaulted (the base holds no state). Default-constructible. Copyable at the base. Movable at the base. Copy-assignable at the base. Move-assignable at the base. One serial line, WITHOUT its "[R3D] " tag and newline (the platform adds them). On the brain it reaches the USB serial as ONE write() per line (SER1).
function, declared at include/shulib/calibration/calibrate_program.hpp:369.
[[nodiscard]] virtual std::uint8_t competitionStatus() = 0The competition status byte (the kCompetition* bits).
function, declared at include/shulib/calibration/calibrate_program.hpp:371.
virtual void delayMs(std::uint32_t ms) = 0Wait ms milliseconds — a plain wait (the touch baseline's retry, the fault's idle).
function, declared at include/shulib/calibration/calibrate_program.hpp:373.
[[nodiscard]] virtual bool readShaftDegrees(int port, double& degrees) = 0THE WATCH'S READ: the DECLARED mechanism motor on port's shaft position, degrees, read WITHOUT configuring or commanding it. False when it cannot be read (then nothing is judged).
function, declared at include/shulib/calibration/calibrate_program.hpp:376.
inline const char* competitionWords(std::uint8_t s, char* buf, std::size_t n)The status byte in words, into buf: "0x04 field=yes disabled=no auton=no". Returns buf.
free function, declared at include/shulib/calibration/calibrate_program.hpp:380.
struct CalibrateDevicesThe devices the program runs on, all BORROWED: each must outlive the program.
struct, declared at include/shulib/calibration/calibrate_program.hpp:389.
hal::IDeviceProvider& devicesmotors and the IMU by port; the clock; the pacer
field, declared at include/shulib/calibration/calibrate_program.hpp:390.
hal::IDeviceRegistry& registrywhat is plugged in, read without opening anything
field, declared at include/shulib/calibration/calibrate_program.hpp:391.
hal::IFileStore& cardthe SD card (the record and its backup)
field, declared at include/shulib/calibration/calibrate_program.hpp:392.
hal::IBrainScreen& screenthe brain's screen and touch
field, declared at include/shulib/calibration/calibrate_program.hpp:393.
CalibrateIo& iothe serial line, the competition status, a wait, the watch
field, declared at include/shulib/calibration/calibrate_program.hpp:394.
class CalibrateProgramTHE STANDARD CALIBRATE (header). Construct it over the robot's devices and the team's facts and call run() from opcontrol(): it owns its own 10 ms loop, and returns when the field disables the robot or starts autonomous (cleanly, every motor at 0 V + Coast) or when no run can start (a refusal painted and printed before anything is made). Not copyable. One runs at a time: its calibrator and the run's record are static (detail::programStorage(), off opcontrol's stack).
class, declared at include/shulib/calibration/calibrate_program.hpp:529.
static constexpr double kPushLogMinSeconds = 0.25The least time between two push live: serial lines while the count changes, seconds.
field, declared at include/shulib/calibration/calibrate_program.hpp:532.
static constexpr double kPushLogKeepaliveSeconds = 5.0The longest time between two push live: lines while nothing changes, seconds.
field, declared at include/shulib/calibration/calibrate_program.hpp:534.
CalibrateProgram(const CalibrateFacts& facts, CalibrateDevices d, const char* buildStamp)buildStamp is " " of the build (the caller's DATE " " TIME): the banner prints it whole and the screen's header its time. facts is copied; d and the stamp are borrowed and must outlive the program.
function, declared at include/shulib/calibration/calibrate_program.hpp:539.
CalibrateProgram(const CalibrateProgram&) = deleteNot copyable: it borrows the robot's devices, and a copy would be a second program commanding the same motors.
function, declared at include/shulib/calibration/calibrate_program.hpp:545.
CalibrateProgram& operator=(const CalibrateProgram&) = deleteNot copyable: it borrows the robot's devices, and a copy would be a second program commanding the same motors. Not copy-assignable, for the same reason.
function, declared at include/shulib/calibration/calibrate_program.hpp:547.
void run()Run calibrations until driver control ends — the field's disable, or autonomous starting — or return at once when no run can start (a refusal, painted and printed) (header).
function, declared at include/shulib/calibration/calibrate_program.hpp:551.
inline void calibrateBootBanner(CalibrateIo& io, const char* label, std::uint8_t status, const char* buildStamp)initialize()'s banner for the standard Calibrate, through io: label (a build's beacon, or null), the competition status at boot, the build stamp. Constructs nothing and powers nothing — the motors are found when driver control starts.
free function, declared at include/shulib/calibration/calibrate_program.hpp:1899.
inline void calibrateStateScreen(hal::IBrainScreen& screen, CalibrateIo& io, const char* state, const char* why)disabled() / competition_initialize() / autonomous() for the standard Calibrate: its competition-state screen on screen (it runs ONLY in driver control) and one serial line through io. Pass calibrate_screen.hpp's words — screen_text::kStateName* for state and kStateWhy* for why — which are checked at compile time to fit; any other text is cut, and the screen says so. A free function: those entry points run on their own PROS tasks, before and after run()'s program exists.
free function, declared at include/shulib/calibration/calibrate_program.hpp:1932.
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 — 103 lines, click to expand
calibrate_program — THE STANDARD "shulib Calibrate" (chunk CAL1, Part A2a, 2026-10-18): the robot
measures its own drivetrain, for ANY team, from the few facts only a person can state.
── What a team states, and nothing else ────────────────────────────────────────────
CalibrateFacts: the drive KIND (config::DrivetrainKind — only a tank is measured; anything else
is refused by name), the drive motors' CARTRIDGE (no reading can tell it: the rotor turns the same
for every insert), and the port of EVERY motor that is NOT a drive motor (its MECHANISMS — the
registry reports a motor's kind, never its job). Everything else is discovered on the robot: which
ports drive, which way each is wired, which side, each side's inches per radian, the effective
track width, the IMU's port — and THE FRONT, which is the end that LEADS the push (the team lead,
2026-10-06). A motor the facts do not list is a drive CANDIDATE: one that turns with the push is
POWERED (3, 6, 9, then 12 V) like a drive motor. The program says so wherever it can (its banner
when nothing is declared, a line per candidate that did not turn, the LEFT OUT and pulse-refusal
lines), because the facts are the only guard.
── Where it comes from ─────────────────────────────────────────────────────────────
This is "shulib Calibrate" — src/programs/calibrate_program.cpp (R3d Part 2F-2, 2026-09-24; SER1's
one-call serial lines, 2026-10-15) — MOVED: the census, the declared-port drop, the refusals, the
calibrator, the touch, the serial record and RUN AGAIN are its code, in its order. What changed is
the CAL1 brief's §1.3 list and nothing else: the words that named robot two are the facts'; the
front is the push's (CAL1 Part B, 2026-11-05, removed the calibrator's WHICH END question, which
this program had answered itself the tick DONE was accepted); the save is SAFE-SAVE B1's
(calibration/record_store.hpp); and three things are new — the FRONT CHECK, the WATCH of the
declared ports, and the two HELD screens. Since CAL1 Part B robot two runs THIS program: its
src/programs/calibrate_program.cpp is a 27-line glue over hal/pros/calibrate.hpp, with facts
derived from its tables (src/robots/calibrate_facts.hpp).
── It owns NO pixel and NO PROS call ───────────────────────────────────────────────
It paints through calibrate_screen.hpp onto an hal::IBrainScreen, builds its motors and its IMU
through an hal::IDeviceProvider (the provider asks the registry before it constructs, and catches
an adapter's throw per device), reads the census from an hal::IDeviceRegistry, reads and saves the
record through an hal::IFileStore, and reaches the rest — a serial line, the competition status, a
plain wait, and the watch's read of a declared motor — through CalibrateIo, four calls. So the
whole program runs on the host test plant (hal::fake), and hal/pros/calibrate.hpp is its thin robot
shell.
── The FRONT CHECK, before anything is saved ───────────────────────────────────────
At DONE (after the MEASURED lines, before any write) the card's record is read the way the boot
reads it (loadRecord(): the record file, else its backup) and compared with this run's port by port
(front_check.hpp's compareFronts()). No card: no check (nothing can be saved). A card holding no
record (neither file opened): the FIRST record, saved with a NOTE (painted only over a save that
SUCCEEDED: under NOT SAVED it would name a record the card does not hold). Files that opened and do
not decode: NOT DONE, a line per file naming it and its reason, saved with a NOTE. SAME FRONT: saved.
CANNOT TELL: saved with a NOTE. FRONT FLIPPED: the save WAITS on the FRONT FLIPPED screen — USE NEW
(save as pushed: right after a LEFT/RIGHT cable swap or a deliberate change of front) or RUN AGAIN
(save nothing: right after a wrong push). The records cannot tell those apart, so the screen states
what the RECORDS say and never what the operator did, and nothing is ever turned to another front:
every saved record's front is the end that led its push.
THE RECORD'S NAME (chunk ROB1-BT): when the facts name this robot and the card's record names another
robot or none, the card line and the front check each add a line saying so. The front is still checked
against it (the only front the card holds; twins are wired the same, HA-256), and the save replaces it.
THE TYPED DRIVE PORTS (CAL1 Part A2b, 2026-10-30 — the team lead's D6 (a), 2026-10-08): a team
whose drive program already TYPES its drive ports may state them (CalibrateFacts::typedDrive,
optional). With a usable record on the card they change nothing — not a line, not a draw, not a
byte. With NO usable record on a present card (neither file opened, or files that opened and do
not decode: the boot treats a record that does not decode as absent, and drives from a valid typed
table) they are the reference instead: the same verdicts in their own words, FRONT FLIPPED held the
same way (USE NEW, then fix the typed ports; or RUN AGAIN), and SAME noted as an EXACT match
(every port in either list agrees) or a partial one (the serial log names each port that differs:
a typed port with a wrong sign fights its side-mates in anything that drives from them). They are
COMPARED, never copied into a record: Calibrate never calibrates from them. With no card there is
no check, typed or not. The words that say what a discarded run leaves follow the CARD's contents,
never the reference.
THE LIMIT: the check and the save read the card separately (one program, one task: no race). A
card that misreads a GOOD record as absent at the check makes this run a FIRST record, saved with
no flip check — SAFE-SAVE's two-fault limit (HA-139, the belief that a read returns what the card
holds; record_store.hpp, THE LIMIT). No third read is added to hide it: a third read can misread
too. So a FIRST RECORD note means "the check READ no record", never "the card held none". (With
typed drive ports in the facts, such a run is checked against THEM instead — still not against the
record the card holds.)
── The WATCH, and the second hold ──────────────────────────────────────────────────
Every declared mechanism port is READ when the push begins and again at DONE — never commanded,
never configured: CalibrateIo::readShaftDegrees(), which on the brain is PROS's C reads by port and
no motor object (hal/pros/calibrate.hpp; its belief is HA-187 in docs/hardware-assumptions.md). One
that turned as far as the push's own movedThreshold — the calibrator's own test for a drive port,
so no new threshold — HOLDS the save on MECHANISM PORT TURNED: SAVE (a mechanism the push turns:
keep it declared) or RUN AGAIN (a drive motor declared by mistake: fix the facts). After a USE NEW
it follows FRONT FLIPPED: one question per screen. EVERY declared port that turned is its own
question, on its own screen, in the facts' order — each with ITS turn and whether the card's record
(or, when they were the reference, the typed drive ports) drives with IT, its boxes greyed again as
it arrives — and nothing is saved until every one is
answered SAVE: SAVE is a judgment about one port, so one port's evidence never stands for another's
(an intake the push legitimately turns must not hide a drive motor declared by mistake). Only an
ACCEPTED push is judged — a push the calibrator refuses at DONE saves nothing, so the watch says
nothing about it.
── Nothing is written while HELD, and every exit leaves the motors at 0 V + Coast ──
A hold is a SaveOutcome, not a calibrator phase: nothing is powered, and RUN AGAIN, the end of
driver control or a power-off ends it with nothing written — the words then say what the card
holds (its record, no usable record, or no card at all), and what ended it (the field's disable,
or autonomous starting). An RAII guard runs the all-stop on every C++ exit; the competition status
is polled every tick, and EITHER bit — disabled, or autonomous — exits the loop cleanly (PROS
deletes the opcontrol task at either change, and a deleted task runs no destructors); a
PreconditionError inside the loop is caught once at its edge (PROGRAM FAULT: everything stopped,
said, idled until driver control ends the same way).
NO HARDWARE CLAIM: this program has not run on a robot in this form. Its form before CAL2 ran on
robot one on 2026-11-16 and 11-17 (every run that reached the pulses stopped there). The
calibrator inside it ran on robot two in its R3d Part 2F form on 2026-09-24 (one run stopped, one
finished unrecorded).
Every threshold is INVENTED (A4 register HA-136). PROS-free, sim-free; allocation-free.