32 #include <serial/serial.h> 36 : motors(port, baud_rate, serial::Timeout::simpleTimeout(100)),
37 serial_errors(0), error_threshold(20) {
49 ROS_DEBUG(
"out %02x %02x %02x %02x %02x %02x %02x %02x", out[0], out[1],
50 out[2], out[3], out[4], out[5], out[6], out[7]);
51 motors.write(out.c_array(), out.size());
56 for (
auto&
command : commands) {
58 ROS_DEBUG(
"out %02x %02x %02x %02x %02x %02x %02x %02x", out[0], out[1],
59 out[2], out[3], out[4], out[5], out[6], out[7]);
60 motors.write(out.c_array(), out.size());
61 boost::this_thread::sleep(boost::posix_time::milliseconds(2));
81 boost::this_thread::interruption_point();
82 if (
motors.waitReadable()) {
85 motors.read(innew.c_array(), 1);
95 motors.waitByteTimes(innew.size());
98 motors.read(&innew.c_array()[1], 7);
99 ROS_DEBUG(
"Got message %x %x %x %x %x %x %x %x", innew[0],
100 innew[1], innew[2], innew[3], innew[4], innew[5],
105 if (error_code == 0) {
114 ROS_WARN_ONCE(
"Message deserialize found an unrecognized firmware register");
116 ROS_ERROR(
"DESERIALIZATION ERROR! - %d", error_code);
123 }
catch (
const boost::thread_interrupted& e) {
125 }
catch (
const serial::IOException& e) {
127 }
catch (
const serial::PortNotOpenedException& e) {
static const uint8_t delimeter
int transmitCommand(MotorMessage command)
boost::array< uint8_t, 8 > RawMotorMessage
int transmitCommands(const std::vector< MotorMessage > &commands)
void push(const T &value)
MotorMessage::MessageTypes getType() const
ROSLIB_DECL std::string command(const std::string &cmd)
MotorSerial(const std::string &port="/dev/ttyUSB0", uint32_t baud_rate=9600)
#define ROS_WARN_ONCE(...)
boost::thread serial_thread
MotorMessage::ErrorCodes deserialize(const RawMotorMessage &serialized)
shared_queue< MotorMessage > output
RawMotorMessage serialize() const
MotorMessage receiveCommand()
void appendOutput(MotorMessage command)
MotorMessage::Registers getRegister() const