13 #include "real_time_tools/timer.hpp" 14 #include "real_time_tools/thread.hpp" 17 #include "real_time_tools/threadsafe/threadsafe_object.hpp" 18 #include "real_time_tools/threadsafe/threadsafe_timeseries.hpp" 76 SET_CAN_RECV_TIMEOUT = 30,
77 ENABLE_POS_ROLLOVER_ERROR = 31,
154 CAN_RECV_TIMEOUT = 2,
171 rt_printf(
"\tSystem enabled: %d\n", system_enabled);
172 rt_printf(
"\tMotor 1 enabled: %d\n", motor1_enabled);
173 rt_printf(
"\tMotor 1 ready: %d\n", motor1_ready);
174 rt_printf(
"\tMotor 2 enabled: %d\n", motor2_enabled);
175 rt_printf(
"\tMotor 2 ready: %d\n", motor2_ready);
176 rt_printf(
"\tError Code: %d\n", error_code);
224 typedef ScalarTimeseries::Index
Index;
240 template<
typename Type>
using Ptr = std::shared_ptr<Type>;
244 template<
typename Type>
using Vector = std::vector<Type>;
250 position_0, position_1,
251 velocity_0, velocity_1,
253 encoder_index_0, encoder_index_1,
273 const int& index)
const = 0;
312 const int& index)
const = 0;
333 virtual void set_control(
const double& control,
const int& index) = 0;
346 virtual void send_if_input_changed() = 0;
358 template<
typename Type>
360 const size_t& size,
const size_t& length)
362 std::vector<std::shared_ptr<Type> > vector;
364 for(
size_t i = 0; i < size; i++)
366 vector[i] = std::make_shared<Type>(length);
387 const size_t& history_length = 1000,
388 const int &control_timeout_ms = 100);
410 return measurement_[index];
432 return control_[index];
453 const int& index)
const 455 return control_[index];
465 return sent_command_;
480 control_[index]->append(control);
490 command_->append(command);
496 virtual void send_if_input_changed();
501 void wait_until_ready();
512 void disable_can_recv_timeout();
530 return (int32_t) bytes[3] + ((int32_t)bytes[2] << 8) +
531 ((int32_t)bytes[1] << 16) + ((int32_t)bytes[0] << 24);
542 return ((
float)qval / (1 << 24));
553 return ((
int)(fval * (1 << 24)));
565 return q24_to_float(bytes_to_int32(qbytes));
573 void send_newest_controls();
579 void send_newest_command();
588 static THREAD_FUNCTION_RETURN_TYPE
loop(
void* instance_pointer)
591 return THREAD_FUNCTION_RETURN_VALUE;
MotorBoardCommand()
Construct a new MotorBoardCommand object.
Definition: motor_board.hpp:37
virtual ~MotorBoardInterface()
Destroy the MotorBoardInterface object.
Definition: motor_board.hpp:215
MotorBoardCommand(uint32_t id, int32_t content)
Construct a new MotorBoardCommand object.
Definition: motor_board.hpp:45
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...
Definition: motor_board.hpp:697
real_time_tools::ThreadsafeTimeseries< Index > IndexTimeseries
A useful shortcut.
Definition: motor_board.hpp:228
uint8_t motor2_ready
Bits 4 checks if the motor 2 is ready or not.
Definition: motor_board.hpp:137
virtual Ptr< const CommandTimeseries > get_command() const
Get the commands to be sent.
Definition: motor_board.hpp:441
virtual Ptr< const ScalarTimeseries > get_measurement(const int &index) const
Getters.
Definition: motor_board.hpp:408
bool is_ready()
Check if the all status are green.
Definition: motor_board.hpp:185
MotorBoardInterface declares an API to inacte with a MotorBoard.
Definition: motor_board.hpp:209
int32_t content_
content_ is the value of teh command to be sent to the cards.
Definition: motor_board.hpp:97
std::vector< Type > Vector
A useful shortcut.
Definition: motor_board.hpp:244
uint8_t error_code
This encodes the error codes.
Definition: motor_board.hpp:142
virtual void set_command(const MotorBoardCommand &command)
Set the commands, see MotorBoardInterface::set_command.
Definition: motor_board.hpp:488
This namespace is the standard namespace of the package.
Definition: const_torque_control.cpp:12
bool motors_are_paused_
Are motor in idle mode = 0 torques? update this documentation with the actual behavior.
Definition: motor_board.hpp:684
virtual void set_control(const double &control, const int &index)
Setters.
Definition: motor_board.hpp:478
float q24_to_float(int32_t qval)
Convert from 24-bit normalized fixed-point to float.
Definition: motor_board.hpp:540
uint8_t motor2_enabled
Bits 3 enables/disable of the motor 2.
Definition: motor_board.hpp:132
#define rt_printf
Create a common type_def to wrap xenomai and posix.
Definition: os_interface.hpp:76
This MotorBoardCommand class is a data structurs that defines a command.
Definition: motor_board.hpp:30
Vector< Ptr< ScalarTimeseries > > measurement_
Outputs.
Definition: motor_board.hpp:635
real_time_tools::ThreadsafeTimeseries< MotorBoardCommand > CommandTimeseries
A useful shortcut.
Definition: motor_board.hpp:236
Vector< Ptr< ScalarTimeseries > > sent_control_
Log.
Definition: motor_board.hpp:663
ErrorCodes
This is the list of the error codes.
Definition: motor_board.hpp:147
virtual Ptr< const StatusTimeseries > get_status() const
Get the status of the CAN card.
Definition: motor_board.hpp:418
virtual Ptr< const CommandTimeseries > get_sent_command() const
Get the already sent commands.
Definition: motor_board.hpp:463
real_time_tools::ThreadsafeTimeseries< double > ScalarTimeseries
A useful shortcut.
Definition: motor_board.hpp:220
Contents
Is the different command status.
Definition: motor_board.hpp:83
float qbytes_to_float(T qbytes)
Converts from qbytes to float.
Definition: motor_board.hpp:563
bool is_loop_active_
Loop management.
Definition: motor_board.hpp:678
void print() const
Simply print the status of the motor board.
Definition: motor_board.hpp:169
uint8_t motor1_ready
Bits 2 checks if the motor 1 is ready or not.
Definition: motor_board.hpp:127
Ptr< CommandTimeseries > command_
This is the buffer of the commands to be sent to the card.
Definition: motor_board.hpp:654
int32_t float_to_q24(float fval)
Converts from float to 24-bit normalized fixed-point.
Definition: motor_board.hpp:551
ScalarTimeseries::Index Index
A useful shortcut.
Definition: motor_board.hpp:224
uint32_t id_
id_ is the command to be modifies on the card.
Definition: motor_board.hpp:92
std::shared_ptr< CanBusInterface > can_bus_
This is the pointer to the can bus to communicate with.
Definition: motor_board.hpp:609
int control_timeout_ms_
If no control is sent for more than control_timeout_ms_ the board will shut down. ...
Definition: motor_board.hpp:691
MeasurementIndex
This is the list of the measurement we can access.
Definition: motor_board.hpp:249
this class exists purely for logical reasons, it does not in itself implement anything.
Definition: device_interface.hpp:36
Ptr< StatusTimeseries > status_
This is the status history of the CAN board.
Definition: motor_board.hpp:640
std::vector< std::shared_ptr< Type > > create_vector_of_pointers(const size_t &size, const size_t &length)
Create a vector of pointers.
Definition: motor_board.hpp:359
Ptr< CommandTimeseries > sent_command_
This is the history of the already sent commands.
Definition: motor_board.hpp:668
void print() const
Display on a terminal the status of the message.
Definition: motor_board.hpp:54
std::shared_ptr< Type > Ptr
A useful shortcut.
Definition: motor_board.hpp:240
uint8_t motor1_enabled
Bits 1 enables/disable of the motor 1.
Definition: motor_board.hpp:122
int32_t bytes_to_int32(T bytes)
private methods ========================================================
Definition: motor_board.hpp:528
real_time_tools::ThreadsafeTimeseries< MotorBoardStatus > StatusTimeseries
A useful shortcut.
Definition: motor_board.hpp:232
virtual Ptr< const ScalarTimeseries > get_control(const int &index) const
Get the controls to be sent.
Definition: motor_board.hpp:430
This class represent a 8 bits message that describe the state (enable/disabled) of the card and the t...
Definition: motor_board.hpp:107
CanframeIDs
These are the frame IDs that define the kind of data we acquiere from the CAN bus.
Definition: motor_board.hpp:615
static THREAD_FUNCTION_RETURN_TYPE loop(void *instance_pointer)
This is the helper function used for spawning the real time thread.
Definition: motor_board.hpp:588
IDs
IDs are the different implemented commands that one can send to the MotorBoard.
Definition: motor_board.hpp:63
This class CanBusMotorBoard implements a MotorBoardInterface specific to CAN networks.
Definition: motor_board.hpp:376
Vector< Ptr< ScalarTimeseries > > control_
Inputs.
Definition: motor_board.hpp:649
ControlIndex
This is the list of the controls we can send.
Definition: motor_board.hpp:259
virtual Ptr< const ScalarTimeseries > get_sent_control(const int &index) const
Get the already sent controls.
Definition: motor_board.hpp:452
uint8_t system_enabled
These are the list of bits of the message.
Definition: motor_board.hpp:117