Skip to content

Latest commit

 

History

History
1078 lines (670 loc) · 34.4 KB

vision_frames.md

File metadata and controls

1078 lines (670 loc) · 34.4 KB

vision_frames.hpp

IVisionFrames — the V5 AI Vision camera read a FRAME at a time.

This header declares 9 types (59 members), 5 free functions, and 5 constants.

Extracted from include/shulib/hal/vision_frames.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

kMaxVisionDetections

inline constexpr std::size_t kMaxVisionDetections = 24

The camera's most detections per read (AIVISION_MAX_OBJECT_COUNT, the vendored ai_vision.h :33 — restated so this header stays PROS-free; hal/pros/ai_vision.hpp static_asserts the two agree).

constant, declared at include/shulib/hal/vision_frames.hpp:48.

kMaxColourDescriptors

inline constexpr std::uint8_t kMaxColourDescriptors = 7

Colour descriptor ids run 1..7 (ai_vision.h :86).

constant, declared at include/shulib/hal/vision_frames.hpp:50.

kMaxVisionClassNames

inline constexpr std::uint8_t kMaxVisionClassNames = 20

The most class names a camera's model can name (AIVISION_MAX_CLASSNAME_COUNT, ai_vision.h :34).

constant, declared at include/shulib/hal/vision_frames.hpp:52.

kVisionImageWidthPx

inline constexpr int kVisionImageWidthPx = 320

The camera's report width, in pixels (api.vex.com: 320 x 240; A4 register HA-193).

constant, declared at include/shulib/hal/vision_frames.hpp:54.

kVisionImageHeightPx

inline constexpr int kVisionImageHeightPx = 240

The camera's report height, in pixels (A4 register HA-193).

constant, declared at include/shulib/hal/vision_frames.hpp:56.

enum class DetectionKind

enum class DetectionKind : std::uint8_t

What a detection IS. OURS, not PROS's bit flags — the adapter maps each. No Tag: VIS1 turns tag detection OFF, and a tag that arrives anyway is counted in VisionFrame::skipped, never passed on.

enum class, declared at include/shulib/hal/vision_frames.hpp:60.

DetectionKind::Colour

Colour = 1

a colour descriptor's blob: id is the descriptor, 1..7 — one the settings wrote

enumerator, declared at include/shulib/hal/vision_frames.hpp:61.

DetectionKind::Code

Code = 2

a colour code's merged blob, id 1..5 (VIS1 writes none; its adapter withholds each)

enumerator, declared at include/shulib/hal/vision_frames.hpp:62.

DetectionKind::Object

Object = 3

the AI model's element: id is its class (meaningful only once ModelCheck::Matches)

enumerator, declared at include/shulib/hal/vision_frames.hpp:63.

struct Detection

struct Detection

One detection, copied OUT of the camera's packed record, in IMAGE pixels: +x right, +y DOWN, (0,0) the top-left corner; the box's LEFT and TOP edges plus its size (ai_vision.h :129-130's "left edge" / "top edge" — A4 register HA-193).

struct, declared at include/shulib/hal/vision_frames.hpp:69.

Detection::kind

DetectionKind kind = DetectionKind::Colour

what it is

field, declared at include/shulib/hal/vision_frames.hpp:70.

Detection::id

std::uint8_t id = 0

descriptor 1..7 / code 1..5 / model class 0..

field, declared at include/shulib/hal/vision_frames.hpp:71.

Detection::left

std::int16_t left = 0

px from the image's left edge

field, declared at include/shulib/hal/vision_frames.hpp:72.

Detection::top

std::int16_t top = 0

px from the image's top edge

field, declared at include/shulib/hal/vision_frames.hpp:73.

Detection::width

std::int16_t width = 0

px

field, declared at include/shulib/hal/vision_frames.hpp:74.

Detection::height

std::int16_t height = 0

px

field, declared at include/shulib/hal/vision_frames.hpp:75.

Detection::angleTenths

std::int16_t angleTenths = 0

Colour/Code only: the blob's angle, tenths of a degree

field, declared at include/shulib/hal/vision_frames.hpp:76.

Detection::score

std::int32_t score = -1

Object only: the raw score, 0..65535 (its scale: HA-198); -1 otherwise

field, declared at include/shulib/hal/vision_frames.hpp:77.

Detection::clipped

[[nodiscard]] constexpr bool clipped(int marginPx = 1) const noexcept

True when the box comes within marginPx of an edge of the image (inclusive at both ends) — part of the thing may be outside the picture, so its size says nothing about its distance.

function, declared at include/shulib/hal/vision_frames.hpp:81.

enum class FrameStatus

enum class FrameStatus : std::uint8_t

How a read went. ONLY Ok is evidence of anything.

enum class, declared at include/shulib/hal/vision_frames.hpp:89.

FrameStatus::NotRead

NotRead = 0

default-constructed: no read happened

enumerator, declared at include/shulib/hal/vision_frames.hpp:90.

FrameStatus::Ok

Ok

the count and every object read answered with a valid type

enumerator, declared at include/shulib/hal/vision_frames.hpp:91.

FrameStatus::ReadFault

ReadFault

a read failed — the count (PROS_ERR), or a read-back the adapter's once-a-second check could not make: NO detections — never a held frame

enumerator, declared at include/shulib/hal/vision_frames.hpp:92.

FrameStatus::PartialFault

PartialFault

the count answered, an object read did not (a torn read, HA-195): not evidence

enumerator, declared at include/shulib/hal/vision_frames.hpp:94.

FrameStatus::NotConfigured

NotConfigured

the adapter's set-up has not succeeded yet (or was lost): nothing was read

enumerator, declared at include/shulib/hal/vision_frames.hpp:95.

enum class ModelCheck

enum class ModelCheck : std::uint8_t

Whether the camera's AI model is the one the robot file expects, checked BY NAME (the camera's own class-name table, ai_vision.h :371-389) — a model class id means nothing until this says Matches: class 3 is yellowPin in VEX's Override model and blueRing in its Classroom model (A4 register HA-197). Object detections are passed on ONLY while it reads Matches.

enum class, declared at include/shulib/hal/vision_frames.hpp:102.

ModelCheck::NotAsked

NotAsked = 0

objects are off, or no read has asked yet

enumerator, declared at include/shulib/hal/vision_frames.hpp:103.

ModelCheck::Matches

Matches

every expected class name read back, in order

enumerator, declared at include/shulib/hal/vision_frames.hpp:104.

ModelCheck::Different

Different

the camera names another table (another model is selected on it), or nothing

enumerator, declared at include/shulib/hal/vision_frames.hpp:105.

ModelCheck::Unreadable

Unreadable

the class-name read failed (PROS_ERR) — the camera may still be booting

enumerator, declared at include/shulib/hal/vision_frames.hpp:106.

struct VisionFrame

struct VisionFrame

One READ of the camera — not a camera frame: the camera may update between the count read and the object reads (HA-195). What ONE poll saw, and when the poll finished.

struct, declared at include/shulib/hal/vision_frames.hpp:111.

VisionFrame::status

FrameStatus status = FrameStatus::NotRead

only Ok is evidence

field, declared at include/shulib/hal/vision_frames.hpp:112.

VisionFrame::readAt

units::Time readAt{}

The clock when the read COMPLETED — not the exposure: the IMAGE is older by an UNMEASURED age (A4 register HA-192; a consumer pairing a frame with a pose widens the pose's bound for it — vision::boundAtImage).

field, declared at include/shulib/hal/vision_frames.hpp:116.

VisionFrame::readSeq

std::uint32_t readSeq = 0

the adapter's poll count — NOT a camera frame number (HA-192)

field, declared at include/shulib/hal/vision_frames.hpp:117.

VisionFrame::reportedCount

std::int32_t reportedCount = 0

what the camera said it holds (it may say more than 24)

field, declared at include/shulib/hal/vision_frames.hpp:118.

VisionFrame::truncated

bool truncated = false

POSSIBLY FULL: the camera reported kMaxVisionDetections OR MORE, so detections may exist that were never sent (a read of exactly 24 cannot show that the 25th was not the one that mattered — whether a camera can report more than 24 is A4 register HA-198's question; the design does not depend on the answer). Never evidence of absence.

field, declared at include/shulib/hal/vision_frames.hpp:123.

VisionFrame::count

std::uint8_t count = 0

valid entries in detections

field, declared at include/shulib/hal/vision_frames.hpp:124.

VisionFrame::skipped

std::uint8_t skipped = 0

object reads with no valid type, or a TAG (tags are off)

field, declared at include/shulib/hal/vision_frames.hpp:125.

VisionFrame::model

ModelCheck model = ModelCheck::NotAsked

the AI model's check at this read

field, declared at include/shulib/hal/vision_frames.hpp:126.

VisionFrame::objectsWithheld

std::uint8_t objectsWithheld = 0

Object detections NOT passed on (the model not Matches, or an id past the table)

field, declared at include/shulib/hal/vision_frames.hpp:127.

VisionFrame::coloursWithheld

std::uint8_t coloursWithheld = 0

Colour and Code detections NOT passed on: a descriptor this program did not write (a slot another program left set), or any code (VIS1 writes none).

field, declared at include/shulib/hal/vision_frames.hpp:130.

VisionFrame::detections

Detection detections[kMaxVisionDetections]{}

[0, count) are valid; their order is UNVERIFIED (HA-198)

field, declared at include/shulib/hal/vision_frames.hpp:131.

VisionFrame::usable

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

True only when this read is EVIDENCE (status Ok).

function, declared at include/shulib/hal/vision_frames.hpp:134.

struct ColourDescriptor

struct ColourDescriptor

One colour descriptor as the camera takes it (ai_vision.h :85-92): an id 1..7, an RGB, a hue tolerance in degrees (1..40) and a saturation tolerance (0.1..1). EVERY FIELD IS A MEASURED FACT the team types (from VEXcode's AI Vision Utility); the defaults are UNSET and refuse.

struct, declared at include/shulib/hal/vision_frames.hpp:140.

ColourDescriptor::id

std::uint8_t id = 0

1..7; 0 = UNSET

field, declared at include/shulib/hal/vision_frames.hpp:141.

ColourDescriptor::red

std::uint8_t red = 0

0..255

field, declared at include/shulib/hal/vision_frames.hpp:142.

ColourDescriptor::green

std::uint8_t green = 0

0..255

field, declared at include/shulib/hal/vision_frames.hpp:143.

ColourDescriptor::blue

std::uint8_t blue = 0

0..255

field, declared at include/shulib/hal/vision_frames.hpp:144.

ColourDescriptor::hueRange

float hueRange = 0.0F

degrees, 1..40; 0 = UNSET

field, declared at include/shulib/hal/vision_frames.hpp:145.

ColourDescriptor::saturationRange

float saturationRange = 0.0F

0.1..1; 0 = UNSET

field, declared at include/shulib/hal/vision_frames.hpp:146.

ColourDescriptor::name

const char* name = ""

the team's word for it ("toggle red"), for every log line

field, declared at include/shulib/hal/vision_frames.hpp:147.

ColourDescriptor::provenance

const char* provenance = ""

who measured it, how, when, under what light — required

field, declared at include/shulib/hal/vision_frames.hpp:148.

colourDescriptorProblem

[[nodiscard]] constexpr const char* colourDescriptorProblem(const ColourDescriptor& c) noexcept

Why c is not acceptable, or nullptr. An all-zero descriptor (id, hue and saturation all 0) is UNSET and refuses; otherwise an id outside 1..7, a hue outside 1..40 or a saturation outside 0.1..1 (each inclusive, NaN refused), a null name, or a missing provenance each refuses by name. Nothing inside the vendored ranges is refused.

free function, declared at include/shulib/hal/vision_frames.hpp:155.

struct AiVisionSettings

struct AiVisionSettings

What the adapter writes to the camera: EXACTLY these modes — TAGS always OFF (VIS1 reads no tags, and Bench Tests station 12 leaves tags ON; a tag would take one of the 24 slots) — and these descriptors.

struct, declared at include/shulib/hal/vision_frames.hpp:180.

AiVisionSettings::colours

ColourDescriptor colours[kMaxColourDescriptors]{}

[0, colourCount) are written

field, declared at include/shulib/hal/vision_frames.hpp:181.

AiVisionSettings::colourCount

std::uint8_t colourCount = 0

0 => COLORS off

field, declared at include/shulib/hal/vision_frames.hpp:182.

AiVisionSettings::objects

bool objects = false

the AI model's game elements (ai_vision.h :73)

field, declared at include/shulib/hal/vision_frames.hpp:183.

AiVisionSettings::expectedClasses

const char* const* expectedClasses = nullptr

With objects: the class names the camera's model must report, in id order (the season's table — vision/override_elements.hpp's kOverrideClassNames). Required: an object id is opaque without it (ModelCheck). BORROWED: the array and its strings must outlive every adapter built from it (a constexpr table does).

field, declared at include/shulib/hal/vision_frames.hpp:188.

AiVisionSettings::expectedClassCount

std::uint8_t expectedClassCount = 0

entries in expectedClasses, 1..kMaxVisionClassNames

field, declared at include/shulib/hal/vision_frames.hpp:189.

AiVisionSettings::colourMerge

bool colourMerge = false

COLOR_MERGE (ai_vision.h :74)

field, declared at include/shulib/hal/vision_frames.hpp:190.

aiVisionSettingsProblem

[[nodiscard]] constexpr const char* aiVisionSettingsProblem(const AiVisionSettings& s) noexcept

The first problem with a settings block, or nullptr: more than 7 colours; a colour's own problem; two colours on one id (the camera silently keeps the second write, ai_vision.h :340); COLOR_MERGE with no colours; NOTHING turned on (a camera configured to see nothing is a wiring mistake, not a choice); objects on with no class table, an empty one, more than 20 names, or a null or empty name.

free function, declared at include/shulib/hal/vision_frames.hpp:197.

sameVisionText

[[nodiscard]] constexpr bool sameVisionText(const char* a, const char* b) noexcept

Two C strings equal by CONTENT (two null pointers are equal; a null and a non-null are not).

free function, declared at include/shulib/hal/vision_frames.hpp:234.

sameAiVisionSettings

[[nodiscard]] constexpr bool sameAiVisionSettings(const AiVisionSettings& a, const AiVisionSettings& b) noexcept

Whether two settings blocks would write the SAME thing to a camera: field by field, every string by content, the colours and class names only up to their counts (entries past a count are never written). The device provider serves a second request for a camera only with settings equal to the first's — two owners disagreeing about one camera is refused (hal/pros/device_provider.hpp).

free function, declared at include/shulib/hal/vision_frames.hpp:251.

struct CameraStatus

struct CameraStatus

What the camera's adapter knows about its own set-up and AI model, WITHOUT touching the device. The two strings are the adapter's own words, "" when there is nothing to say; they live as long as the adapter and change only on a read() (single-task).

struct, declared at include/shulib/hal/vision_frames.hpp:280.

CameraStatus::configured

bool configured = false

the set-up was written AND read back

field, declared at include/shulib/hal/vision_frames.hpp:281.

CameraStatus::setupProblem

const char* setupProblem = ""

why the last set-up failed or was re-done ("" when it holds)

field, declared at include/shulib/hal/vision_frames.hpp:282.

CameraStatus::model

ModelCheck model = ModelCheck::NotAsked

the AI model's check (NotAsked: objects off)

field, declared at include/shulib/hal/vision_frames.hpp:283.

CameraStatus::modelProblem

const char* modelProblem = ""

e.g. "class 0 is 'blueBall', the robot file expects 'redBluePin'"

field, declared at include/shulib/hal/vision_frames.hpp:284.

cameraStatusWords

[[nodiscard]] constexpr const char* cameraStatusWords(const CameraStatus& s) noexcept

The camera's state in a few ASCII words for a boot line or a bench page (the brain's screen turns non-ASCII into '?'): "NOT set up", "set up, objects off", "set up, model OK", "set up, model check pending" (the names did not read — re-asked once a second), "set up, model DIFFERENT". A caller that needs the reason prints setupProblem / modelProblem after it.

free function, declared at include/shulib/hal/vision_frames.hpp:291.

class IVisionFrames

class IVisionFrames

The camera, read a frame at a time. read() HITS THE DEVICE (one count read, then one read per detection; once a second, the PROS adapter's check of its settings and model; and, after a lost setting or a failed read, at most every half second, its set-up written again — A4 register HA-203), so it is not const, and reading at the rate a consumer needs is the consumer's job. Single-task by contract, like every device here.

class, declared at include/shulib/hal/vision_frames.hpp:309.

IVisionFrames::~IVisionFrames

virtual ~IVisionFrames() = default

Polymorphic base: delete-through-base is well-defined; the provider owns every camera.

function, declared at include/shulib/hal/vision_frames.hpp:312.

IVisionFrames::IVisionFrames

IVisionFrames() = default

Polymorphic base: delete-through-base is well-defined; the provider owns every camera. Default-constructible: the base has no state.

function, declared at include/shulib/hal/vision_frames.hpp:314.

IVisionFrames::IVisionFrames (overload 2)

IVisionFrames(const IVisionFrames&) = default

Polymorphic base: delete-through-base is well-defined; the provider owns every camera. Default-constructible: the base has no state. Copyable at the base (stateless); an adapter decides for itself.

function, declared at include/shulib/hal/vision_frames.hpp:316.

IVisionFrames::IVisionFrames (overload 3)

IVisionFrames(IVisionFrames&&) = default

Polymorphic base: delete-through-base is well-defined; the provider owns every camera. Default-constructible: the base has no state. Copyable at the base (stateless); an adapter decides for itself. Movable, same reasoning.

function, declared at include/shulib/hal/vision_frames.hpp:318.

IVisionFrames::operator=

IVisionFrames& operator=(const IVisionFrames&) = default

Polymorphic base: delete-through-base is well-defined; the provider owns every camera. Default-constructible: the base has no state. Copyable at the base (stateless); an adapter decides for itself. Movable, same reasoning. Copy-assignable, same reasoning.

function, declared at include/shulib/hal/vision_frames.hpp:320.

IVisionFrames::operator= (overload 2)

IVisionFrames& operator=(IVisionFrames&&) = default

Polymorphic base: delete-through-base is well-defined; the provider owns every camera. Default-constructible: the base has no state. Copyable at the base (stateless); an adapter decides for itself. Movable, same reasoning. Copy-assignable, same reasoning. Move-assignable, same reasoning.

function, declared at include/shulib/hal/vision_frames.hpp:322.

IVisionFrames::read

[[nodiscard]] virtual VisionFrame read() noexcept = 0

Read the camera NOW (A4 register HA-203: one call per detection, plus the count; once a second the PROS adapter's check, up to 28 more; and a set-up written again, up to 36 more). A failed read is a frame whose status says so, with NO detections — never the last good frame.

function, declared at include/shulib/hal/vision_frames.hpp:327.

IVisionFrames::status

[[nodiscard]] virtual CameraStatus status() const noexcept = 0

The adapter's set-up and model check as it last found them — never touches the device.

function, declared at include/shulib/hal/vision_frames.hpp:329.

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

 IVisionFrames — the V5 AI Vision camera read a FRAME at a time (chunk VIS1-A1, 2026-10-18).

 ── An F4-ADDITIVE SIBLING of the frozen hal::IVision ───────────────────────────────
 hal/vision.hpp is untouched, byte for byte (F4, LOCKED 2026-06-19). This seam sits beside it, exactly
 as IDigitalOut (F11), IController (F13), IDigitalIn (F14) and IReadFaults (MECH-A1) were added beside
 the frozen set. It is NOT FROZEN (the Freeze Register says so out loud, row F15).

 ── Why a sibling and not IVision ───────────────────────────────────────────────────
 IVision yields a class id, a bearing and a confidence (hal/vision.hpp's ObjectObservation). It has no
 detection TYPE — a colour descriptor 1 and a model class 1 are the same `classId` —, no BOX (so no
 size, no elevation, no range) and no TIME. And the PROS AI Vision API has NO frame counter and NO
 timestamp (the vendored include/pros/ai_vision.h, read whole): freshness can only be TIME-based. So a
 frame carries the time its READ completed, stamped from the run's IClock, and a read count that
 counts the ADAPTER's polls — never camera frames (A4 register HA-192). The image itself is OLDER than
 that read by an age nobody has measured (HA-192 again): a consumer that pairs a frame with a pose
 widens the pose's bound for it (vision::boundAtImage).

 ── A FAILED READ IS A FRAME THAT SAYS SO, WITH NO DETECTIONS ──────────────────────
 Never the last good frame held. The F4 sensor adapters answer a PROS_ERR with their last good value
 (MECH-A1's read-fault channel exists because of it); a frame cannot, because a held frame would read
 as a fresh "nothing changed". Only `FrameStatus::Ok` is evidence of anything.

 ── What the adapter writes, as data ────────────────────────────────────────────────
 AiVisionSettings is the robot file's camera block's adapter half (config/camera_config.hpp carries
 it): the colour descriptors the team measured with VEXcode's AI Vision Utility, whether the AI model's
 OBJECTS are on, and the class names the model must report BY NAME before an object id means anything
 (ModelCheck; HA-197). Its refusals are named — an all-zero descriptor is UNSET, never a colour.

 ── status(): the set-up and the model check, through the SEAM ──────────────────────
 The Robot's boot line and a bench page report whether the camera was set up and whether its AI model
 matched — and the builder never reads a frame and must never downcast to the PROS adapter. So the
 seam carries `status()`, which touches nothing (VIS1's re-check T2).

 Allocation-free (a fixed 24-entry array — AIVISION_MAX_OBJECT_COUNT, ai_vision.h :33), PROS-free,
 sim-free. Single-task by contract, like every device here.