testing.sim¶
High-level Python API for the libstp simulator.
This module wraps raccoon.sim (the pybind11 bindings) with ergonomic
helpers so a team’s pytest can do:
from raccoon.testing.sim import use_scene
with use_scene("empty_table.ftmap",
robot=my_robot_config,
start=(50, 50, 0)):
await drive_forward(cm=30).run_step(robot)
assert pose().x == pytest.approx(80.0, abs=2.0)
The context manager configures the process-wide MockPlatform singleton
to talk to a fresh SimWorld for the duration of the block, then detaches
on exit so subsequent code paths see the stock mock HAL.
Only available when the wheel is built with DRIVER_BUNDLE=mock — the
raccoon.sim.mock submodule must be present. Importing this module on a
wombat-bundle wheel raises RuntimeError.
This module lives under raccoon.testing because it is exclusively
a test-harness concern; the actual C++ sim bindings still live at
raccoon.sim. Historically this API was at raccoon.step.sim — that
path remains as a deprecation shim and will be removed in a future release.
Classes¶
Sim-side counterpart to the team's GenericRobot geometry/kinematics. |
Functions¶
|
Attach a fresh sim to the MockPlatform singleton. |
|
Disconnect any attached sim. The mock HAL goes back to zero odometry. |
|
Return the sim's current ground-truth pose (cm, cm, rad). |
|
Return the sim's current yaw rate in rad/s. |
|
Manually advance the sim. Use this for fully deterministic tests. |
|
Context manager: attach the sim for the duration of a |
Module Contents¶
- class testing.sim.LineSensorMount¶
- class testing.sim.DistanceSensorMount¶
- class testing.sim.SimRobotConfig¶
Sim-side counterpart to the team’s GenericRobot geometry/kinematics.
Defaults match a typical Botball wombat. Override fields that differ on your robot — they must agree with whatever the real
Drive/DifferentialKinematicswere constructed with so the sim physics matches what the motion controllers expect.- line_sensors: List[LineSensorMount] = []¶
- distance_sensors: List[DistanceSensorMount] = []¶
- testing.sim.configure(scene: str | pathlib.Path, *, robot: SimRobotConfig | None = None, start: PoseLike = (0.0, 0.0, 0.0), auto_tick: bool = True, auto_tick_max_step_sec: float = 0.05) None¶
Attach a fresh sim to the MockPlatform singleton.
After this returns, motor commands written through any HAL
Motordrive the simulated chassis, andOdometryBridge::readOdometryreports its pose. Auto-tick is enabled by default so a real motion loop reading odometry on its own schedule will see the sim advance with wall time.
- testing.sim.pose() raccoon.sim.Pose2D¶
Return the sim’s current ground-truth pose (cm, cm, rad).
- testing.sim.tick(dt_seconds: float) None¶
Manually advance the sim. Use this for fully deterministic tests.
- testing.sim.use_scene(scene: str | pathlib.Path, *, robot: SimRobotConfig | None = None, start: PoseLike = (0.0, 0.0, 0.0), auto_tick: bool = True, auto_tick_max_step_sec: float = 0.05) Iterator[None]¶
Context manager: attach the sim for the duration of a
withblock.Example:
with use_scene("empty_table.ftmap", start=(20, 50, 0)): await drive_forward(cm=30).run_step(my_robot) x, y, _ = pose() assert x == pytest.approx(50, abs=2)