Kinematics Animation Multithread
Public Member Functions | Private Attributes | List of all members
Exoskeleton Class Reference

Class Exoskeleton. More...

#include <exoskeleton.h>

Public Member Functions

 Exoskeleton ()
 Empty constructor. More...
 
void initialize (const std::string &serial_com, unsigned int serial_baudrate)
 Initialize. More...
 
std::vector< double > incoming_data_callback (void)
 Read incoming data. More...
 
std::vector< double > get_joint_angles (void)
 Get joint angles. More...
 

Private Attributes

const int m_meas_num = 13
 Measurements num. More...
 
std::vector< double > m_raw_sensor_data
 Sensors data vector (raw) More...
 
std::shared_ptr< SerialCOMm_serial
 Serial communication handler. More...
 
std::future< std::vector< double > > m_future_fun
 Future function handle. More...
 
bool m_return_value = 0
 Termination flag for callback function. More...
 

Detailed Description

Class Exoskeleton.

This class is the interface between the hardware and the software. Its goal is to provide a callback function that reads asychronously the serial data from the SerialCOM:: class and translates it to joint angle values. It then sends the data to the animation loop and to the rendering engine

Definition at line 19 of file exoskeleton.h.

Constructor & Destructor Documentation

◆ Exoskeleton()

Exoskeleton::Exoskeleton ( )
inline

Empty constructor.

Definition at line 24 of file exoskeleton.h.

24{};

Member Function Documentation

◆ get_joint_angles()

std::vector< double > Exoskeleton::get_joint_angles ( void  )

Get joint angles.

It is the point of entry that feeds the animation loop with the exoskeleton data. It returns a vector of the raw jont angle data converted to radians. It also manages the asynchronous threading.

Returns
std::vector<double> The joint angles.

Definition at line 54 of file exoskeleton.cpp.

55{
56 // Set termination flag for asychronous function
58
59 // Get joint angles from future function
60 std::vector<double> joint_angles = m_future_fun.get();
61
62 // Convert to rad
63 for (size_t i = 0; i < joint_angles.size(); i++)
64 {
65 joint_angles.at(i) = Utils::deg2rad(joint_angles.at(i));
66 }
67
68 // Reinitialize async function
71
72 return joint_angles;
73}
bool m_return_value
Termination flag for callback function.
Definition: exoskeleton.h:51
std::future< std::vector< double > > m_future_fun
Future function handle.
Definition: exoskeleton.h:48
std::vector< double > incoming_data_callback(void)
Read incoming data.
Definition: exoskeleton.cpp:37
static double deg2rad(double deg)
Convert degrees to rad.
Definition: utils.h:28
Here is the call graph for this function:
Here is the caller graph for this function:

◆ incoming_data_callback()

std::vector< double > Exoskeleton::incoming_data_callback ( void  )

Read incoming data.

This is the callback function for reading asynchronously the incoming data from the serial port. The data come in the format:

\[ data =\left[{\theta}_{i_1}, {\theta}_{i_2}, {\theta}_{i_3}, {\theta}_{i_4}, {\theta}_{m_1}, {\theta}_{m_2}, {\theta}_{m_3}, {\theta}_{m_4}, {\theta}_{t_1}, {\theta}_{t_2}, {\theta}_{t_3}, {\theta}_{t_4}, {\theta}_{t_5} \right]^{T} \]

Returns
std::vector<double> The raw angle data coming from the exoskeleton board.

Definition at line 37 of file exoskeleton.cpp.

38{
39 while(!m_return_value)
40 {
43 }
44 return m_raw_sensor_data;
45}
std::vector< double > m_raw_sensor_data
Sensors data vector (raw)
Definition: exoskeleton.h:40
std::shared_ptr< SerialCOM > m_serial
Serial communication handler.
Definition: exoskeleton.h:45
static std::vector< double > analog_str_buf_to_double_vec(const std::string &str)
Convert comma-delimited string to double vector of analog values.
Definition: utils.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize()

void Exoskeleton::initialize ( const std::string &  serial_com,
unsigned int  serial_baudrate 
)

Initialize.

It initialiazes the serial communication and sets the asychronous callback function. See https://en.cppreference.com/w/cpp/thread/async.

Parameters
serial_comThe serial communication port.
serial_baudrateThe serial communication baudrate.

Definition at line 10 of file exoskeleton.cpp.

12{
13 // Generate serial communication channel
14 m_serial = std::make_shared<SerialCOM>(serial_com, serial_baudrate);
15
16 // Initialize stream
17 m_serial->initialize_stream();
18
19 // Initialize asychronous function
21}
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_future_fun

std::future<std::vector<double> > Exoskeleton::m_future_fun
private

Future function handle.

Definition at line 48 of file exoskeleton.h.

◆ m_meas_num

const int Exoskeleton::m_meas_num = 13
private

Measurements num.

Definition at line 37 of file exoskeleton.h.

◆ m_raw_sensor_data

std::vector<double> Exoskeleton::m_raw_sensor_data
private

Sensors data vector (raw)

Definition at line 40 of file exoskeleton.h.

◆ m_return_value

bool Exoskeleton::m_return_value = 0
private

Termination flag for callback function.

Definition at line 51 of file exoskeleton.h.

◆ m_serial

std::shared_ptr<SerialCOM> Exoskeleton::m_serial
private

Serial communication handler.

Definition at line 45 of file exoskeleton.h.


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