bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::actuators::backends::MQTT_DCMotorBackend Class Referencefinal

A real DC motor on a board. The target speed goes to the board, and the angle comes back from its encoder. More...

#include <mqtt_dc_motor_backend.h>

Inheritance diagram for bitsim::actuators::backends::MQTT_DCMotorBackend:
Collaboration diagram for bitsim::actuators::backends::MQTT_DCMotorBackend:

Public Member Functions

 MQTT_DCMotorBackend (std::shared_ptr< boards::DCMotorBoardBase > board, uint_t channel, real_t bandwidth=30.0)
OutputType output_type () const noexcept override
void set_target_speed (real_t speed) override
 Set the target speed of the output shaft [rad/s].
void step (real_t dt) override
 Advance the backend by dt. A model moves its own shaft.
void step (real_t dt, const ShaftState &) override
 Advance the backend by dt, with the shaft moved by a physics engine. Backends with OutputType::ANGLE ignore the shaft.
real_t angle () const override
real_t speed () const override
real_t encoder_angle () const override
bool is_ready () const override
real_t reported_angle () const noexcept
real_t reported_speed () const noexcept
std::shared_ptr< boards::DCMotorBoardBase > board () const noexcept
uint_t channel () const noexcept
Public Member Functions inherited from bitsim::actuators::backends::DCMotorBackendBase
virtual ~DCMotorBackendBase ()=default
virtual real_t torque () const
const std::string & backend_type_str () const noexcept

Static Public Attributes

static const std::string BACKEND_TYPE = "MQTT"

Additional Inherited Members

Public Types inherited from bitsim::actuators::backends::DCMotorBackendBase
enum class  OutputType { TORQUE , ANGLE }
Protected Member Functions inherited from bitsim::actuators::backends::DCMotorBackendBase
 DCMotorBackendBase (const std::string &backend_type)

Detailed Description

A real DC motor on a board. The target speed goes to the board, and the angle comes back from its encoder.

The board reports every few tens of milliseconds, while a simulation steps every millisecond or two. In between, the backend predicts the angle from the last report and the speed. A physics engine that follows the angle differentiates it twice, so every correction of the prediction would show up as a spike of torque. So angle() is a smooth estimate instead: a second-order filter pulled towards the predicted angle and the reported speed.

Angles are counted from the first report, so the shaft starts at zero.

Constructor & Destructor Documentation

◆ MQTT_DCMotorBackend()

bitsim::actuators::backends::MQTT_DCMotorBackend::MQTT_DCMotorBackend ( std::shared_ptr< boards::DCMotorBoardBase > board,
uint_t channel,
real_t bandwidth = 30.0 )
Parameters
boardThe board the motor is on. Several motors share a board
channelThe motor on the board
bandwidthThe bandwidth of the estimate [rad/s]

Member Function Documentation

◆ angle()

real_t bitsim::actuators::backends::MQTT_DCMotorBackend::angle ( ) const
inlineoverridevirtual
Returns
The angle of the output shaft [rad]

Implements bitsim::actuators::backends::DCMotorBackendBase.

◆ board()

std::shared_ptr< boards::DCMotorBoardBase > bitsim::actuators::backends::MQTT_DCMotorBackend::board ( ) const
inlinenoexcept

◆ channel()

uint_t bitsim::actuators::backends::MQTT_DCMotorBackend::channel ( ) const
inlinenoexcept

◆ encoder_angle()

real_t bitsim::actuators::backends::MQTT_DCMotorBackend::encoder_angle ( ) const
inlineoverridevirtual
Returns
What the board's encoder last reported: reported_angle(). Unlike angle(), it is not smoothed or predicted

Reimplemented from bitsim::actuators::backends::DCMotorBackendBase.

◆ is_ready()

bool bitsim::actuators::backends::MQTT_DCMotorBackend::is_ready ( ) const
overridevirtual
Returns
True once the board has reported, and while it keeps reporting

Reimplemented from bitsim::actuators::backends::DCMotorBackendBase.

◆ output_type()

OutputType bitsim::actuators::backends::MQTT_DCMotorBackend::output_type ( ) const
inlineoverridevirtualnoexcept
Returns
How the backend couples to a physics engine

Implements bitsim::actuators::backends::DCMotorBackendBase.

◆ reported_angle()

real_t bitsim::actuators::backends::MQTT_DCMotorBackend::reported_angle ( ) const
inlinenoexcept
Returns
The angle the board last reported, from the first report [rad]

◆ reported_speed()

real_t bitsim::actuators::backends::MQTT_DCMotorBackend::reported_speed ( ) const
inlinenoexcept
Returns
The speed the board last reported [rad/s]

◆ set_target_speed()

void bitsim::actuators::backends::MQTT_DCMotorBackend::set_target_speed ( real_t speed)
overridevirtual

Set the target speed of the output shaft [rad/s].

Implements bitsim::actuators::backends::DCMotorBackendBase.

◆ speed()

real_t bitsim::actuators::backends::MQTT_DCMotorBackend::speed ( ) const
inlineoverridevirtual
Returns
The speed of the output shaft [rad/s]

Implements bitsim::actuators::backends::DCMotorBackendBase.

◆ step() [1/2]

void bitsim::actuators::backends::MQTT_DCMotorBackend::step ( real_t dt)
overridevirtual

Advance the backend by dt. A model moves its own shaft.

Implements bitsim::actuators::backends::DCMotorBackendBase.

◆ step() [2/2]

void bitsim::actuators::backends::MQTT_DCMotorBackend::step ( real_t dt,
const ShaftState & shaft )
inlineoverridevirtual

Advance the backend by dt, with the shaft moved by a physics engine. Backends with OutputType::ANGLE ignore the shaft.

Implements bitsim::actuators::backends::DCMotorBackendBase.

Member Data Documentation

◆ BACKEND_TYPE

const std::string bitsim::actuators::backends::MQTT_DCMotorBackend::BACKEND_TYPE = "MQTT"
static

The documentation for this class was generated from the following files: