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

serial communication

asked 2013-06-18 02:07:47 -0500

ryann2k1 gravatar image

updated 2013-06-18 09:51:12 -0500

ipso gravatar image

Im having problems when reading the package from my usb port, It seems the data package is not correctly capture. I am following : by a slight modification:

#define REPLY_SIZE 8
#define TIMEOUT 1000

int main(int argc, char** argv)
    ros::init(argc, argv, "example_node");
    ros::NodeHandle n;

    cereal::CerealPort device;
    char reply[REPLY_SIZE];
   // int reference;

    try{"/dev/ttyUSB0", 57600); }
    catch(cereal::Exception& e)
        ROS_FATAL("Failed to open the serial port!!!");
    ROS_INFO("The serial port is opened.");

    ros::Rate r(1);
        // Send 'R' over the serial port
        //device.write("A"); replacing by the data sent by the Maxbotix usb sensor

        // Get the reply, the last value is the timeout in ms
        //int cereal::CerealPort::read(char * buffer, int max_length, int timeout)
        try{, REPLY_SIZE, TIMEOUT); }
        catch(cereal::TimeoutException& e)
       ROS_INFO("Got this reply: %s", reply);
       // reference = atoi (reply);


so instead of sending character A, I am reading data sent by a Maxbotix USB ultrasonic sensor. But the output displayed is not correct, there is a mismatch. I am presuming i need to synronize when the sensor is sending data( start and end data) as the Maxbotix usb sensor keeps monitoring and updating its sensor reading. Should I use : bool startReadStream(boost::function<void(char*, int)> f) as to determine when to start to read and when to stop.

Looking forward to any comment. Thanks

edit retag flag offensive close merge delete


I have managed to solved the problem. Do I need to delete this thread as no one is responding?

ryann2k1 gravatar image ryann2k1  ( 2013-06-18 23:22:53 -0500 )edit

You're allowed to answer your own question - I'd go ahead and answer with what your solution was, in case it'll help somebody else.

lindzey gravatar image lindzey  ( 2013-06-19 11:17:46 -0500 )edit

3 Answers

Sort by » oldest newest most voted

answered 2013-06-19 23:56:48 -0500

ryann2k1 gravatar image

As the MaxBotix sensor is free running, need to adjust proper delay time:

ros::Rate r(1); r.sleep();

in my case, the accurate time is r(10). Different sensor may require different settings. removing the delay will just generate a mismatch to the reading.

edit flag offensive delete link more

answered 2014-01-28 21:49:27 -0500


Do you have the updated version of this node? I am using the Maxbotix USB-ProxSonar-EZ and would like to read the range in a similar manner. I have adjusted my rate to 10 but still seem to get a mismatch with reads. Thanks.

edit flag offensive delete link more

answered 2017-02-16 08:05:29 -0500

MaxBotix Inc., is pleased to support the ROS community.

MaxBotix Inc., has produced a large number of articles to help users be more successful with our sensors. There are three such articles that would be of help in regards to ROS and the Serial output

Using the MaxSonar TX Output

Configuring USB-MaxSonar® Ultrasonic Sensors

MaxBotix Ultrasonic Sensor used in the Robot Operating System (ROS)

If any users have further questions regarding MaxBotix sensors, we are glad to provide detailed support by phone or email. Please visit our contact us page for contact information.

We wish you success on your project.

Best Regards,

Scott Wielenberg

Sales and Engineering Specialist

of MaxBotix Inc.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-06-18 02:07:47 -0500

Seen: 1,975 times

Last updated: Jan 28 '14