|
libstp
Robotics library for Botball
|
#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 () |
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.
|
default |
| 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.
| 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.
|
inline |
Definition at line 212 of file SimWorld.hpp.
| void libstp::sim::SimWorld::configure | ( | const RobotConfig & | robot, |
| const SimMotorMap & | motors ) |
|
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.
| void libstp::sim::SimWorld::detachSensor | ( | uint8_t | analogPort | ) |
Detach any sensor bound to analogPort.
| 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).
|
inlinenoexcept |
Definition at line 101 of file SimWorld.hpp.
| 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.
| 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.
|
inlinenoexcept |
Definition at line 166 of file SimWorld.hpp.
|
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.
|
inlinenoexcept |
Definition at line 132 of file SimWorld.hpp.
| 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).
| Vec2 libstp::sim::SimWorld::sensorWorldPosition | ( | const SensorMount & | mount | ) | const |
World-frame position of a sensor mount attached to this robot.
|
inlinenoexcept |
Definition at line 108 of file SimWorld.hpp.
| void libstp::sim::SimWorld::setMap | ( | WorldMap | map | ) |
| 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.
| 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.
|
inlinenoexcept |
Definition at line 162 of file SimWorld.hpp.
| void libstp::sim::SimWorld::setPose | ( | const Pose2D & | pose | ) |
| void libstp::sim::SimWorld::tick | ( | float | dt | ) |
Advance the simulation by dt seconds (fixed-step integration for determinism).
|
inlinenoexcept |
Definition at line 211 of file SimWorld.hpp.
|
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.
|
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.
|
inlinenoexcept |
Definition at line 202 of file SimWorld.hpp.
|
inlinenoexcept |
Definition at line 133 of file SimWorld.hpp.