0
$\begingroup$

Rosanswers logo

I occasionally get a lost sync message with rosserial: "Lost sync with device, restarting..." and am wondering what exactly is being restarted and how best to recover from that in the arduino code.

It seems that the python code is fine with starting while the arduino is running its loop(). So am I correct in interpreting that to mean the python code does not need to be running for the setup() part of the arduino code, the part where the initNode() statement as well as the advertise and subscribe statements occur?

I am driving a roomba with the arduino and it seems I most often get the "lost sync" when the roomba is taking its time getting some task completed. The python code does not recover from that. I tried putting in a statement to check if the connection was up: while (!nh.connected())...... but whenever it disconnected, it would just stay in this loop and never recover.

Suggestions?


Originally posted by dan on ROS Answers with karma: 875 on 2011-09-16

Post score: 8

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

There are a few steps in to sync/resync:

  1. On your Arduino, in setup(), you define what topics you want to publish/subscribe. This data is stored on the Arduino.

  2. When the python node (re)connects, it requests the topics to be published/subscribed from the Arduino.

  3. Once synced, both sides exchange data. The python node keeps track of when the last communication was, and if no communication has happened recently, it announces "Lost sync..." and attempts step 2 again to get the Arduino/PC back into a consistent state.

Even if you weren't publishing any information, the calls to spinOnce() will cause a timestamp update every 5s (which will keep the Arduino "synced" as far as the python node is concerned).

If you frequently see "Lost sync..." then you probably aren't calling spinOnce() frequently enough. You want to be careful, because this can also cause lots of data loss on subscribers (since your serial input buffers will only be processed when you call spinOnce()).


Originally posted by fergs with karma: 13902 on 2011-09-19

This answer was ACCEPTED on the original site

Post score: 11


Original comments

Comment by ebozgul on 2013-12-25:
I was having frequent t lossync errors and this worked for me.

There was a delay loop, which didn't contain any spinOnce() calls. Althought there was one before the delay, it wasnt frequent enough as you say.

When I added a spinOnce() call inside the delay loop, problem was solved.

Thank you

Comment by Kamiccolo on 2014-03-05:
and what does "frequently enough" mean?

Comment by ebozgul on 2014-03-09:
The time between each spinOnce calls should be less than a certain amount. However, I dont know the exact amount of that time. So if you are calling spinOnce but still experiencing "lost sync" error, the frequency of the spinOnce() calls might not be enough and you should call spinOnce() more often

Comment by adelleodel on 2016-06-04:
how often spinOnce() that you mean?.. i gor confused with delay, rate in python and that spinOnce().. i just called spinOnce() in my loop like this:

void loop(){
  nh.spinOnce();
  delay(1);
}

is it not right?

Comment by أسامة الادريسي on 2017-11-04:
Didn't work for me

$\endgroup$

Your Answer

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