blmc_drivers
blmc_drivers::CanBusMotorBoard Class Reference

This class CanBusMotorBoard implements a MotorBoardInterface specific to CAN networks. More...

#include <motor_board.hpp>

Inheritance diagram for blmc_drivers::CanBusMotorBoard:
Collaboration diagram for blmc_drivers::CanBusMotorBoard:

Public Member Functions

 CanBusMotorBoard (std::shared_ptr< CanBusInterface > can_bus, const size_t &history_length=1000, const int &control_timeout_ms=100)
 Construct a new CanBusMotorBoard object. More...
 
 ~CanBusMotorBoard ()
 Destroy the CanBusMotorBoard object.
 
virtual Ptr< const ScalarTimeseriesget_measurement (const int &index) const
 Getters. More...
 
virtual Ptr< const StatusTimeseriesget_status () const
 Get the status of the CAN card. More...
 
virtual Ptr< const ScalarTimeseriesget_control (const int &index) const
 Get the controls to be sent. More...
 
virtual Ptr< const CommandTimeseriesget_command () const
 Get the commands to be sent. More...
 
virtual Ptr< const ScalarTimeseriesget_sent_control (const int &index) const
 Get the already sent controls. More...
 
virtual Ptr< const CommandTimeseriesget_sent_command () const
 Get the already sent commands. More...
 
virtual void set_control (const double &control, const int &index)
 Setters. More...
 
virtual void set_command (const MotorBoardCommand &command)
 Set the commands, see MotorBoardInterface::set_command. More...
 
virtual void send_if_input_changed ()
 Send the actual command and controls.
 
void wait_until_ready ()
 returns only once board and motors are ready.
 
bool is_ready ()
 
void pause_motors ()
 
void disable_can_recv_timeout ()
 Disable the can reciever timeout.
 
- Public Member Functions inherited from blmc_drivers::MotorBoardInterface
virtual ~MotorBoardInterface ()
 Destroy the MotorBoardInterface object.
 

Private Types

enum  CanframeIDs {
  COMMAND_ID = 0x00, IqRef = 0x05, STATUSMSG = 0x10, Iq = 0x20,
  POS = 0x30, SPEED = 0x40, ADC6 = 0x50, ENC_INDEX = 0x60
}
 These are the frame IDs that define the kind of data we acquiere from the CAN bus.
 

Private Member Functions

template<typename T >
int32_t bytes_to_int32 (T bytes)
 private methods ======================================================== More...
 
float q24_to_float (int32_t qval)
 Convert from 24-bit normalized fixed-point to float. More...
 
int32_t float_to_q24 (float fval)
 Converts from float to 24-bit normalized fixed-point. More...
 
template<typename T >
float qbytes_to_float (T qbytes)
 Converts from qbytes to float. More...
 
void send_newest_controls ()
 send the controls to the cards. More...
 
void send_newest_command ()
 send the latest commands to the cards.
 
void loop ()
 Is the loop that constently communicate with the network.
 
void print_status ()
 Display details of this object.
 

Static Private Member Functions

static THREAD_FUNCTION_RETURN_TYPE loop (void *instance_pointer)
 This is the helper function used for spawning the real time thread. More...
 

Private Attributes

std::shared_ptr< CanBusInterfacecan_bus_
 This is the pointer to the can bus to communicate with.
 
Vector< Ptr< ScalarTimeseries > > measurement_
 Outputs. More...
 
Ptr< StatusTimeseriesstatus_
 This is the status history of the CAN board.
 
Vector< Ptr< ScalarTimeseries > > control_
 Inputs. More...
 
Ptr< CommandTimeseriescommand_
 This is the buffer of the commands to be sent to the card.
 
Vector< Ptr< ScalarTimeseries > > sent_control_
 Log. More...
 
Ptr< CommandTimeseriessent_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? update this documentation with the actual behavior.
 
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.
 

Additional Inherited Members

- Public Types inherited from blmc_drivers::MotorBoardInterface
enum  MeasurementIndex {
  current_0, current_1, position_0, position_1,
  velocity_0, velocity_1, analog_0, analog_1,
  encoder_index_0, encoder_index_1, measurement_count
}
 This is the list of the measurement we can access.
 
enum  ControlIndex { current_target_0, current_target_1, control_count }
 This is the list of the controls we can send.
 
typedef real_time_tools::ThreadsafeTimeseries< double > ScalarTimeseries
 A useful shortcut.
 
typedef ScalarTimeseries::Index Index
 A useful shortcut.
 
typedef real_time_tools::ThreadsafeTimeseries< IndexIndexTimeseries
 A useful shortcut.
 
typedef real_time_tools::ThreadsafeTimeseries< MotorBoardStatusStatusTimeseries
 A useful shortcut.
 
typedef real_time_tools::ThreadsafeTimeseries< MotorBoardCommandCommandTimeseries
 A useful shortcut.
 
template<typename Type >
using Ptr = std::shared_ptr< Type >
 A useful shortcut.
 
template<typename Type >
using Vector = std::vector< Type >
 A useful shortcut.
 

Detailed Description

This class CanBusMotorBoard implements a MotorBoardInterface specific to CAN networks.

Constructor & Destructor Documentation

◆ CanBusMotorBoard()

blmc_drivers::CanBusMotorBoard::CanBusMotorBoard ( std::shared_ptr< CanBusInterface can_bus,
const size_t &  history_length = 1000,
const int &  control_timeout_ms = 100 
)

Construct a new CanBusMotorBoard object.

Parameters
can_bus
history_length

Member Function Documentation

◆ bytes_to_int32()

template<typename T >
int32_t blmc_drivers::CanBusMotorBoard::bytes_to_int32 ( bytes)
inlineprivate

private methods ========================================================

Useful converters Converts from bytes to int32.

Template Parameters
Tthis is the type of the bytes convert.
Parameters
bytesThe bytes value
Returns
int32_t the output integer in int32.

◆ float_to_q24()

int32_t blmc_drivers::CanBusMotorBoard::float_to_q24 ( float  fval)
inlineprivate

Converts from float to 24-bit normalized fixed-point.

Parameters
fval
Returns
int32_t

◆ get_command()

virtual Ptr<const CommandTimeseries> blmc_drivers::CanBusMotorBoard::get_command ( ) const
inlinevirtual

Get the commands to be sent.

Returns
Ptr<const CommandTimeseries> is the list of the command to be sent.

Implements blmc_drivers::MotorBoardInterface.

◆ get_control()

virtual Ptr<const ScalarTimeseries> blmc_drivers::CanBusMotorBoard::get_control ( const int &  index) const
inlinevirtual

Get the controls to be sent.

Parameters
indexthe kind of control we are interested in.
Returns
Ptr<const ScalarTimeseries> is the list of the control to be sent.

Implements blmc_drivers::MotorBoardInterface.

◆ get_measurement()

virtual Ptr<const ScalarTimeseries> blmc_drivers::CanBusMotorBoard::get_measurement ( const int &  index) const
inlinevirtual

Getters.

Get the measurement data.

Parameters
indexis the kind of measurement we are insterested in.
Returns
Ptr<const ScalarTimeseries> is the list of the last measurements acquiered from the CAN card.

Implements blmc_drivers::MotorBoardInterface.

◆ get_sent_command()

virtual Ptr<const CommandTimeseries> blmc_drivers::CanBusMotorBoard::get_sent_command ( ) const
inlinevirtual

Get the already sent commands.

Returns
Ptr<const CommandTimeseries> is the list of the sent cotnrols.

Implements blmc_drivers::MotorBoardInterface.

◆ get_sent_control()

virtual Ptr<const ScalarTimeseries> blmc_drivers::CanBusMotorBoard::get_sent_control ( const int &  index) const
inlinevirtual

Get the already sent controls.

Parameters
indexthe kind of control we are interested in.
Returns
Ptr<const ScalarTimeseries> is the list of the sent cotnrols.

Implements blmc_drivers::MotorBoardInterface.

◆ get_status()

virtual Ptr<const StatusTimeseries> blmc_drivers::CanBusMotorBoard::get_status ( ) const
inlinevirtual

Get the status of the CAN card.

Returns
Ptr<const StatusTimeseries> is the list of last acquiered status.

Implements blmc_drivers::MotorBoardInterface.

◆ loop()

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

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.

◆ pause_motors()

void blmc_drivers::CanBusMotorBoard::pause_motors ( )
Todo:
: this function should go away, and we should add somewhere a warning in case there is a timeout

◆ q24_to_float()

float blmc_drivers::CanBusMotorBoard::q24_to_float ( int32_t  qval)
inlineprivate

Convert from 24-bit normalized fixed-point to float.

Parameters
qvalis the floating base point.
Returns
float is the converted value

◆ qbytes_to_float()

template<typename T >
float blmc_drivers::CanBusMotorBoard::qbytes_to_float ( qbytes)
inlineprivate

Converts from qbytes to float.

Template Parameters
Tthe type of byte to manage
Parameters
qbytesthe input value in bytes
Returns
float the output value.

◆ send_newest_controls()

void blmc_drivers::CanBusMotorBoard::send_newest_controls ( )
private

send the controls to the cards.

Parameters
controlsare the controls to be sent.

◆ set_command()

virtual void blmc_drivers::CanBusMotorBoard::set_command ( const MotorBoardCommand command)
inlinevirtual

Set the commands, see MotorBoardInterface::set_command.

Parameters
command

Implements blmc_drivers::MotorBoardInterface.

◆ set_control()

virtual void blmc_drivers::CanBusMotorBoard::set_control ( const double &  control,
const int &  index 
)
inlinevirtual

Setters.

Set the controls, see MotorBoardInterface::set_control

Parameters
control
index

Implements blmc_drivers::MotorBoardInterface.

Member Data Documentation

◆ control_

Vector<Ptr<ScalarTimeseries> > blmc_drivers::CanBusMotorBoard::control_
private

Inputs.

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

◆ is_loop_active_

bool blmc_drivers::CanBusMotorBoard::is_loop_active_
private

Loop management.

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

◆ measurement_

Vector<Ptr<ScalarTimeseries> > blmc_drivers::CanBusMotorBoard::measurement_
private

Outputs.

measurement_ contains all the measurements acquiered from the CAN board.

◆ sent_control_

Vector<Ptr<ScalarTimeseries> > blmc_drivers::CanBusMotorBoard::sent_control_
private

Log.

This is the history of the already sent controls.


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