bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
real_dc_motors::DCArduinoBoardImpl Class Referencefinal

An Arduino that drives DC motors with encoders and talks over MQTT. More...

#include <dc_arduino_board_impl.h>

Inheritance diagram for real_dc_motors::DCArduinoBoardImpl:
Collaboration diagram for real_dc_motors::DCArduinoBoardImpl:

Classes

struct  Config

Public Types

using Clock = std::chrono::steady_clock

Public Member Functions

 DCArduinoBoardImpl (const Config &config)
void connect () override
 Connect to the board.
uint_t n_motors () const noexcept override
void set_target_speed (uint_t channel, real_t speed) override
 Set the target speed of the output shaft of a motor [rad/s].
void update () override
 Exchange messages with the board: send the targets when it is time and read what has arrived. Cheap, so it is safe to call it often.
std::optional< MotorChannelState > motor_state (uint_t channel) const override
bool is_alive () const override
bool wait_for_board (std::chrono::milliseconds timeout)
 Wait until the board reports, for at most timeout.
const Config & config () const noexcept
real_t round_trip () const noexcept
real_t mean_round_trip () const noexcept
real_t max_round_trip () const noexcept
uint_t n_sent () const noexcept
uint_t n_received () const noexcept
Public Member Functions inherited from bitsim::boards::DCMotorBoardBase
virtual ~DCMotorBoardBase ()=default

Additional Inherited Members

Protected Member Functions inherited from bitsim::boards::DCMotorBoardBase
 DCMotorBoardBase ()=default

Detailed Description

An Arduino that drives DC motors with encoders and talks over MQTT.

The application publishes the target speeds on the command topic, and the board publishes the distance each wheel has covered on the state topic:

command: {"seq": 12, "left_speed": 2.5, "right_speed": 2.5}
state: {"ack": 12, "left_distance": 0.53, "right_distance": 0.52,
"left_speed": 2.49, "right_speed": 2.51, "t_ms": 81234}

Speeds are wheel speeds in rad/s and distances are in m. The board turns encoder counts into distance with its wheel radius, so wheel_radius here must match the one in the sketch. ack is the number of the last command the board received, which gives the round trip of the messages.

Member Typedef Documentation

◆ Clock

using bitsim::boards::arduino::DCArduinoBoardImpl::Clock = std::chrono::steady_clock

Constructor & Destructor Documentation

◆ DCArduinoBoardImpl()

Member Function Documentation

◆ config()

◆ connect()

Connect to the board.

Implements bitsim::boards::DCMotorBoardBase.

◆ is_alive()

Returns
True if the board has reported recently

Implements bitsim::boards::DCMotorBoardBase.

◆ max_round_trip()

◆ mean_round_trip()

◆ motor_state()

std::optional< MotorChannelState > bitsim::boards::arduino::DCArduinoBoardImpl::motor_state ( uint_t channel) const
overridevirtual
Returns
The latest report for a motor, or nothing if the board has not reported yet

Implements bitsim::boards::DCMotorBoardBase.

◆ n_motors()

uint_t bitsim::boards::arduino::DCArduinoBoardImpl::n_motors ( ) const
inlineoverridevirtualnoexcept
Returns
The number of motors the board drives

Implements bitsim::boards::DCMotorBoardBase.

◆ n_received()

◆ n_sent()

◆ round_trip()

Returns
The last round trip: from sending a command until hearing that the board has it [s]

◆ set_target_speed()

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

Implements bitsim::boards::DCMotorBoardBase.

◆ update()

Exchange messages with the board: send the targets when it is time and read what has arrived. Cheap, so it is safe to call it often.

Implements bitsim::boards::DCMotorBoardBase.

◆ wait_for_board()

bool bitsim::boards::arduino::DCArduinoBoardImpl::wait_for_board ( std::chrono::milliseconds timeout)

Wait until the board reports, for at most timeout.

Returns
True if it did

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