ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You're doing a lot of strange things that might be affecting your ability to read the data effectively. The system has a limited serial buffer, so if you're reading the data slower than it is being sent over serial, then you'll lose some. You're calling ros::spinOnce() in your loops where you're reading the serial data. There are also a lot of cases where you're reading data but not checking to see what it is.

My recommendation is to start by creating a thread to read from the serial port and do ros::spin() in a separate thread. Then you can write a simpler loop that just reads one byte at a time. I'd also recommend using a timeout rather than doing waitReadable() between calls to read.