libstp
Robotics library for Botball
Loading...
Searching...
No Matches
platform::mock::core::MockPlatform Class Reference

#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 ()

Detailed Description

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.

Member Typedef Documentation

◆ ClockFn

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.

Member Function Documentation

◆ autoTickIfEnabled()

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.

◆ configureSim()

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 )

◆ detachSim()

void platform::mock::core::MockPlatform::detachSim ( )

◆ getAccelX()

float platform::mock::core::MockPlatform::getAccelX ( ) const

◆ getAccelY()

float platform::mock::core::MockPlatform::getAccelY ( ) const

◆ getAccelZ()

float platform::mock::core::MockPlatform::getAccelZ ( ) const

◆ getAnalog()

uint16_t platform::mock::core::MockPlatform::getAnalog ( uint8_t port) const

◆ getBemf()

float platform::mock::core::MockPlatform::getBemf ( uint8_t port) const

◆ getDigital()

bool platform::mock::core::MockPlatform::getDigital ( uint8_t bit) const

◆ getDigitalRaw()

uint16_t platform::mock::core::MockPlatform::getDigitalRaw ( ) const

◆ getGyroX()

float platform::mock::core::MockPlatform::getGyroX ( ) const

◆ getGyroY()

float platform::mock::core::MockPlatform::getGyroY ( ) const

◆ getGyroZ()

float platform::mock::core::MockPlatform::getGyroZ ( ) const

◆ getLastUpdateUs()

uint32_t platform::mock::core::MockPlatform::getLastUpdateUs ( ) const

◆ getMagX()

float platform::mock::core::MockPlatform::getMagX ( ) const

◆ getMagY()

float platform::mock::core::MockPlatform::getMagY ( ) const

◆ getMagZ()

float platform::mock::core::MockPlatform::getMagZ ( ) const

◆ getMotorPosition()

int platform::mock::core::MockPlatform::getMotorPosition ( uint8_t port) const

◆ getQuatW()

float platform::mock::core::MockPlatform::getQuatW ( ) const

◆ getQuatX()

float platform::mock::core::MockPlatform::getQuatX ( ) const

◆ getQuatY()

float platform::mock::core::MockPlatform::getQuatY ( ) const

◆ getQuatZ()

float platform::mock::core::MockPlatform::getQuatZ ( ) const

◆ hasSim()

bool platform::mock::core::MockPlatform::hasSim ( ) const

◆ init()

bool platform::mock::core::MockPlatform::init ( )

◆ instance()

MockPlatform & platform::mock::core::MockPlatform::instance ( )
inlinestatic

Definition at line 27 of file MockPlatform.hpp.

◆ isAutoTickEnabled()

bool platform::mock::core::MockPlatform::isAutoTickEnabled ( ) const

◆ resetSimOrigin()

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.

◆ setAnalogValue()

void platform::mock::core::MockPlatform::setAnalogValue ( uint8_t port,
uint16_t value )

◆ setAutoTickEnabled()

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.

◆ setAutoTickMaxStep()

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.

◆ setClockSource()

void platform::mock::core::MockPlatform::setClockSource ( ClockFn clock)

◆ setDigitalValue()

void platform::mock::core::MockPlatform::setDigitalValue ( uint8_t bit,
bool value )

◆ setIMUValues()

void platform::mock::core::MockPlatform::setIMUValues ( float gx,
float gy,
float gz,
float ax,
float ay,
float az,
float mx,
float my,
float mz )

◆ setMotor()

void platform::mock::core::MockPlatform::setMotor ( uint8_t port,
MotorDir dir,
uint32_t value )

◆ setMotorVelocity()

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.

◆ setServo()

void platform::mock::core::MockPlatform::setServo ( uint8_t port,
ServoMode mode,
uint16_t pos )

◆ sim()

libstp::sim::SimWorld * platform::mock::core::MockPlatform::sim ( )

◆ simCurrentLayer()

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.

◆ simOdometryRelativePose()

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().

◆ simPose()

libstp::sim::Pose2D platform::mock::core::MockPlatform::simPose ( ) const

◆ simRelativePose()

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.

◆ simYawRate()

float platform::mock::core::MockPlatform::simYawRate ( ) const

◆ tickSim()

void platform::mock::core::MockPlatform::tickSim ( float dtSeconds)

◆ update()

bool platform::mock::core::MockPlatform::update ( )

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