libstp
Robotics library for Botball
Loading...
Searching...
No Matches
libstp::hal::motor::Motor Class Reference

#include <Motor.hpp>

Inheritance diagram for libstp::hal::motor::Motor:
[legend]
Collaboration diagram for libstp::hal::motor::Motor:
[legend]

Public Member Functions

 Motor (int port, bool inverted, const foundation::MotorCalibration &calibration={})
 ~Motor () override
void setSpeed (int percent) override
 Open-loop percent output in the range expected by the platform driver.
void setVelocity (int velocity) override
 Closed-loop velocity target in firmware-specific BEMF units.
void moveToPosition (int velocity, int goalPosition) override
 Closed-loop absolute move in firmware-specific position units.
void moveRelative (int velocity, int deltaPosition) override
 Closed-loop relative move in firmware-specific position units.
int getPosition () const override
 Return the current motor position using the driver's sign convention.
int getBemf () const override
 Return the driver's current BEMF or velocity-like feedback value.
bool isDone () const override
 Return whether the last position command has completed.
void brake () override
 Actively stop this motor using the platform's safest available path.
void off () override
 Disable this motor completely (no power, no brake — free-spinning).
void resetPositionCounter () override
 Reset the position counter to zero.
const foundation::MotorCalibration & getCalibration () const override
void setCalibration (const foundation::MotorCalibration &calibration) override
int getPort () const override
bool isInverted () const override
void setFirmwarePidGains (float kp, float ki, float kd) override
void setSimulatedBemfResponse (int steady_state_bemf, double time_constant_s)
void clearSimulatedBemfResponse ()
 Disable the simulated BEMF response (mock platform only).
void getLastFirmwarePidGains (float &kp, float &ki, float &kd) const override
Public Member Functions inherited from libstp::hal::motor::IMotor
virtual ~IMotor ()=default

Static Public Member Functions

static void disableAll ()
 Put every motor managed by the active platform into its disabled state.
static void enableAll ()
 Re-enable globally disabled motors when the platform supports it.

Detailed Description

Concrete motor wrapper whose method bodies are provided by the selected platform bundle.

The public contract here is what higher-level modules and Python bindings program against. Shared process-wide safety behavior, such as duplicate port tracking and fail-safe shutdown hooks, lives in libstp-hal.

Definition at line 19 of file Motor.hpp.

Constructor & Destructor Documentation

◆ Motor()

libstp::hal::motor::Motor::Motor ( int port,
bool inverted,
const foundation::MotorCalibration & calibration = {} )
explicit

Construct a motor on the given port.

inverted flips command and feedback sign conventions so callers can keep chassis-level logic independent of wiring direction.

◆ ~Motor()

libstp::hal::motor::Motor::~Motor ( )
override

Member Function Documentation

◆ brake()

void libstp::hal::motor::Motor::brake ( )
overridevirtual

Actively stop this motor using the platform's safest available path.

Implements libstp::hal::motor::IMotor.

◆ clearSimulatedBemfResponse()

void libstp::hal::motor::Motor::clearSimulatedBemfResponse ( )

Disable the simulated BEMF response (mock platform only).

◆ disableAll()

void libstp::hal::motor::Motor::disableAll ( )
static

Put every motor managed by the active platform into its disabled state.

◆ enableAll()

void libstp::hal::motor::Motor::enableAll ( )
static

Re-enable globally disabled motors when the platform supports it.

◆ getBemf()

int libstp::hal::motor::Motor::getBemf ( ) const
nodiscardoverridevirtual

Return the driver's current BEMF or velocity-like feedback value.

Implements libstp::hal::motor::IMotor.

◆ getCalibration()

const foundation::MotorCalibration & libstp::hal::motor::Motor::getCalibration ( ) const
nodiscardoverridevirtual

◆ getLastFirmwarePidGains()

void libstp::hal::motor::Motor::getLastFirmwarePidGains ( float & kp,
float & ki,
float & kd ) const
overridevirtual

Read back the gains most recently passed to setFirmwarePidGains(). Useful for asserting tuner behavior in unit tests.

Reimplemented from libstp::hal::motor::IMotor.

◆ getPort()

int libstp::hal::motor::Motor::getPort ( ) const
inlinenodiscardoverridevirtual

Implements libstp::hal::motor::IMotor.

Definition at line 64 of file Motor.hpp.

◆ getPosition()

int libstp::hal::motor::Motor::getPosition ( ) const
nodiscardoverridevirtual

Return the current motor position using the driver's sign convention.

Implements libstp::hal::motor::IMotor.

◆ isDone()

bool libstp::hal::motor::Motor::isDone ( ) const
nodiscardoverridevirtual

Return whether the last position command has completed.

Implements libstp::hal::motor::IMotor.

◆ isInverted()

bool libstp::hal::motor::Motor::isInverted ( ) const
inlinenodiscardoverridevirtual

Implements libstp::hal::motor::IMotor.

Definition at line 65 of file Motor.hpp.

◆ moveRelative()

void libstp::hal::motor::Motor::moveRelative ( int velocity,
int deltaPosition )
overridevirtual

Closed-loop relative move in firmware-specific position units.

Implements libstp::hal::motor::IMotor.

◆ moveToPosition()

void libstp::hal::motor::Motor::moveToPosition ( int velocity,
int goalPosition )
overridevirtual

Closed-loop absolute move in firmware-specific position units.

Implements libstp::hal::motor::IMotor.

◆ off()

void libstp::hal::motor::Motor::off ( )
overridevirtual

Disable this motor completely (no power, no brake — free-spinning).

Implements libstp::hal::motor::IMotor.

◆ resetPositionCounter()

void libstp::hal::motor::Motor::resetPositionCounter ( )
overridevirtual

Reset the position counter to zero.

Implements libstp::hal::motor::IMotor.

◆ setCalibration()

void libstp::hal::motor::Motor::setCalibration ( const foundation::MotorCalibration & calibration)
overridevirtual

◆ setFirmwarePidGains()

void libstp::hal::motor::Motor::setFirmwarePidGains ( float kp,
float ki,
float kd )
overridevirtual

Push per-motor firmware-side velocity PID gains.

On wombat this publishes to the STM32; on the mock platform the gains are stored for getLastFirmwarePidGains().

Reimplemented from libstp::hal::motor::IMotor.

◆ setSimulatedBemfResponse()

void libstp::hal::motor::Motor::setSimulatedBemfResponse ( int steady_state_bemf,
double time_constant_s )

Configure a simulated first-order BEMF step response. When active (mock platform only), getBemf() returns steady_state * (1 - exp(-t / time_constant_s)) where t is the time since the last setVelocity() call.

◆ setSpeed()

void libstp::hal::motor::Motor::setSpeed ( int percent)
overridevirtual

Open-loop percent output in the range expected by the platform driver.

Implements libstp::hal::motor::IMotor.

◆ setVelocity()

void libstp::hal::motor::Motor::setVelocity ( int velocity)
overridevirtual

Closed-loop velocity target in firmware-specific BEMF units.

Implements libstp::hal::motor::IMotor.


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