37 : motors(port, baud_rate,
serial::Timeout::simpleTimeout(10000)),
38 serial_loop_rate(loopRate) {
85 bool failed_update =
false;
90 motors.
read(innew.c_array(), failed_update ? 1 : 8);
97 for (
size_t i = 0; i < in.size() - 1; ++i) {
100 in[in.size() - 2] = in[in.size() - 1];
102 in[in.size() - 1] = innew[0];
108 if (error_code == 0) {
111 "GOT ERROR RESPONSE FROM PSOC FOR REGISTER 0x%02x",
115 failed_update =
false;
116 }
else if (error_code == 1) {
117 failed_update =
true;
118 char rejected[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
119 for (
size_t i = 0; i < in.size() && i < 8; i++) {
120 rejected[i] = in.at(i);
124 failed_update =
true;
125 ROS_ERROR(
"DESERIALIZATION ERROR! - %d", error_code);
129 bool did_update =
false;
134 ROS_DEBUG(
"out %02x %02x %02x %02x %02x %02x %02x %02x", out[0],
135 out[1], out[2], out[3], out[4], out[5], out[6],
138 boost::this_thread::sleep(boost::posix_time::milliseconds(2));
145 boost::this_thread::interruption_point();
149 }
catch (
const boost::thread_interrupted& e) {
shared_queue< MotorMessage > input
MotorMessage::MessageTypes getType() const
int transmitCommand(MotorMessage command)
MotorMessage::Registers getRegister() const
ros::Rate serial_loop_rate
boost::array< uint8_t, 8 > RawMotorMessage
int transmitCommands(const std::vector< MotorMessage > &commands)
void push(const T &value)
MotorSerial(const std::string &port="/dev/ttyUSB0", uint32_t baud_rate=9600, double loopRate=100)
RawMotorMessage serialize() const
boost::thread serial_thread
virtual const char * what() const
MotorMessage getInputCommand()
shared_queue< MotorMessage > output
size_t read(uint8_t *buffer, size_t size)
MotorMessage receiveCommand()
void appendOutput(MotorMessage command)
int deserialize(const RawMotorMessage &serialized)
size_t write(const uint8_t *data, size_t size)
virtual const char * what() const