blmc_drivers
blmc_drivers::SpiBus Class Reference
Inheritance diagram for blmc_drivers::SpiBus:
Collaboration diagram for blmc_drivers::SpiBus:

Public Member Functions

 SpiBus (std::shared_ptr< MasterBoardInterface > main_board_interface, const size_t &nb_udrivers, const size_t &history_length=1000)
 Construct a new SpiBus object. More...
 
 ~SpiBus ()
 Destroy the SpiBus object. More...
 
virtual std::shared_ptr< const MotorInterface::ScalarTimeseriesget_measurement (const size_t udriver_id, const MotorBoardInterface::MeasurementIndex &index) const
 Output and status. More...
 
virtual std::shared_ptr< const MotorBoardInterface::StatusTimeseriesget_status (const size_t udriver_id) const
 Get the status of the motor board. More...
 
virtual std::shared_ptr< const MotorInterface::ScalarTimeseriesget_control (const size_t udriver_id, const MotorBoardInterface::ControlIndex &index) const
 input logs More...
 
virtual std::shared_ptr< const MotorBoardInterface::CommandTimeseriesget_command (const size_t udriver_id) const
 Get the commands to be send. More...
 
virtual std::shared_ptr< const MotorInterface::ScalarTimeseriesget_sent_control (const size_t udriver_id, const MotorBoardInterface::ControlIndex &index) const
 Get the sent controls. More...
 
virtual std::shared_ptr< const MotorBoardInterface::CommandTimeseriesget_sent_command (const size_t udriver_id) const
 Get the sent commands. More...
 
virtual void set_control (const size_t udriver_id, const double &control, const MotorBoardInterface::ControlIndex &index)
 Setters. More...
 
virtual void set_command (const size_t udriver_id, const MotorBoardCommand &command)
 set_command save the command internally. More...
 
virtual void send_if_input_changed ()
 Actually send the commands and the controls. More...
 
bool is_ready ()
 return s only once board and motors are ready.
 
void wait_until_ready ()
 Wait until the robot is ready.
 

Private Member Functions

void loop ()
 This is the real time thread that streams the data to/from the main board.
 
void send_newest_command ()
 Send the newest control stored in the time series. More...
 
void send_newest_controls ()
 Send the newest control stored in the time series.
 

Static Private Member Functions

static THREAD_FUNCTION_RETURN_TYPE loop (void *instance_pointer)
 Private methods. More...
 

Private Attributes

std::shared_ptr< MasterBoardInterface > main_board_interface_
 Communication related attributes. More...
 
size_t nb_udrivers_
 nb_udrivers_ is the number of the udriver controlled by the main board.
 
std::vector< std::shared_ptr< MotorInterface::ScalarTimeseries > > measurement_
 Outputs. More...
 
std::vector< std::shared_ptr< MotorBoardInterface::StatusTimeseries > > status_
 This is the status history of the udriver board.
 
std::vector< std::shared_ptr< MotorInterface::ScalarTimeseries > > control_
 Inputs. More...
 
std::vector< std::shared_ptr< MotorBoardInterface::CommandTimeseries > > command_
 This is the buffer of the commands to be sent to the card.
 
size_t history_length_
 history_length_ is the length of data buffers in number of iteration.
 
std::vector< std::shared_ptr< MotorInterface::ScalarTimeseries > > sent_control_
 Log. More...
 
std::vector< std::shared_ptr< MotorBoardInterface::CommandTimeseries > > sent_command_
 This is the history of the already sent commands.
 
bool is_loop_active_
 Loop management. More...
 
bool motors_are_paused_
 Are motor in idle mode = 0 torques.
 
int control_timeout_ms_
 If no control is sent for more than control_timeout_ms_ the board will shut down.
 
real_time_tools::RealTimeThread rt_thread_
 This is the thread object that allow to spwan a real-time thread or not dependening on the current OS.
 
std::array< bool, 12 > motor_index_toggle_bits_
 Everytime a motor index is detected the corresponding bit change for the opposite value. More...
 

Constructor & Destructor Documentation

◆ SpiBus()

blmc_drivers::SpiBus::SpiBus ( std::shared_ptr< MasterBoardInterface >  main_board_interface,
const size_t &  nb_udrivers,
const size_t &  history_length = 1000 
)

Construct a new SpiBus object.

The constructor starts a real time thread: SpiBus::loop(). This thread streams the data back and forth collecting the sensor data and sends the control/commands.

Parameters
main_board_interfaceis the object that communicate with the main board. The main board provides the hardware informations.
nb_udriversis the number udrivers plugged on the main board.
history_lengthis the size of the buffer of messages stored.

◆ ~SpiBus()

blmc_drivers::SpiBus::~SpiBus ( )

Destroy the SpiBus object.

The destructor handles the proper shutdown of the class and the threads.

Member Function Documentation

◆ get_command()

std::shared_ptr< const MotorBoardInterface::CommandTimeseries > blmc_drivers::SpiBus::get_command ( const size_t  udriver_id) const
virtual

Get the commands to be send.

Returns
Ptr<const CommandTimeseries> is the list of the commands to be send. Inherited from MotorBoardInterface

◆ get_control()

std::shared_ptr< const MotorBoardInterface::ScalarTimeseries > blmc_drivers::SpiBus::get_control ( const size_t  udriver_id,
const MotorBoardInterface::ControlIndex index 
) const
virtual

input logs

input logs Get the controls to be send.

Parameters
indexdefine the kind of control we are looking for.
Returns
Ptr<const ScalarTimeseries> is the list of the controls to be send. Inherited from MotorBoardInterface

◆ get_measurement()

std::shared_ptr< const MotorBoardInterface::ScalarTimeseries > blmc_drivers::SpiBus::get_measurement ( const size_t  udriver_id,
const MotorBoardInterface::MeasurementIndex index 
) const
virtual

Output and status.

Get the measurements from the main board.

Parameters
udriver_idis the index of the spi port on the control board
index
Returns
std::shared_ptr<const MotorInterface::ScalarTimeseries>

◆ get_sent_command()

std::shared_ptr< const MotorBoardInterface::CommandTimeseries > blmc_drivers::SpiBus::get_sent_command ( const size_t  udriver_id) const
virtual

Get the sent commands.

Returns
Ptr<const CommandTimeseries> is the list of the commands sent recently. Inherited from MotorBoardInterface

◆ get_sent_control()

std::shared_ptr< const MotorBoardInterface::ScalarTimeseries > blmc_drivers::SpiBus::get_sent_control ( const size_t  udriver_id,
const MotorBoardInterface::ControlIndex index 
) const
virtual

Get the sent controls.

Parameters
indexdefine the kind of control we are looking for.
Returns
Ptr<const ScalarTimeseries> is the list of the controls sent recently. Inherited from MotorBoardInterface

◆ get_status()

std::shared_ptr< const MotorBoardInterface::StatusTimeseries > blmc_drivers::SpiBus::get_status ( const size_t  udriver_id) const
virtual

Get the status of the motor board.

Returns
Ptr<const StatusTimeseries> is the list of the last status of the card. Inherited from MotorBoardInterface

◆ loop()

static THREAD_FUNCTION_RETURN_TYPE blmc_drivers::SpiBus::loop ( void *  instance_pointer)
inlinestaticprivate

Private methods.

This is the helper function used for spawning the real time thread.

Parameters
instance_pointeris the current object in this case.
Returns
THREAD_FUNCTION_RETURN_TYPE depends on the current OS.

◆ send_if_input_changed()

void blmc_drivers::SpiBus::send_if_input_changed ( )
virtual

Actually send the commands and the controls.

Inherited from MotorBoardInterface. This particualr instance does not actually check if it is is a new command or control as the full status of the robot is exchange at every tick.

◆ send_newest_command()

void blmc_drivers::SpiBus::send_newest_command ( )
private

Send the newest control stored in the time series.

Some of the command are not implemented/will be implemented. A warning is issued upon miss-use.

◆ set_command()

void blmc_drivers::SpiBus::set_command ( const size_t  udriver_id,
const MotorBoardCommand command 
)
virtual

set_command save the command internally.

In order to actaully send the controls to the network please call "send_if_input_changed"

Parameters
commandis the command to be sent. Inherited from MotorBoardInterface

◆ set_control()

void blmc_drivers::SpiBus::set_control ( const size_t  udriver_id,
const double &  control,
const MotorBoardInterface::ControlIndex index 
)
virtual

Setters.

Setters. set_control save the control internally. In order to actaully send the controls to the network please call "send_if_input_changed"

Parameters
controlis the value of the control.
indexdefine the kind of control we want to send. Inherited from MotorBoardInterface

Member Data Documentation

◆ control_

std::vector<std::shared_ptr<MotorInterface::ScalarTimeseries> > blmc_drivers::SpiBus::control_
private

Inputs.

This is the buffer of the controls to be sent to card.

◆ is_loop_active_

bool blmc_drivers::SpiBus::is_loop_active_
private

Loop management.

This boolean makes sure that the loop is stopped upon destruction of this object.

◆ main_board_interface_

std::shared_ptr<MasterBoardInterface> blmc_drivers::SpiBus::main_board_interface_
private

Communication related attributes.

Main board interface sdk: https://github.com/open-dynamic-robot-initiative/master-board

◆ measurement_

std::vector<std::shared_ptr<MotorInterface::ScalarTimeseries> > blmc_drivers::SpiBus::measurement_
private

Outputs.

All the measurements acquiered from the CAN board.

◆ motor_index_toggle_bits_

std::array<bool, 12> blmc_drivers::SpiBus::motor_index_toggle_bits_
private

Everytime a motor index is detected the corresponding bit change for the opposite value.

if (index detected on motor X)
{
}

◆ sent_control_

std::vector<std::shared_ptr<MotorInterface::ScalarTimeseries> > blmc_drivers::SpiBus::sent_control_
private

Log.

This is the history of the already sent controls.


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