0
$\begingroup$

Rosanswers logo

Im having problems when reading the package from my usb port, It seems the data package is not correctly capture. I am following : http://www.ros.org/wiki/cereal_port. 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{ device.open("/dev/ttyUSB0", 57600); }
    catch(cereal::Exception& e)
    {
        ROS_FATAL("Failed to open the serial port!!!");
        ROS_BREAK();
    }
    ROS_INFO("The serial port is opened.");

    ros::Rate r(1);
    while(ros::ok())
    {
        // 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{ device.read(reply, REPLY_SIZE, TIMEOUT); }
        catch(cereal::TimeoutException& e)
        {
            ROS_ERROR("Timeout!");
        }
       ROS_INFO("Got this reply: %s", reply);
       // reference = atoi (reply);

        ros::spinOnce();
        r.sleep();
    }   
}

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


Originally posted by ryann2k1 on ROS Answers with karma: 128 on 2013-06-18

Post score: 0


Original comments

Comment by ryann2k1 on 2013-06-18:
I have managed to solved the problem. Do I need to delete this thread as no one is responding?

Comment by lindzey on 2013-06-19:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by ryann2k1 with karma: 128 on 2013-06-19

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.