Skip to content

Latest commit

 

History

History
592 lines (373 loc) · 19.2 KB

until.md

File metadata and controls

592 lines (373 loc) · 19.2 KB

until.hpp

mechanism/until.hpp — WHEN A STEP IS DONE: a power step's done-conditions.

This header declares 4 types (29 members), 1 free function, 3 constants, and 3 type aliass.

Extracted from include/shulib/mechanism/until.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 DoneBy

enum class DoneBy : std::uint8_t

Which done-condition ended a step — the word the step's log line names (doneByWord).

enum class, declared at include/shulib/mechanism/until.hpp:56.

DoneBy::None

None = 0

no condition: the bound, a refusal, a cancel

enumerator, declared at include/shulib/mechanism/until.hpp:57.

DoneBy::Time

Time

its time condition (a duration, or orAfter's)

enumerator, declared at include/shulib/mechanism/until.hpp:58.

DoneBy::Reached

Reached

a position or speed step reached its target (MECH-A3)

enumerator, declared at include/shulib/mechanism/until.hpp:59.

DoneBy::Stalled

Stalled

it stalled (stalls: SUCCEEDED; a stall signature otherwise: STALLED)

enumerator, declared at include/shulib/mechanism/until.hpp:60.

DoneBy::Sees

Sees

a piece sensor saw a piece

enumerator, declared at include/shulib/mechanism/until.hpp:61.

DoneBy::StopsSeeing

StopsSeeing

a piece sensor stopped seeing a piece

enumerator, declared at include/shulib/mechanism/until.hpp:62.

doneByWord

[[nodiscard]] constexpr const char* doneByWord(DoneBy d) noexcept

The words of a DoneBy, as the step's log line prints them. Never null; an out-of-range value reads "?".

free function, declared at include/shulib/mechanism/until.hpp:67.

class Until

class Until

A step's done-conditions (header): any combination of a time, a stall and a piece sensor's seeing or not seeing, ALWAYS beside the step's bound. Combined with | (either ends the step) or orAfter (a sensor condition, or after a time).

class, declared at include/shulib/mechanism/until.hpp:82.

Until::kSelf

static constexpr const char* kSelf = nullptr

"This mechanism": no other mechanism named — the condition reads the step's OWN sensor.

field, declared at include/shulib/mechanism/until.hpp:85.

Until::time

[[nodiscard]] static constexpr Until time(units::Time t) noexcept

Done when t has passed since the step started (a desired duration: SUCCEEDED, by time).

function, declared at include/shulib/mechanism/until.hpp:88.

Until::stalled

[[nodiscard]] static constexpr Until stalled() noexcept

Done when the mechanism STALLS — a squeeze that closes until it is tight: SUCCEEDED, not a fault. Without it, a stated stall signature that trips is the STALLED verdict and a MECHANISM_STALLED fault. Needs the mechanism's stall signature (refused at the step without).

function, declared at include/shulib/mechanism/until.hpp:94.

Until::sees

[[nodiscard]] static constexpr Until sees() noexcept

Done when THIS mechanism's piece sensor sees a piece.

function, declared at include/shulib/mechanism/until.hpp:96.

Until::stopsSeeing

[[nodiscard]] static constexpr Until stopsSeeing() noexcept

Done when THIS mechanism's piece sensor stops seeing a piece.

function, declared at include/shulib/mechanism/until.hpp:98.

Until::sees (overload 2)

template <class Declared> [[nodiscard]] static constexpr Until sees(const Declared& other) noexcept

Done when ANOTHER mechanism's piece sensor sees a piece (the roller runs until the GRIP sees one), named by that mechanism's declaration of any kind and found by its NAME at run time. The words (seesPiece(grip)) also refuse, at build, a mechanism that declares no sensor and a declaration with no .name. Here, a declaration with no .name stores an EMPTY name — never kSelf, which would read the step's own sensor in its place — and the step refuses it.

function, declared at include/shulib/mechanism/until.hpp:105.

Until::stopsSeeing (overload 2)

template <class Declared> [[nodiscard]] static constexpr Until stopsSeeing(const Declared& other) noexcept

Done when ANOTHER mechanism's piece sensor stops seeing a piece (sees(other)'s rules).

function, declared at include/shulib/mechanism/until.hpp:110.

Until::bound

[[nodiscard]] static constexpr Until bound() noexcept

Never done by a condition: only the bound ends the step (TIMED_OUT) — a run that is meant to last its whole time limit while the robot does something else.

function, declared at include/shulib/mechanism/until.hpp:115.

Until::operator|

[[nodiscard]] constexpr Until operator|(const Until& o) const noexcept

Either condition ends the step. Two TIME conditions keep the EARLIER. The sensor conditions must read ONE mechanism's sensor (header): two different NAMES (seesPiece(grip) | stopsSeeingPiece(claw)) are conflicting() and the step refuses them; the step's OWN sensor beside a name keeps the name and sets readsOwnSensorToo(), which the step resolves (one sensor when it runs on that mechanism, refused otherwise).

function, declared at include/shulib/mechanism/until.hpp:122.

Until::orAfter

[[nodiscard]] constexpr Until orAfter(units::Time t) const noexcept

"... or after t, whichever comes first" — the time ends it SUCCEEDED, by time (seesPiece.orAfter(2.5_s): a missed piece does not end the auton). t must be shorter than the step's time limit (refused at the step otherwise: the bound would always win).

function, declared at include/shulib/mechanism/until.hpp:157.

Until::has

[[nodiscard]] constexpr bool has(std::uint8_t bit) const noexcept

Whether the condition bit (kTime, kStalled, kSees, kStops) is part of it.

function, declared at include/shulib/mechanism/until.hpp:160.

Until::seconds

[[nodiscard]] constexpr double seconds() const noexcept

The time condition's duration, seconds (0 when there is none).

function, declared at include/shulib/mechanism/until.hpp:162.

Until::sensor

[[nodiscard]] constexpr const char* sensor() const noexcept

The NAME of the mechanism whose piece sensor the condition reads (kSelf = the step's own; "" = a declaration with no .name, which no robot's list has).

function, declared at include/shulib/mechanism/until.hpp:165.

Until::readsOwnSensorToo

[[nodiscard]] constexpr bool readsOwnSensorToo() const noexcept

True when the condition ALSO reads the step's own sensor beside the one sensor() names (seesPiece | stopsSeeingPiece(intake)): one sensor if the step runs on that mechanism, two otherwise — the step resolves it (operator|). Always false when sensor() is kSelf.

function, declared at include/shulib/mechanism/until.hpp:169.

Until::conflicting

[[nodiscard]] constexpr bool conflicting() const noexcept

True when | joined sensor conditions NAMING two different mechanisms (operator|): the step refuses it rather than silently read one of them.

function, declared at include/shulib/mechanism/until.hpp:172.

Until::kTime

static constexpr std::uint8_t kTime = 1

The time condition's bit.

field, declared at include/shulib/mechanism/until.hpp:175.

Until::kStalled

static constexpr std::uint8_t kStalled = 4

The stall condition's bit (2 is left free: "reached" is a position step's own, not a condition).

field, declared at include/shulib/mechanism/until.hpp:177.

Until::kSees

static constexpr std::uint8_t kSees = 8

The "sees a piece" condition's bit.

field, declared at include/shulib/mechanism/until.hpp:179.

Until::kStops

static constexpr std::uint8_t kStops = 16

The "stops seeing a piece" condition's bit.

field, declared at include/shulib/mechanism/until.hpp:181.

struct SeesPiece

struct SeesPiece : Until

THE WORD seesPiece: as itself, the step's OWN piece sensor; called with another mechanism's declaration, THAT one's (seesPiece(grip)) — refused AT BUILD when that one declares none.

struct, declared at include/shulib/mechanism/until.hpp:231.

SeesPiece::SeesPiece

constexpr SeesPiece() noexcept

The step's own sensor.

function, declared at include/shulib/mechanism/until.hpp:233.

SeesPiece::operator()

template <class Declared> [[nodiscard]] consteval Until operator()(const Declared& other) const

Another mechanism's piece sensor; a declaration with none fails the build, named.

function, declared at include/shulib/mechanism/until.hpp:236.

struct StopsSeeingPiece

struct StopsSeeingPiece : Until

THE WORD stopsSeeingPiece: as seesPiece, for "no longer sees a piece".

struct, declared at include/shulib/mechanism/until.hpp:242.

StopsSeeingPiece::StopsSeeingPiece

constexpr StopsSeeingPiece() noexcept

The step's own sensor.

function, declared at include/shulib/mechanism/until.hpp:244.

StopsSeeingPiece::operator()

template <class Declared> [[nodiscard]] consteval Until operator()(const Declared& other) const

Another mechanism's piece sensor; a declaration with none fails the build, named.

function, declared at include/shulib/mechanism/until.hpp:247.

seesPiece

inline constexpr SeesPiece seesPiece{}

Until the step's piece sensor (or another's, seesPiece(grip)) sees a piece.

constant, declared at include/shulib/mechanism/until.hpp:253.

stopsSeeingPiece

inline constexpr StopsSeeingPiece stopsSeeingPiece{}

Until it stops seeing one.

constant, declared at include/shulib/mechanism/until.hpp:255.

stalls

inline constexpr Until stalls = Until::stalled()

Until the mechanism stalls (a squeeze: SUCCEEDED).

constant, declared at include/shulib/mechanism/until.hpp:257.

seesPiece (overload 2)

using mechanism::seesPiece

Until a piece sensor sees a piece.

type alias, declared at include/shulib/mechanism/until.hpp:263.

stopsSeeingPiece (overload 2)

using mechanism::stopsSeeingPiece

Until a piece sensor stops seeing one.

type alias, declared at include/shulib/mechanism/until.hpp:265.

stalls (overload 2)

using mechanism::stalls

Until the mechanism stalls.

type alias, declared at include/shulib/mechanism/until.hpp:267.

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 — 44 lines

 mechanism/until.hpp — WHEN A STEP IS DONE: a power step's done-conditions (the mechanism core,
 chunk MECH-A2, 2026-10-15).

 A step that runs a mechanism ends when ANY of its conditions holds — "this much time has passed",
 "it stalled", "a piece sensor sees a piece", "a piece sensor stops seeing one" — and ALWAYS also at
 its BOUND, the time limit every step states. `Until` never replaces the bound (requirements P4:
 every action is bounded and says how it ended); it only lets a step end sooner, and says which
 condition ended it (`DoneBy`, the word the step's log line names).

     r.run(intake, 12_volt, seesPiece, 3_s)              // until ITS piece sensor sees a piece
     r.run(intake, 12_volt, seesPiece.orAfter(2.5_s), 3_s)  // ... or after 2.5 s: SUCCEEDED by time
     r.run(intake, -6_volt, stopsSeeingPiece, 1_s)       // until it no longer sees one (an eject)
     r.run(roller, 12_volt, seesPiece(grip), 2_s)        // until ANOTHER mechanism's sensor sees one
     r.run(catapult, 6_volt, stalls, 1_s)                // until it stalls: a squeeze, SUCCEEDED

 (`r.run(...)` is the auton's step, MECH-A4; the mechanism service runs the condition,
 mechanism/service.hpp.)

 ── A condition that can never be met is a mistake, said where it is made ────────────
 `seesPiece(arm)` — another mechanism's sensor, on a mechanism that declares none — FAILS THE BUILD
 at the auton's line (detail::that_mechanism_has_no_piece_sensor). The forms the build cannot see
 (`seesPiece` / `stopsSeeingPiece` on the step's OWN mechanism, `stalls` on one with no stall
 signature) are refused at the STEP, before anything is commanded (the service's preconditions):
 the condition and the declaration are two arguments of one run-time call, and the host test of
 every registered auton runs each step against its robot's real list (MECH-A5), so the refusal
 fails the suite before any upload.

 ── What a condition reads ───────────────────────────────────────────────────────────
 A piece sensor is read as POSITIVE evidence (the service's Slot::seen()): YES, NO or UNKNOWN, and
 UNKNOWN — a sensor declared but missing this boot, a distance held near with no confidence, a
 sample taken while its read-fault count moved — satisfies NEITHER `seesPiece` nor
 `stopsSeeingPiece`. A condition that names ANOTHER mechanism stores that mechanism's NAME, not
 its address: the service finds it by name at run time (a declaration copied without `inline` has
 one address per translation unit — the brief's P12). A declaration written without `.name` is
 on no robot's list: the words refuse it at build (A1's `a_mechanism_has_no_name`), and the plain
 `Until::sees(decl)` stores an EMPTY name — never "this mechanism" — which the step refuses.

 ONE mechanism's sensor per condition. Two different NAMES joined by `|` are `conflicting()` at
 once. The step's OWN sensor beside a NAME (`seesPiece | stopsSeeingPiece(intake)`) is one sensor
 when the step runs on that very mechanism and two otherwise — only the step knows which, so the
 condition keeps both facts (`sensor()` and `readsOwnSensorToo()`) and the step decides.

 Plain constexpr data: a bit set, a time, which mechanism's sensor. PROS-free, allocation-free.