Skip to content

Latest commit

 

History

History
375 lines (234 loc) · 11.1 KB

devices.md

File metadata and controls

375 lines (234 loc) · 11.1 KB

devices.hpp

mechanism/devices.hpp — the DEVICES one mechanism was built over, and what the build found for each of its ROLES.

This header declares 3 types (21 members) and 1 constant.

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

kDevicesMaxMotors

inline constexpr std::size_t kDevicesMaxMotors = 4

How many motors one mechanism's Devices has room for: config::kMaxMotorsPerMechanism, stated here because this header includes nothing above hal/ (robot/mechanism_parts.hpp and mechanism/service.hpp each static_assert that the two agree).

constant, declared at include/shulib/mechanism/devices.hpp:41.

struct Devices

struct Devices

The devices one mechanism was built over (header).

struct, declared at include/shulib/mechanism/devices.hpp:44.

Devices::motors

hal::MotorMechanism* motors = nullptr

A motor kind's actuator (power, position, speed); nullptr for a pneumatic or when ABSENT.

field, declared at include/shulib/mechanism/devices.hpp:46.

Devices::pneumatic

hal::PneumaticMechanism* pneumatic = nullptr

A pneumatic kind's actuator; nullptr for a motor kind or when ABSENT.

field, declared at include/shulib/mechanism/devices.hpp:48.

Devices::angleSensor

hal::IRotation* angleSensor = nullptr

Its angle sensor (a Rotation role).

field, declared at include/shulib/mechanism/devices.hpp:50.

Devices::homeSwitch

hal::IDigitalIn* homeSwitch = nullptr

Its home switch (a limit switch on a 3-wire line).

field, declared at include/shulib/mechanism/devices.hpp:52.

Devices::pieceDistance

hal::IDistance* pieceDistance = nullptr

Its piece sensor when it is a distance sensor (at most one of the three piece pointers).

field, declared at include/shulib/mechanism/devices.hpp:54.

Devices::pieceOptical

hal::IOptical* pieceOptical = nullptr

Its piece sensor when it is an optical sensor.

field, declared at include/shulib/mechanism/devices.hpp:56.

Devices::pieceSwitch

hal::IDigitalIn* pieceSwitch = nullptr

Its piece sensor when it is a limit switch.

field, declared at include/shulib/mechanism/devices.hpp:58.

Devices::pieceFaults

const hal::IReadFaults* pieceFaults = nullptr

The piece sensor's READ-FAULT count (the provider's readFaults(port) / lineReadFaults(line)): a sample taken while it moved was a HELD value, never evidence. nullptr = no piece sensor, or one that never screens a read.

field, declared at include/shulib/mechanism/devices.hpp:62.

Devices::homeSwitchFaults

const hal::IReadFaults* homeSwitchFaults = nullptr

The home switch's read-fault count (lineReadFaults(line)).

field, declared at include/shulib/mechanism/devices.hpp:64.

Devices::absence

const char* absence = ""

Why the mechanism was NOT built — the provider's sentence naming the port; "" when it was.

field, declared at include/shulib/mechanism/devices.hpp:66.

Devices::currentLimits

hal::IMotorCurrentLimit* currentLimits[kDevicesMaxMotors]{}

Each motor's own current limit, in the motors' order (MECH-S-A; the provider's currentLimit(port)); nullptr past the mechanism's motors, for a pneumatic or ABSENT one, and where the provider's motor cannot limit its current.

field, declared at include/shulib/mechanism/devices.hpp:70.

enum class RoleState

enum class RoleState : std::uint8_t

What the build found for ONE ROLE — the facts its boot line words (mechanism::roleLine, in mechanism/wiring.hpp).

enum class, declared at include/shulib/mechanism/devices.hpp:75.

RoleState::Present

Present

a smart device of the expected kind answered on its port

enumerator, declared at include/shulib/mechanism/devices.hpp:76.

RoleState::Refused

Refused

the provider refused it (its sentence names the port and what was found)

enumerator, declared at include/shulib/mechanism/devices.hpp:77.

RoleState::NotCheckable

NotCheckable

a 3-wire role: made, but the brain cannot see a 3-wire device (HA-158)

enumerator, declared at include/shulib/mechanism/devices.hpp:78.

RoleState::NotAsked

NotAsked

not requested: the mechanism was already ABSENT

enumerator, declared at include/shulib/mechanism/devices.hpp:79.

struct RoleFact

struct RoleFact

One role of one mechanism, as the build left it — what a boot line needs.

struct, declared at include/shulib/mechanism/devices.hpp:83.

RoleFact::role

const char* role = ""

The role in the boot line's words: "motor 1".."motor 4", "line 1", "line 2", "angle sensor", "home switch", "piece sensor".

field, declared at include/shulib/mechanism/devices.hpp:86.

RoleFact::port

std::uint8_t port = 0

Its smart port, physical (1..21); 0 for a 3-wire role.

field, declared at include/shulib/mechanism/devices.hpp:88.

RoleFact::line

std::uint8_t line = 0

Its 3-wire line, 1..8 = A..H; 0 for a smart role.

field, declared at include/shulib/mechanism/devices.hpp:90.

RoleFact::state

RoleState state = RoleState::NotAsked

What the build found.

field, declared at include/shulib/mechanism/devices.hpp:92.

RoleFact::degradeOnly

bool degradeOnly = false

A refusal that leaves the mechanism RUNNING WITHOUT this role (a piece sensor), rather than ABSENT.

field, declared at include/shulib/mechanism/devices.hpp:95.

RoleFact::refusal

const char* refusal = ""

The provider's refusal sentence when state is Refused (stable for the parts' lifetime); "" otherwise.

field, declared at include/shulib/mechanism/devices.hpp:98.

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

 mechanism/devices.hpp — the DEVICES one mechanism was built over, and what the build found for
 each of its ROLES (the mechanism core, chunk MECH-A1, 2026-10-08).

 robot::MechanismParts (robot/mechanism_parts.hpp) builds every role a mechanism declares — its
 motors or lines, its angle sensor, its home switch, its piece sensor — and hands the result to
 the mechanism service (MECH-A2) as one `Devices` per mechanism, and to the boot lines as one
 `RoleFact` per role. HAL POINTERS ONLY, and no other mechanism/ header included, so robot/ may
 produce these without depending on the vocabulary above it (mechanism/kinds.hpp, wiring.hpp).

 nullptr in a `Devices` = that role is not on this mechanism, or the mechanism is ABSENT, or (a
 piece sensor) it was refused and the mechanism runs WITHOUT one. The read-fault pointers are the
 provider's IDeviceProvider::readFaults / lineReadFaults for that sensor (hal/read_faults.hpp):
 the service reads a sample taken while one moved as HELD, never as evidence (MECH-A2's rule).

 Since MECH-S-A (2026-11-05) a motor mechanism's `Devices` also carries each motor's own CURRENT
 LIMIT (the provider's IDeviceProvider::currentLimit(port) — hal/motor_current_limit.hpp), in the
 motors' order: the service writes a stated cap through it at boot and reads every motor's limit
 back (mechanism/service.hpp). nullptr = no such motor, or a provider whose motor cannot limit its
 current (the service says so when a cap is stated).

 PROS-free, allocation-free.