Skip to content

Latest commit

 

History

History
302 lines (191 loc) · 10.3 KB

camera_feed.md

File metadata and controls

302 lines (191 loc) · 10.3 KB

camera_feed.hpp

CameraFeed — ONE read of the camera per period, handed to every consumer.

This header declares 3 types (15 members) and 1 free function.

Extracted from include/shulib/vision/camera_feed.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

struct CameraFeedConfig

struct CameraFeedConfig

The feed's one number — the TEAM's. 0 = UNSET, and refused (no library default).

struct, declared at include/shulib/vision/camera_feed.hpp:39.

CameraFeedConfig::minReadPeriodSeconds

double minReadPeriodSeconds = 0.0

Read at most this often, seconds — e.g. 0.033 (VEX's ~30 frames a second, A4 register HA-192).

field, declared at include/shulib/vision/camera_feed.hpp:41.

cameraFeedConfigProblem

[[nodiscard]] constexpr const char* cameraFeedConfigProblem(const CameraFeedConfig& c) noexcept

The first problem with a feed config, or nullptr: a period that is UNSET, zero, negative, NaN or infinite (an infinite one would read once and never again).

free function, declared at include/shulib/vision/camera_feed.hpp:46.

struct CameraFeedStats

struct CameraFeedStats

What the feed has seen — for a bench page, and for A4 register HA-203's settle (the read's cost).

struct, declared at include/shulib/vision/camera_feed.hpp:54.

CameraFeedStats::reads

std::uint32_t reads = 0

reads made

field, declared at include/shulib/vision/camera_feed.hpp:55.

CameraFeedStats::usable

std::uint32_t usable = 0

of them, status Ok

field, declared at include/shulib/vision/camera_feed.hpp:56.

CameraFeedStats::readFaults

std::uint32_t readFaults = 0

of them, status ReadFault

field, declared at include/shulib/vision/camera_feed.hpp:57.

CameraFeedStats::partialFaults

std::uint32_t partialFaults = 0

of them, status PartialFault (a torn read)

field, declared at include/shulib/vision/camera_feed.hpp:58.

CameraFeedStats::notConfigured

std::uint32_t notConfigured = 0

of them, status NotConfigured

field, declared at include/shulib/vision/camera_feed.hpp:59.

CameraFeedStats::truncated

std::uint32_t truncated = 0

usable reads that were POSSIBLY FULL (24 or more reported)

field, declared at include/shulib/vision/camera_feed.hpp:60.

CameraFeedStats::objectsWithheld

std::uint32_t objectsWithheld = 0

Object detections the adapter withheld, summed over the reads

field, declared at include/shulib/vision/camera_feed.hpp:61.

CameraFeedStats::coloursWithheld

std::uint32_t coloursWithheld = 0

Colour and Code detections the adapter withheld, summed

field, declared at include/shulib/vision/camera_feed.hpp:62.

CameraFeedStats::lastReadSeconds

double lastReadSeconds = 0.0

how long the last read took: the clock after it less before it

field, declared at include/shulib/vision/camera_feed.hpp:63.

CameraFeedStats::slowestReadSeconds

double slowestReadSeconds = 0.0

the longest read so far, seconds

field, declared at include/shulib/vision/camera_feed.hpp:64.

class CameraFeed

class CameraFeed

One camera read per period for every consumer (header). Holds references: the camera and the clock must outlive the feed. PRECONDITION: cameraFeedConfigProblem(cfg) == nullptr (a consumer that builds one asks first and refuses to construct, naming it).

class, declared at include/shulib/vision/camera_feed.hpp:70.

CameraFeed::CameraFeed

CameraFeed(hal::IVisionFrames& camera, const hal::IClock& clock, const CameraFeedConfig& cfg) noexcept

Reads nothing until the first tick().

function, declared at include/shulib/vision/camera_feed.hpp:73.

CameraFeed::tick

bool tick()

Read the camera if at least the period has passed since the last read BEGAN (the first call always reads); never more than one read per call. True when it read — latest() is then a new frame.

function, declared at include/shulib/vision/camera_feed.hpp:78.

CameraFeed::latest

[[nodiscard]] const hal::VisionFrame& latest() const noexcept

The latest READ — a fault frame included, never the last good one held; a default frame (status NotRead) before the first.

function, declared at include/shulib/vision/camera_feed.hpp:111.

CameraFeed::stats

[[nodiscard]] const CameraFeedStats& stats() const noexcept

What the feed has seen.

function, declared at include/shulib/vision/camera_feed.hpp:113.

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

 CameraFeed — ONE read of the camera per period, handed to every consumer (chunk VIS1-A2, 2026-11-03).

 ── Who reads the camera, and how often ─────────────────────────────────────────────
 A read is one device call for the count and one per detection (up to 25), plus the adapter's own
 checks (hal::IVisionFrames::read()), and the library is single-task by contract: every device here is
 read from the caller's own loop, never from a task of the library's. So the program's loop — the
 driver loop's per-tick hook, an auton step's wait — calls tick() once per ITS tick, and the feed reads
 the camera only when at least `minReadPeriodSeconds` has passed since its last read BEGAN (never twice
 in one call). Every consumer — the Toggle tracker, the piece finder, and later the automatic flip and
 the drive to a piece — is handed the SAME frame through latest(): two consumers never cost two reads,
 and none reads faster than the camera changes (VEX states about 30 frames a second — A4 register
 HA-192 — so about 0.033 s is the natural floor; the period is the TEAM's number, and an UNSET one is
 refused: no library default).

 ── latest() is the latest READ — never the last good one ───────────────────────────
 A fault frame included: a frame held over a failed read would read as a fresh "nothing changed"
 (hal/vision_frames.hpp). Only `FrameStatus::Ok` is evidence, and each consumer checks it.

 ── Every read is timed ─────────────────────────────────────────────────────────────
 With the clock before and after it (on the robot that clock is pros::micros()-backed —
 hal/pros/clock.hpp), so stats() carries the last and the slowest read's cost: the measurement
 A4 register HA-203 (one read is cheap enough for the driver loop's tick) needs, from the loop the
 read actually runs in.

 No task, no allocation, PROS-free, sim-free; single-task, like every device here. NO HARDWARE CLAIM:
 it has run against the host's fake camera and nothing else.