36 #include <libserial/SerialPort.h>
37 #include <libserial/SerialStream.h>
82 private: Eigen::Matrix<Eigen::VectorXd, 3, 1>
UnpackageBuffer(
unsigned char *_data);
108 public:
void SetPort(
const std::string &_port);
A class for serial communication.
void SetNumberOfMotors(const int &_number_of_motors)
Set the number of motors for the port after creating the constructor.
std::vector< unsigned char > rx_buffer
Serial read buffer.
int RX_BUFFER_SIZE
Serial read buffer size.
void PackageBufferControlMode(const double *_data)
The PackageBufferControlMode function fills the transmit buffer with control mode data.
void PackageBufferControlCommand(const double *_data)
The PackageBufferControlCommand function fills the transmit buffer with control command data.
SerialCommunication()
Default Constructor.
void InitLibSerial()
The InitLibSerial function initializes the serial port to the correct input and sets baud rate,...
ControlMode
Control mode enumerator.
virtual ~SerialCommunication()
Destructor.
std::vector< unsigned char > tx_buffer
Serial transmit buffer.
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.
bool IsNewDataAvailable()
The IsNewDataAvailable function checks if there is available data on the serial port.
std::string port
Serial Port.
LibSerial::SerialPort serial_port
LibSerial object instance.
int num_motors
Number of motors.
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...
int TX_BUFFER_SIZE
Serial transmit buffer size.
void SetPort(const std::string &_port)
Set the port for the Teensy communication after creating the constructor.
Eigen::Matrix< Eigen::VectorXd, 3, 1 > UnpackageBuffer(unsigned char *_data)
The UnpackageBuffer function unpacks the read buffer data into joint state data vectors.
static constexpr double rx_timeout
Read buffer timeout.
Eigen::Matrix< Eigen::VectorXd, 3, 1 > ReceiveMessage()
The ReceiveMessage function listens for serial messages of incoming joint state data from the motors ...