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

I'm not able to give you a full answer, however I did experience something similar so maybe I can be of some help to you or others. The sync error may have something to do with your script getting stuck before it is connected.

When I would run rosserial_python, let it run for a while then close it, the next time I started it I would always get the unable to sync error message. Sometimes I would gave to reload the script onto the arduino to get it to work again.

You can add a line in the setup to wait until your node handle is connected. I think this is definitely needed when you are getting parameters from the parameter server, as you need to make sure you are connected before the line to fetch the parameters is reached. Below is an example:

void setup(){

  nh.initNode();

  nh.subscribe(sub);

  while(!nh.connected()) {nh.spinOnce();}

  ... get parameters, do more stuff, etc.

This appeared to have solved my sync issue for me, as I think my script was getting hung up occasionally when getting parameters. Maybe after the sync error is issued it retries, and that is why yours connects?