|
libstp
Robotics library for Botball
|
#include <MockPlatform.hpp>
Public Types | |
| using | ClockFn = std::function<double()> |
Public Member Functions | |
| bool | init () |
| bool | update () |
| void | setMotor (uint8_t port, MotorDir dir, uint32_t value) |
| void | setMotorVelocity (uint8_t port, int signedBemfUnits) |
| float | getBemf (uint8_t port) const |
| int | getMotorPosition (uint8_t port) const |
| void | setServo (uint8_t port, ServoMode mode, uint16_t pos) |
| uint16_t | getAnalog (uint8_t port) const |
| bool | getDigital (uint8_t bit) const |
| uint16_t | getDigitalRaw () const |
| float | getGyroX () const |
| float | getGyroY () const |
| float | getGyroZ () const |
| float | getAccelX () const |
| float | getAccelY () const |
| float | getAccelZ () const |
| float | getMagX () const |
| float | getMagY () const |
| float | getMagZ () const |
| float | getQuatW () const |
| float | getQuatX () const |
| float | getQuatY () const |
| float | getQuatZ () const |
| uint32_t | getLastUpdateUs () const |
| void | setAnalogValue (uint8_t port, uint16_t value) |
| void | setDigitalValue (uint8_t bit, bool value) |
| void | setIMUValues (float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) |
| void | configureSim (const libstp::sim::RobotConfig &robot, const libstp::sim::SimMotorMap &motors, libstp::sim::WorldMap map, const libstp::sim::Pose2D &startPose) |
| void | detachSim () |
| bool | hasSim () const |
| libstp::sim::SimWorld * | sim () |
| libstp::sim::Pose2D | simPose () const |
| libstp::sim::Pose2D | simRelativePose () const |
| libstp::sim::Pose2D | simOdometryRelativePose () const |
| void | resetSimOrigin () |
| float | simYawRate () const |
| int | simCurrentLayer () const |
| void | tickSim (float dtSeconds) |
| void | setAutoTickEnabled (bool enabled) |
| bool | isAutoTickEnabled () const |
| void | setClockSource (ClockFn clock) |
| void | setAutoTickMaxStep (float maxDtSeconds) |
| void | autoTickIfEnabled () |
Static Public Member Functions | |
| static MockPlatform & | instance () |
In-process backend used by the mock driver bundle.
HAL driver implementations call this singleton instead of touching real hardware. Tests can also seed state through the helper setters below.
Definition at line 24 of file MockPlatform.hpp.
| using platform::mock::core::MockPlatform::ClockFn = std::function<double()> |
Replace the wall-clock source used by auto-tick. Returns seconds. Default is monotonic steady_clock. Unit tests can inject a fake clock to freeze or advance time deterministically.
Definition at line 131 of file MockPlatform.hpp.
| void platform::mock::core::MockPlatform::autoTickIfEnabled | ( | ) |
Invoked from query paths (internal). Advances sim by clock delta when auto-tick is enabled, else no-op. Safe to call with no sim.
| void platform::mock::core::MockPlatform::configureSim | ( | const libstp::sim::RobotConfig & | robot, |
| const libstp::sim::SimMotorMap & | motors, | ||
| libstp::sim::WorldMap | map, | ||
| const libstp::sim::Pose2D & | startPose ) |
| void platform::mock::core::MockPlatform::detachSim | ( | ) |
| float platform::mock::core::MockPlatform::getAccelX | ( | ) | const |
| float platform::mock::core::MockPlatform::getAccelY | ( | ) | const |
| float platform::mock::core::MockPlatform::getAccelZ | ( | ) | const |
| uint16_t platform::mock::core::MockPlatform::getAnalog | ( | uint8_t | port | ) | const |
| float platform::mock::core::MockPlatform::getBemf | ( | uint8_t | port | ) | const |
| bool platform::mock::core::MockPlatform::getDigital | ( | uint8_t | bit | ) | const |
| uint16_t platform::mock::core::MockPlatform::getDigitalRaw | ( | ) | const |
| float platform::mock::core::MockPlatform::getGyroX | ( | ) | const |
| float platform::mock::core::MockPlatform::getGyroY | ( | ) | const |
| float platform::mock::core::MockPlatform::getGyroZ | ( | ) | const |
| uint32_t platform::mock::core::MockPlatform::getLastUpdateUs | ( | ) | const |
| float platform::mock::core::MockPlatform::getMagX | ( | ) | const |
| float platform::mock::core::MockPlatform::getMagY | ( | ) | const |
| float platform::mock::core::MockPlatform::getMagZ | ( | ) | const |
| int platform::mock::core::MockPlatform::getMotorPosition | ( | uint8_t | port | ) | const |
| float platform::mock::core::MockPlatform::getQuatW | ( | ) | const |
| float platform::mock::core::MockPlatform::getQuatX | ( | ) | const |
| float platform::mock::core::MockPlatform::getQuatY | ( | ) | const |
| float platform::mock::core::MockPlatform::getQuatZ | ( | ) | const |
| bool platform::mock::core::MockPlatform::hasSim | ( | ) | const |
| bool platform::mock::core::MockPlatform::init | ( | ) |
|
inlinestatic |
Definition at line 27 of file MockPlatform.hpp.
| bool platform::mock::core::MockPlatform::isAutoTickEnabled | ( | ) | const |
| void platform::mock::core::MockPlatform::resetSimOrigin | ( | ) |
Capture the current ground-truth sim pose as the origin for simRelativePose(). Equivalent to telling the coprocessor to zero its integrator.
| void platform::mock::core::MockPlatform::setAnalogValue | ( | uint8_t | port, |
| uint16_t | value ) |
| void platform::mock::core::MockPlatform::setAutoTickEnabled | ( | bool | enabled | ) |
Auto-tick mode: when enabled, every call into the mock HAL that reads sim state (getAnalog, MockOdometry queries, gyroZ) first advances the sim by the wall-clock delta since the last tick. Disabled by default so C++ tests stay deterministic with explicit tickSim() calls.
| void platform::mock::core::MockPlatform::setAutoTickMaxStep | ( | float | maxDtSeconds | ) |
Cap on how far a single auto-tick advances the sim — prevents a long pause (e.g. breakpoint, slow test setup) from teleporting the robot. Default 50 ms.
| void platform::mock::core::MockPlatform::setClockSource | ( | ClockFn | clock | ) |
| void platform::mock::core::MockPlatform::setDigitalValue | ( | uint8_t | bit, |
| bool | value ) |
| void platform::mock::core::MockPlatform::setIMUValues | ( | float | gx, |
| float | gy, | ||
| float | gz, | ||
| float | ax, | ||
| float | ay, | ||
| float | az, | ||
| float | mx, | ||
| float | my, | ||
| float | mz ) |
| void platform::mock::core::MockPlatform::setMotor | ( | uint8_t | port, |
| MotorDir | dir, | ||
| uint32_t | value ) |
| void platform::mock::core::MockPlatform::setMotorVelocity | ( | uint8_t | port, |
| int | signedBemfUnits ) |
Closed-loop velocity command path: signed BEMF integer units. Distinguished from setMotor() because the unit is different (BEMF ticks/s, not duty %), and the sim needs to interpret it through the motor calibration rather than as a duty.
| void platform::mock::core::MockPlatform::setServo | ( | uint8_t | port, |
| ServoMode | mode, | ||
| uint16_t | pos ) |
| libstp::sim::SimWorld * platform::mock::core::MockPlatform::sim | ( | ) |
| int platform::mock::core::MockPlatform::simCurrentLayer | ( | ) | const |
Index of the table plane (layer) the sim robot is currently on (0 = ground). Switches when the robot crosses a v2 ramp transition. Returns -1 when no sim is attached.
| libstp::sim::Pose2D platform::mock::core::MockPlatform::simOdometryRelativePose | ( | ) | const |
Like simRelativePose() but backed by the sim's dead-reckoned odometry pose (SimWorld::odometryPose()) instead of the collision-clamped ground-truth pose. This is what the production motion controllers (IOdometry) read: its lateral axis is sign-aligned with the +vy command so closed-loop strafes converge. Zeroes on resetSimOrigin() exactly like simRelativePose().
| libstp::sim::Pose2D platform::mock::core::MockPlatform::simPose | ( | ) | const |
| libstp::sim::Pose2D platform::mock::core::MockPlatform::simRelativePose | ( | ) | const |
Pose relative to the last resetSimOrigin() call, expressed in the frame of the original heading. Mirrors how a real STM32 coprocessor reports its locally-integrated pose: the value zeroes on reset and climbs from there. Returned pose is in centimeters / radians.
| float platform::mock::core::MockPlatform::simYawRate | ( | ) | const |
| void platform::mock::core::MockPlatform::tickSim | ( | float | dtSeconds | ) |
| bool platform::mock::core::MockPlatform::update | ( | ) |