Skip to content

Latest commit

 

History

History
634 lines (397 loc) · 24 KB

drive_characterization.md

File metadata and controls

634 lines (397 loc) · 24 KB

drive_characterization.hpp

DriveCharacterization — what the GAINS and REST steps of shulib Calibrate MEASURE, as data.

This header declares 4 types (40 members).

Extracted from include/shulib/calibration/drive_characterization.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.

Contents

enum class CharacterizationSource

enum class CharacterizationSource : std::uint8_t

Where a characterization came from. APPEND-ONLY and persisted: a new source goes at the end.

enum class, declared at include/shulib/calibration/drive_characterization.hpp:51.

CharacterizationSource::Unset

Unset = 0

nothing measured — the placeholders (HA-45) are in force

enumerator, declared at include/shulib/calibration/drive_characterization.hpp:52.

CharacterizationSource::Measured

Measured = 1

measured by the robot, in shulib Calibrate (GAINS and/or REST)

enumerator, declared at include/shulib/calibration/drive_characterization.hpp:53.

struct SideCharacterization

struct SideCharacterization

One drive side's fitted gains and the facts behind them (calibration::FitResult, kept).

struct, declared at include/shulib/calibration/drive_characterization.hpp:57.

SideCharacterization::gains

control::FeedforwardGains gains{}

kS (V), kV (V·s/in, per in/s of the side's SURFACE speed in the drivetrain record's scale), kA (V·s²/in — RECORDED, NOT APPLIED; see the header).

field, declared at include/shulib/calibration/drive_characterization.hpp:60.

SideCharacterization::residualRms

double residualRms = 0.0

The fit's residual RMS, in/s.

field, declared at include/shulib/calibration/drive_characterization.hpp:62.

SideCharacterization::alpha

double alpha = 0.0

The fitted α (the discrete law's decay per tick; feedforward_fit.hpp).

field, declared at include/shulib/calibration/drive_characterization.hpp:64.

SideCharacterization::voltsMin

double voltsMin = 0.0

The smallest |volts| the fit admitted — the low end of the range the gains were fitted over.

field, declared at include/shulib/calibration/drive_characterization.hpp:66.

SideCharacterization::voltsMax

double voltsMax = 0.0

The largest |volts| the fit admitted — the high end (A4 register HA-171: they must hold beyond it).

field, declared at include/shulib/calibration/drive_characterization.hpp:69.

SideCharacterization::samples

std::uint32_t samples = 0

How many samples the fit admitted.

field, declared at include/shulib/calibration/drive_characterization.hpp:71.

SideCharacterization::members

std::uint8_t members = 0

How many members the side had when it was measured: a later boot with fewer present raises kS roughly as 1/(members present) (A4 register HA-174), which Part B's gains line notes.

field, declared at include/shulib/calibration/drive_characterization.hpp:74.

SideCharacterization::kABelowResolution

bool kABelowResolution = false

True when kA was below the fit's resolution and is therefore exactly 0.

field, declared at include/shulib/calibration/drive_characterization.hpp:76.

struct RestSummary

struct RestSummary

The REST step's summary (rest_capture.hpp computes it; the header there derives every formula). Every angle is in RADIANS, every rate in rad/s, every speed in in/s, every time in seconds.

struct, declared at include/shulib/calibration/drive_characterization.hpp:81.

RestSummary::driftRadPerS

double driftRadPerS = 0.0

The heading's drift: the least-squares SLOPE of the unwrapped heading against time, rad/s. A PER-BOOT number — never applied as a correction (A4 register HA-173).

field, declared at include/shulib/calibration/drive_characterization.hpp:84.

RestSummary::driftSigmaWhite

double driftSigmaWhite = 0.0

The slope's standard error IF the heading noise is WHITE: σ_line / √(Σ(t − t̄)²), which is σ_line·√12/(√N·T) for evenly spaced ticks. rad/s.

field, declared at include/shulib/calibration/drive_characterization.hpp:87.

RestSummary::driftSigmaWalk

double driftSigmaWalk = 0.0

The slope's standard error IF the heading is a RANDOM WALK (integrated rate noise): σ_Δ·√(1.2/(dt·T)). rad/s. Neither is picked automatically: each overstates the other case badly (rest_capture.hpp; HA-173).

field, declared at include/shulib/calibration/drive_characterization.hpp:91.

RestSummary::structureRatio

double structureRatio = 0.0

The structure ratio ρ = σ_Δ/(√2·σ_line): ≈ 1 for white heading noise, ≪ 1 for a random walk. UNDEFINED when the heading has no noise about its line (σ_line = 0 — the quiet host test plant, or an IMU that reports a constant): it is then reported as 0, which is NOT random-walk evidence — read structureRatioDefined() first. A rotation the encoders saw (encoderTurnMaxRad) also pulls ρ toward 0: the step it puts in the heading inflates σ_line and not σ_Δ (A4 register HA-173).

field, declared at include/shulib/calibration/drive_characterization.hpp:98.

RestSummary::headingSigmaRad

double headingSigmaRad = 0.0

Heading noise: σ_line, the standard deviation of the residual about the fitted LINE (never about the mean — a drift inflates that), rad.

field, declared at include/shulib/calibration/drive_characterization.hpp:101.

RestSummary::stepRateSigma

double stepRateSigma = 0.0

σ_Δ/dt: the standard deviation of the per-tick heading step about its mean, over the mean dt — the rate noise SettledUtil actually differentiates. rad/s.

field, declared at include/shulib/calibration/drive_characterization.hpp:104.

RestSummary::yawRateMean

double yawRateMean = 0.0

The IMU's yaw-rate channel: its mean, rad/s — a second, independent drift estimate.

field, declared at include/shulib/calibration/drive_characterization.hpp:106.

RestSummary::yawRateSigma

double yawRateSigma = 0.0

The yaw-rate channel's standard deviation, rad/s.

field, declared at include/shulib/calibration/drive_characterization.hpp:108.

RestSummary::maxHeadingStepRad

double maxHeadingStepRad = 0.0

The largest |tick-to-tick heading step| seen, rad (A4 register HA-160 evidence).

field, declared at include/shulib/calibration/drive_characterization.hpp:110.

RestSummary::durationS

double durationS = 0.0

How long the capture ran, seconds (first sample to last).

field, declared at include/shulib/calibration/drive_characterization.hpp:112.

RestSummary::speedSigma

double speedSigma[2] = {0.0, 0.0}

Each side's median encoder speed at rest: its standard deviation, in/s. [0] LEFT, [1] RIGHT.

field, declared at include/shulib/calibration/drive_characterization.hpp:114.

RestSummary::encoderTurnRad

double encoderTurnRad = 0.0

The encoders' rotation (dR − dL)/W at the capture's LAST sample, from its first, rad (positive = CCW). A robot that really turned — a hand on it — turned the IMU's heading too, and the drift's slope cannot tell that from drift (rest_capture.hpp's header).

field, declared at include/shulib/calibration/drive_characterization.hpp:118.

RestSummary::encoderTurnMaxRad

double encoderTurnMaxRad = 0.0

The largest |encoder rotation| from the first sample, over the whole capture, rad — under RestCaptureConfig::turnBound, or the capture would have been refused as Turned. What it can have done to the drift is driftTurnBiasBound().

field, declared at include/shulib/calibration/drive_characterization.hpp:122.

RestSummary::encoderMoveMaxIn

double encoderMoveMaxIn = 0.0

The largest |encoder translation| — the centre's travel (dL + dR)/2 — from the first sample, over the whole capture, inches (under moveBound, or it was refused as Moved).

field, declared at include/shulib/calibration/drive_characterization.hpp:125.

RestSummary::samples

std::uint32_t samples = 0

How many samples the capture took.

field, declared at include/shulib/calibration/drive_characterization.hpp:127.

RestSummary::timing

diag::TickTimingSummary timing{}

The capture's loop timing.

field, declared at include/shulib/calibration/drive_characterization.hpp:129.

RestSummary::driftDegPerMin

[[nodiscard]] double driftDegPerMin() const noexcept

The drift in degrees per minute — the unit HA-20 states its bound in.

function, declared at include/shulib/calibration/drive_characterization.hpp:132.

RestSummary::driftTurnBiasBound

[[nodiscard]] double driftTurnBiasBound() const noexcept

The most the rotation the ENCODERS saw can have moved driftRadPerS, rad/s: 3·encoderTurnMaxRad/durationS. A heading offset bounded by M over [0, T] moves a least-squares slope by at most M·Σ|t − t̄|/Σ(t − t̄)², which is 3·M/T for evenly spaced ticks (rest_capture.hpp's header derives it; one step of size A at mid-capture moves it by 1.5·A/T). A capture is not refused for a rotation under turnBound, so this is how a reader tells a measured drift from a nudge: a drift not well clear of this bound says nothing (A4 register HA-170, HA-173). 0 for a robot that never turned; 0 when durationS is 0.

function, declared at include/shulib/calibration/drive_characterization.hpp:143.

RestSummary::structureRatioDefined

[[nodiscard]] bool structureRatioDefined() const noexcept

True when structureRatio is defined — the heading had SOME noise about its line (headingSigmaRad > 0). When false, structureRatio is reported as 0 and means nothing.

function, declared at include/shulib/calibration/drive_characterization.hpp:149.

struct DriveCharacterization

struct DriveCharacterization

Everything shulib Calibrate's GAINS and REST steps measured about one drivetrain (header). Part B's record persists it; Part B's builder consumes combined().

struct, declared at include/shulib/calibration/drive_characterization.hpp:154.

DriveCharacterization::source

CharacterizationSource source = CharacterizationSource::Unset

Where the numbers came from. Unset (the default) is "nothing measured".

field, declared at include/shulib/calibration/drive_characterization.hpp:156.

DriveCharacterization::hasGains

bool hasGains = false

True when the GAINS section (left, right, rampTiming) holds a measurement.

field, declared at include/shulib/calibration/drive_characterization.hpp:158.

DriveCharacterization::hasRest

bool hasRest = false

True when the REST section (rest) holds a measurement.

field, declared at include/shulib/calibration/drive_characterization.hpp:160.

DriveCharacterization::left

SideCharacterization left{}

The LEFT side's gains.

field, declared at include/shulib/calibration/drive_characterization.hpp:162.

DriveCharacterization::right

SideCharacterization right{}

The RIGHT side's gains.

field, declared at include/shulib/calibration/drive_characterization.hpp:164.

DriveCharacterization::rampTiming

diag::TickTimingSummary rampTiming{}

The GAINS run's loop timing, every powered and stopping tick of it.

field, declared at include/shulib/calibration/drive_characterization.hpp:166.

DriveCharacterization::rest

RestSummary rest{}

The REST step's summary.

field, declared at include/shulib/calibration/drive_characterization.hpp:168.

DriveCharacterization::provenance

char provenance[96]{}

The build stamp or session note, NUL-terminated (a fixed buffer, not a pointer — the whole struct is written to a card as it stands).

field, declared at include/shulib/calibration/drive_characterization.hpp:171.

DriveCharacterization::combined

[[nodiscard]] constexpr control::FeedforwardGains combined() const noexcept

D2's combination: the field-by-field MEAN of the two sides' gains. Its kA is carried, and no consumer applies it (header). Meaningful only when hasGains.

function, declared at include/shulib/calibration/drive_characterization.hpp:175.

DriveCharacterization::kVAsymmetry

[[nodiscard]] double kVAsymmetry() const noexcept

|kV_left − kV_right| / their mean — how far apart the sides are. 0 when both are 0.

function, declared at include/shulib/calibration/drive_characterization.hpp:182.

DriveCharacterization::valid

[[nodiscard]] bool valid(char* why, std::size_t cap) const

True when the characterization holds together, else false with the first offending FIELD named in why (NUL-terminated, cut to cap; may be null) — ASCII, no '%': * source is a known value; Unset carries no section, Measured at least one; * a GAINS section: per side every number finite, kV > 0, kS >= 0, kA >= 0, residual >= 0, 0 <= voltsMin <= voltsMax <= 12, samples > 0, members in 1..21, and a kA below resolution is exactly 0; the ramp's timing summary valid; * a REST section: every number finite, every sigma, ratio, step and largest encoder motion >= 0, the final encoder rotation no larger than the largest, the duration > 0, samples > 0, its timing summary valid; * provenance NUL-terminated inside its buffer. It does not judge whether the numbers are PLAUSIBLE — FitConfig's ranges did that when they were measured, and a record must not be refused later because a range moved.

function, declared at include/shulib/calibration/drive_characterization.hpp:199.

Design commentary, from the header

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

 DriveCharacterization — what the GAINS and REST steps of shulib Calibrate MEASURE, as data (chunk
 R5a Part A, 2026-09-29). drive_characterizer.hpp (the GAINS step: each side's kS/kV/kA) and
 rest_capture.hpp (the REST step: the IMU's drift and noise, the encoders' noise at rest, the loop's
 timing) produce it; Part B of R5a persists it on the SD card beside the drivetrain record, bound
 to that record, and teaches the robot builder to consume the gains. NOTHING CONSUMES IT YET: until
 Part B, no program reads it and every drive runs on the placeholder gains (A4 register HA-45).

 NOTHING IN IT HAS BEEN MEASURED ON A ROBOT. The host test plant fills it with the plant's own
 constants; a robot session (S2 gains, S3 noise) is what will put real numbers here.

 ── Why TWO sides, and what "combined" means (R5a's decision D2) ───────────────────────
 The motion layer applies ONE control::Feedforward to every wheel (feedforward.hpp; the command
 pipeline's step 7). The two sides are fitted and kept SEPARATELY anyway — a dragging side or a
 slipping member is a mechanical finding, and averaging it away before anyone saw it would hide
 it — and combined() is their field-by-field MEAN, which is what Part B hands the pipeline.
 kVAsymmetry() says how far apart the sides are; the characterizer warns past 15 %.
 OF THE MEAN, ONLY kS AND kV REACH A MOTOR: the pipeline calls the cruise overload
 Feedforward::calculate(v) and WheelSpeeds has no acceleration channel, so kA is RECORDED (for the
 S2 log and R6's plant back-fit, where τ = kA/kV) and NOT APPLIED (D2, D10).

 ── Laid out to be SERIALIZED (Part B's record) ─────────────────────────────────────
 Fixed-width fields, bounded arrays, no pointers, no std::string, no allocation, constexpr-
 constructible — config/robot_config.hpp's rule for everything a RobotConfig carries, because Part
 B embeds this struct in RobotConfig BY VALUE (that header's ruling B1: one representation, never a
 mirror). The section flags say which halves hold data, so a REST run can be merged into a record
 that already holds a GAINS run without erasing it (Part B's mergeSections). `source` and every
 enum here are APPEND-ONLY: their values are persisted.

 ── The one thing that must never be done with `rest` (A4 register HA-173) ───────────
 The drift is a PER-BOOT bias of the IMU (HA-20): one boot's number is wrong at the next boot. It is
 a sample for the register, reported and kept — NEVER applied as a heading correction.

 PROS-free, sim-free, allocation-free. valid() writes ASCII with no '%' (a panel may paint it).