Tetrapod Project
|
A class for serial communication. More...
#include <serial_communication.h>
Public Types | |
enum | ControlMode { position = 1 , velocity = 2 , torque = 3 } |
Control mode enumerator. More... | |
Public Member Functions | |
SerialCommunication () | |
Default Constructor. More... | |
SerialCommunication (const std::string &_port) | |
Custom Constructor, defaults number of motors to 6. More... | |
SerialCommunication (const std::string &_port, const int &_num_motors) | |
Custom Constructor. More... | |
virtual | ~SerialCommunication () |
Destructor. More... | |
Eigen::Matrix< Eigen::VectorXd, 3, 1 > | ReceiveMessage () |
The ReceiveMessage function listens for serial messages of incoming joint state data from the motors and assign corresponding values to a joint state vector of vectors. More... | |
void | SendMessage (const ControlMode &_control_mode, const std::vector< double > &_state) |
The SendMessage function handles the sending of joint state command messages to the motors. More... | |
bool | IsNewDataAvailable () |
The IsNewDataAvailable function checks if there is available data on the serial port. More... | |
void | SetPort (const std::string &_port) |
Set the port for the Teensy communication after creating the constructor. More... | |
void | SetNumberOfMotors (const int &_number_of_motors) |
Set the number of motors for the port after creating the constructor. More... | |
void | InitLibSerial () |
The InitLibSerial function initializes the serial port to the correct input and sets baud rate, character size, flow control, and stop bits. It also sets buffer sizes for transmit (TX) and receive (RX). More... | |
Private Member Functions | |
Eigen::Matrix< Eigen::VectorXd, 3, 1 > | UnpackageBuffer (unsigned char *_data) |
The UnpackageBuffer function unpacks the read buffer data into joint state data vectors. More... | |
void | PackageBuffer (const ControlMode &_control_mode, const double *_data) |
The PackageBuffer function fills the transmit buffer with control mode and control command data to be transmitted on the serial port. More... | |
void | PackageBufferControlMode (const double *_data) |
The PackageBufferControlMode function fills the transmit buffer with control mode data. More... | |
void | PackageBufferControlCommand (const double *_data) |
The PackageBufferControlCommand function fills the transmit buffer with control command data. More... | |
Private Attributes | |
int | num_motors |
Number of motors. More... | |
std::string | port |
Serial Port. More... | |
LibSerial::SerialPort | serial_port |
LibSerial object instance. More... | |
int | TX_BUFFER_SIZE |
Serial transmit buffer size. More... | |
int | RX_BUFFER_SIZE |
Serial read buffer size. More... | |
std::vector< unsigned char > | tx_buffer |
Serial transmit buffer. More... | |
std::vector< unsigned char > | rx_buffer |
Serial read buffer. More... | |
Static Private Attributes | |
static constexpr double | rx_timeout = 0.00001 |
Read buffer timeout. More... | |
A class for serial communication.
Definition at line 40 of file serial_communication.h.
Control mode enumerator.
Enumerator | |
---|---|
position | |
velocity | |
torque |
Definition at line 46 of file serial_communication.h.
SerialCommunication::SerialCommunication | ( | ) |
Default Constructor.
Definition at line 3 of file serial_communication.cpp.
SerialCommunication::SerialCommunication | ( | const std::string & | _port | ) |
Custom Constructor, defaults number of motors to 6.
[in] | _port | Serial port name for teensy communication. |
Definition at line 5 of file serial_communication.cpp.
SerialCommunication::SerialCommunication | ( | const std::string & | _port, |
const int & | _num_motors | ||
) |
Custom Constructor.
[in] | _port | Serial port name for teensy communication. |
[in] | _num_motors | Number of motors in use. |
Definition at line 12 of file serial_communication.cpp.
|
virtual |
Destructor.
Definition at line 19 of file serial_communication.cpp.
Eigen::Matrix< Eigen::VectorXd, 3, 1 > SerialCommunication::ReceiveMessage | ( | ) |
The ReceiveMessage function listens for serial messages of incoming joint state data from the motors and assign corresponding values to a joint state vector of vectors.
Definition at line 24 of file serial_communication.cpp.
void SerialCommunication::SendMessage | ( | const ControlMode & | _control_mode, |
const std::vector< double > & | _state | ||
) |
The SendMessage function handles the sending of joint state command messages to the motors.
[in] | _control_mode | Desired motor control mode. |
[in] | _state | Desired motor commands. |
Definition at line 45 of file serial_communication.cpp.
|
private |
The UnpackageBuffer function unpacks the read buffer data into joint state data vectors.
[in] | _data | Read buffer data. |
Definition at line 65 of file serial_communication.cpp.
|
private |
The PackageBuffer function fills the transmit buffer with control mode and control command data to be transmitted on the serial port.
[in] | _control_mode | Motor control mode. |
[in] | _data | Motor command data. |
Definition at line 88 of file serial_communication.cpp.
|
private |
The PackageBufferControlMode function fills the transmit buffer with control mode data.
[in] | _data | Control mode data. |
Definition at line 97 of file serial_communication.cpp.
|
private |
The PackageBufferControlCommand function fills the transmit buffer with control command data.
[in] | _data | Control command data. |
Definition at line 105 of file serial_communication.cpp.
bool SerialCommunication::IsNewDataAvailable | ( | ) |
The IsNewDataAvailable function checks if there is available data on the serial port.
Definition at line 113 of file serial_communication.cpp.
void SerialCommunication::SetPort | ( | const std::string & | _port | ) |
Set the port for the Teensy communication after creating the constructor.
[in] | _port | Serial port name for the Teensy communication |
Definition at line 125 of file serial_communication.cpp.
void SerialCommunication::SetNumberOfMotors | ( | const int & | _number_of_motors | ) |
Set the number of motors for the port after creating the constructor.
[in] | _number_of_motors | Number of motors to use |
Definition at line 130 of file serial_communication.cpp.
void SerialCommunication::InitLibSerial | ( | ) |
The InitLibSerial function initializes the serial port to the correct input and sets baud rate, character size, flow control, and stop bits. It also sets buffer sizes for transmit (TX) and receive (RX).
Definition at line 135 of file serial_communication.cpp.
|
staticconstexprprivate |
Read buffer timeout.
Definition at line 43 of file serial_communication.h.
|
private |
Number of motors.
Definition at line 121 of file serial_communication.h.
|
private |
Serial Port.
Definition at line 124 of file serial_communication.h.
|
private |
LibSerial object instance.
Definition at line 127 of file serial_communication.h.
|
private |
Serial transmit buffer size.
Definition at line 130 of file serial_communication.h.
|
private |
Serial read buffer size.
Definition at line 133 of file serial_communication.h.
|
private |
Serial transmit buffer.
Definition at line 136 of file serial_communication.h.
|
private |
Serial read buffer.
Definition at line 139 of file serial_communication.h.