libstp
Robotics library for Botball
Loading...
Searching...
No Matches
libstp::map::WorldMap Class Reference

#include <WorldMap.hpp>

Public Member Functions

 WorldMap ()=default
float tableWidthCm () const noexcept
float tableHeightCm () const noexcept
const std::vector< MapSegment > & segments () const noexcept
std::size_t layerCount () const noexcept
const std::vector< MapLayer > & layers () const noexcept
const std::vector< MapTransition > & transitions () const noexcept
int layerIndex (const std::string &id) const noexcept
 Index of the layer with the given id, or -1 when absent.
const std::vector< MapSegment > & layerSegments (std::size_t idx) const noexcept
bool isOnLine (float xCm, float yCm, std::size_t layerIdx) const
bool isOnWall (float xCm, float yCm, std::size_t layerIdx) const
std::vector< MapSegment > lines () const
 Subset of segments() with Kind::Line.
std::vector< MapSegment > walls () const
bool isOnBlackLine (float xCm, float yCm) const
bool isOnLine (float xCm, float yCm) const
bool isOnWall (float xCm, float yCm) const
float distanceToNearestLine (float xCm, float yCm) const
float distanceToNearestWall (float xCm, float yCm) const
Point2D sensorFieldPosition (float robotXCm, float robotYCm, float robotHeadingRad, const SensorOffset &sensor) const
bool sensorIsOnLine (float robotXCm, float robotYCm, float robotHeadingRad, const SensorOffset &sensor) const
 Convenience: sensorFieldPosition + isOnLine.
bool sensorIsOnWall (float robotXCm, float robotYCm, float robotHeadingRad, const SensorOffset &sensor) const
 Convenience: sensorFieldPosition + isOnWall.
void loadFtmap (const std::filesystem::path &path)
void parseFtmap (const std::string &content)
void setTable (float widthCm, float heightCm) noexcept
void addSegment (const MapSegment &seg)
void clear () noexcept

Detailed Description

Canonical Botball table map: bounds + line/wall segments + the geometric queries the particle filter and existing TableMap users need.

Coordinate convention: origin at bottom-left of the table, +X right, +Y up, all values in cm. The ftmap on-disk format stores Y top-down; every parser in this class flips it on ingest so the in-memory representation stays bottom-up.

This module supersedes both the in-sim WorldMap (libstp-sim still owns its copy until Phase 1 commit B migrates it) and the Python TableMap (deleted in a later commit). Sensor projection lives here so the Python side can call into it without paying FFI per particle.

Definition at line 73 of file WorldMap.hpp.

Constructor & Destructor Documentation

◆ WorldMap()

libstp::map::WorldMap::WorldMap ( )
default

Member Function Documentation

◆ addSegment()

void libstp::map::WorldMap::addSegment ( const MapSegment & seg)
inline

Definition at line 190 of file WorldMap.hpp.

◆ clear()

void libstp::map::WorldMap::clear ( )
inlinenoexcept

Definition at line 191 of file WorldMap.hpp.

◆ distanceToNearestLine()

float libstp::map::WorldMap::distanceToNearestLine ( float xCm,
float yCm ) const

Shortest distance from (xCm, yCm) to any line segment centerline, in cm. Returns +infinity when the map has no lines. Used by the particle filter as a soft observation likelihood.

◆ distanceToNearestWall()

float libstp::map::WorldMap::distanceToNearestWall ( float xCm,
float yCm ) const

Shortest distance from (xCm, yCm) to any wall segment OR border edge. Returns +infinity when the map has neither. Border edges are included so a robot just inside the table still gets a finite "distance to wall" reading.

◆ isOnBlackLine()

bool libstp::map::WorldMap::isOnBlackLine ( float xCm,
float yCm ) const

Legacy alias — kept so callers porting from libstp::sim::WorldMap or the Python TableMap don't have to grep twice. Same logic as isOnLine.

◆ isOnLine() [1/2]

bool libstp::map::WorldMap::isOnLine ( float xCm,
float yCm ) const

True when (xCm, yCm) is within max(0.75 cm, widthCm/2) of any line segment. The 0.75 cm floor is the heuristic carried over from the web-ide TableMapService — thin authored lines still register as "on the line" for IR detection purposes.

◆ isOnLine() [2/2]

bool libstp::map::WorldMap::isOnLine ( float xCm,
float yCm,
std::size_t layerIdx ) const

Layer-scoped variants of the point queries. Same semantics as the no-arg versions but against layer idx's segments (table border walls still apply to every layer).

◆ isOnWall() [1/2]

bool libstp::map::WorldMap::isOnWall ( float xCm,
float yCm ) const

True when the point is within widthCm/2 of any wall segment OR within 0.5 cm of any of the four border edges. The border fallback is what makes "robot at the edge of the table" register as on-wall without needing the .ftmap to spell out border walls.

◆ isOnWall() [2/2]

bool libstp::map::WorldMap::isOnWall ( float xCm,
float yCm,
std::size_t layerIdx ) const

◆ layerCount()

std::size_t libstp::map::WorldMap::layerCount ( ) const
inlinenoexcept

Definition at line 90 of file WorldMap.hpp.

◆ layerIndex()

int libstp::map::WorldMap::layerIndex ( const std::string & id) const
noexcept

Index of the layer with the given id, or -1 when absent.

◆ layers()

const std::vector< MapLayer > & libstp::map::WorldMap::layers ( ) const
inlinenoexcept

Definition at line 91 of file WorldMap.hpp.

◆ layerSegments()

const std::vector< MapSegment > & libstp::map::WorldMap::layerSegments ( std::size_t idx) const
noexcept

Segments of layer idx. Falls back to the ground segments when the map has no explicit layers or idx is out of range.

◆ lines()

std::vector< MapSegment > libstp::map::WorldMap::lines ( ) const

Subset of segments() with Kind::Line.

◆ loadFtmap()

void libstp::map::WorldMap::loadFtmap ( const std::filesystem::path & path)

Load an .ftmap file (flowchart-table-map v1, JSON-on-disk; we parse it via yaml-cpp because YAML is a JSON superset). Throws FtmapParseError for any schema violation.

◆ parseFtmap()

void libstp::map::WorldMap::parseFtmap ( const std::string & content)

Parse an in-memory ftmap payload (flowchart-table-map v1 or v2). Used by tests and by Python callers — including TableMap.from_ftmap, whose binding serializes the project's ftmap dict to JSON and hands it here so there is one parser.

◆ segments()

const std::vector< MapSegment > & libstp::map::WorldMap::segments ( ) const
inlinenoexcept

Definition at line 81 of file WorldMap.hpp.

◆ sensorFieldPosition()

Point2D libstp::map::WorldMap::sensorFieldPosition ( float robotXCm,
float robotYCm,
float robotHeadingRad,
const SensorOffset & sensor ) const

Project a sensor mounted at sensor (robot-local frame) into the field frame given the robot pose. forward_cm is along the heading, strafe_cm is 90° CCW. Equivalent to the body→world rotation used by raccoon.robot.table_map.sensor_field_position (kept bit-for-bit identical so the Python TableMap can be retired without behavior drift).

◆ sensorIsOnLine()

bool libstp::map::WorldMap::sensorIsOnLine ( float robotXCm,
float robotYCm,
float robotHeadingRad,
const SensorOffset & sensor ) const

Convenience: sensorFieldPosition + isOnLine.

◆ sensorIsOnWall()

bool libstp::map::WorldMap::sensorIsOnWall ( float robotXCm,
float robotYCm,
float robotHeadingRad,
const SensorOffset & sensor ) const

Convenience: sensorFieldPosition + isOnWall.

◆ setTable()

void libstp::map::WorldMap::setTable ( float widthCm,
float heightCm )
inlinenoexcept

Definition at line 185 of file WorldMap.hpp.

◆ tableHeightCm()

float libstp::map::WorldMap::tableHeightCm ( ) const
inlinenoexcept

Definition at line 80 of file WorldMap.hpp.

◆ tableWidthCm()

float libstp::map::WorldMap::tableWidthCm ( ) const
inlinenoexcept

Definition at line 79 of file WorldMap.hpp.

◆ transitions()

const std::vector< MapTransition > & libstp::map::WorldMap::transitions ( ) const
inlinenoexcept

Definition at line 92 of file WorldMap.hpp.

◆ walls()

std::vector< MapSegment > libstp::map::WorldMap::walls ( ) const

Subset of segments() with Kind::Wall plus the four table border edges synthesized from the table bounds. The border edges have width=0 — isOnWall treats them as zero-thickness collision lines via the same min-threshold rule used for thin black lines.


The documentation for this class was generated from the following file:
  • /home/runner/work/raccoon-lib/raccoon-lib/modules/libstp-map/include/libstp/map/WorldMap.hpp