libstp
Robotics library for Botball
Loading...
Searching...
No Matches
libstp::sim::SimWorld Class Reference

#include <SimWorld.hpp>

Classes

struct  OdometryDrift

Public Member Functions

 SimWorld ()=default
void configure (const RobotConfig &robot, const SimMotorMap &motors)
void setMap (WorldMap map)
const WorldMap & map () const noexcept
int currentLayer () const noexcept
void setCurrentLayer (int idx) noexcept
void attachLineSensor (uint8_t analogPort, float forwardCm, float strafeCm, std::string name={})
void attachDistanceSensor (uint8_t analogPort, float forwardCm, float strafeCm, float mountAngleRad=0.0f, float maxRangeCm=100.0f, std::string name={})
void detachSensor (uint8_t analogPort)
 Detach any sensor bound to analogPort.
std::optional< uint16_t > readAnalog (uint8_t analogPort) const
void setPose (const Pose2D &pose)
Pose2D pose () const noexcept
float yawRateRadS () const noexcept
Pose2D odometryPose () const noexcept
void setOdometryDrift (float vxBias, float vyBias, float yawBias) noexcept
OdometryDrift odometryDrift () const noexcept
void setMotorCommand (uint8_t port, int signedPercent)
void setMotorVelocityCommand (uint8_t port, int bemfUnits)
int motorBemf (uint8_t port) const
int motorPositionTicks (uint8_t port) const
void tick (float dt)
Vec2 sensorWorldPosition (const SensorMount &mount) const
 World-frame position of a sensor mount attached to this robot.
bool isSensorOnBlackLine (const SensorMount &mount) const
float wheelOmegaLeft () const noexcept
float wheelOmegaRight () const noexcept
float wheelOmega (std::size_t idx) const noexcept
const std::vector< Pose2D > & trace () const noexcept
void clearTrace ()

Detailed Description

Ground-truth simulated robot. Owns a pose, integrates motor commands through a diff-drive kinematic model, and snaps motion through the collision layer so it respects walls.

Not a singleton by design — tests create their own and the mock HAL will hold a single instance at the platform layer.

Definition at line 94 of file SimWorld.hpp.

Constructor & Destructor Documentation

◆ SimWorld()

libstp::sim::SimWorld::SimWorld ( )
default

Member Function Documentation

◆ attachDistanceSensor()

void libstp::sim::SimWorld::attachDistanceSensor ( uint8_t analogPort,
float forwardCm,
float strafeCm,
float mountAngleRad = 0.0f,
float maxRangeCm = 100.0f,
std::string name = {} )

Register a distance sensor on analogPort. Uses raycast against walls. Returns the KIPR ET empirical polynomial value in [0, 4095] truncated to [0, 1023] to match the analog ADC range.

◆ attachLineSensor()

void libstp::sim::SimWorld::attachLineSensor ( uint8_t analogPort,
float forwardCm,
float strafeCm,
std::string name = {} )

Register a line sensor on analogPort. Sampled by readAnalog: returns ~0 when the mount is over a black line, ~1023 otherwise.

◆ clearTrace()

void libstp::sim::SimWorld::clearTrace ( )
inline

Definition at line 212 of file SimWorld.hpp.

◆ configure()

void libstp::sim::SimWorld::configure ( const RobotConfig & robot,
const SimMotorMap & motors )

◆ currentLayer()

int libstp::sim::SimWorld::currentLayer ( ) const
inlinenoexcept

Index of the table layer (plane) the robot is currently on. Line sensors and collision resolve against this layer's segments; the robot switches layers when it crosses a map transition (ramp). For v1 (single-layer) maps this is always the ground layer (0).

Definition at line 107 of file SimWorld.hpp.

◆ detachSensor()

void libstp::sim::SimWorld::detachSensor ( uint8_t analogPort)

Detach any sensor bound to analogPort.

◆ isSensorOnBlackLine()

bool libstp::sim::SimWorld::isSensorOnBlackLine ( const SensorMount & mount) const

Convenience: true iff the line sensor mount is currently over a black line, with optional noise in the 0..1 probability domain (default 0 = deterministic).

◆ map()

const WorldMap & libstp::sim::SimWorld::map ( ) const
inlinenoexcept

Definition at line 101 of file SimWorld.hpp.

◆ motorBemf()

int libstp::sim::SimWorld::motorBemf ( uint8_t port) const

Live BEMF feedback for port, derived from the sim's current wheel ω and the calibration. Returned in raw integer BEMF units so it round-trips with Motor::getBemf.

◆ motorPositionTicks()

int libstp::sim::SimWorld::motorPositionTicks ( uint8_t port) const

Integrated motor encoder position for port, returned in encoder ticks so it round-trips with Motor::getPosition.

◆ odometryDrift()

OdometryDrift libstp::sim::SimWorld::odometryDrift ( ) const
inlinenoexcept

Definition at line 166 of file SimWorld.hpp.

◆ odometryPose()

Pose2D libstp::sim::SimWorld::odometryPose ( ) const
inlinenoexcept

Dead-reckoned odometry pose, integrated from the body-frame chassis velocities (vx, vy, yawRate) the same way real wheel/IMU odometry is — independent of the collision-clamped physical pose(). This is the frame the production motion controllers read: by construction a +vx command grows the forward projection, a +vy command grows the "right-positive" lateral projection, and a +wz command grows the heading, consistently at any heading. (The physical pose() stays in the standard +y=left world frame used for rendering / sensors / collision; the two intentionally differ on the lateral axis because the sim integrates a +vy command as the robot's physical RIGHT.)

Definition at line 145 of file SimWorld.hpp.

◆ pose()

Pose2D libstp::sim::SimWorld::pose ( ) const
inlinenoexcept

Definition at line 132 of file SimWorld.hpp.

◆ readAnalog()

std::optional< uint16_t > libstp::sim::SimWorld::readAnalog ( uint8_t analogPort) const

Sample the analog value currently visible at analogPort. Returns std::nullopt if no sensor is registered on that port (the mock HAL then falls through to its stock static analog values).

◆ sensorWorldPosition()

Vec2 libstp::sim::SimWorld::sensorWorldPosition ( const SensorMount & mount) const

World-frame position of a sensor mount attached to this robot.

◆ setCurrentLayer()

void libstp::sim::SimWorld::setCurrentLayer ( int idx)
inlinenoexcept

Definition at line 108 of file SimWorld.hpp.

◆ setMap()

void libstp::sim::SimWorld::setMap ( WorldMap map)

◆ setMotorCommand()

void libstp::sim::SimWorld::setMotorCommand ( uint8_t port,
int signedPercent )

Signed motor command in the range [-100, 100]. Matches the scale used by HAL Motor::setSpeed.

◆ setMotorVelocityCommand()

void libstp::sim::SimWorld::setMotorVelocityCommand ( uint8_t port,
int bemfUnits )

Closed-loop velocity command in BEMF integer units (matches HAL Motor::setVelocity). Converted internally to a wheel ω target via the SimMotorMap.ticksToRad calibration.

◆ setOdometryDrift()

void libstp::sim::SimWorld::setOdometryDrift ( float vxBias,
float vyBias,
float yawBias )
inlinenoexcept

Definition at line 162 of file SimWorld.hpp.

◆ setPose()

void libstp::sim::SimWorld::setPose ( const Pose2D & pose)

◆ tick()

void libstp::sim::SimWorld::tick ( float dt)

Advance the simulation by dt seconds (fixed-step integration for determinism).

◆ trace()

const std::vector< Pose2D > & libstp::sim::SimWorld::trace ( ) const
inlinenoexcept

Definition at line 211 of file SimWorld.hpp.

◆ wheelOmega()

float libstp::sim::SimWorld::wheelOmega ( std::size_t idx) const
inlinenoexcept

Generic wheel ω accessor. Indices: diff = {0:L, 1:R}; mecanum = {0:FL, 1:FR, 2:BL, 3:BR}.

Definition at line 206 of file SimWorld.hpp.

◆ wheelOmegaLeft()

float libstp::sim::SimWorld::wheelOmegaLeft ( ) const
inlinenoexcept

Current left/right wheel angular velocity (rad/s) — exposed for tests and for simulated BEMF output. For mecanum drivetrains these alias to the front-left and front-right wheels.

Definition at line 201 of file SimWorld.hpp.

◆ wheelOmegaRight()

float libstp::sim::SimWorld::wheelOmegaRight ( ) const
inlinenoexcept

Definition at line 202 of file SimWorld.hpp.

◆ yawRateRadS()

float libstp::sim::SimWorld::yawRateRadS ( ) const
inlinenoexcept

Definition at line 133 of file SimWorld.hpp.


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