ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

rosserial arduino losing sync

asked 2019-01-08 11:36:44 -0500

cr055 gravatar image

Dear community,

I have used ROS in the past, but it was for different applications.

Going straight to the point, I am building an autonomous hexapod (with lidars, depth cameras etc.) but I am struggling to have the communication with arduino working properly.

The problem seems to be linked to the calculations I do in order to obtain the IMU readings.

If I comment out the function responsible for retrieving the new data, the publishing from arduino, and the echo I do on the topic of interest, can loop forever.

If I retrieve IMU readings in the main loop the command:

rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0 _baud:=115200

fails after an arbitrary time.

Here I list the code for the loop and the function I am using in order to retrieve the readings:

void loop() {

if (!dmpReady) return;



if (state == "Idle" && millis() - t0 >= 80){

    updateMeasurements();

    delay(20);

    pub_imu.publish(&imuMeasure);

    t0 = millis();

}


nh.spinOnce();}


void updateMeasurements(){

  mpu.resetFIFO();
  while (!mpuInterrupt && fifoCount < packetSize) {
      if (mpuInterrupt && fifoCount < packetSize) {
          fifoCount = mpu.getFIFOCount();
      }  
  }
  mpuInterrupt = false;
  mpuIntStatus = mpu.getIntStatus();


  fifoCount = mpu.getFIFOCount();
  while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

  mpu.getFIFOBytes(fifoBuffer, packetSize);


  fifoCount -= packetSize;


  mpu.dmpGetQuaternion(&q, fifoBuffer);

  imuMeasure.w = q.w;
  imuMeasure.x = q.x;
  imuMeasure.y = q.y;
  imuMeasure.z = q.z;}

As I said, after an arbitrary time I start to get error messages from the rosserial python terminal like:

[ERROR] [1546970875.729310]: Lost sync with device, restarting...
[ERROR] [1546970890.731936]: Lost sync with device, restarting...
[ERROR] [1546970905.734680]: Lost sync with device, restarting...

At this point, in order to get things to work properly again, I have to reset the Arduino (mega).

I beg for your help, I am not getting out this it seems.

edit retag flag offensive close merge delete

Comments

You seem to only call nh.spinOnce() if dmpReady == true. That might not be what you want. I'd call spinOnce() always, and only process IMU data when it is available.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-08 14:57:27 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-01-08 12:38:38 -0500

cr055 gravatar image

updated 2019-01-14 12:42:26 -0500

Apparently, it's magically solved after trying another IMU. It seems that a faulty sensor was the reason of crashes.

EDIT: more than a faulty sensor only, it was also the combination between the varying time in executing the IMU measures update and the bad organized loop.

After reducing to its simplest form the cited function and by making the loop lighter, it seems that I can publish IMU readings (together other sensors) for undetermined time.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-01-08 11:36:44 -0500

Seen: 394 times

Last updated: Jan 14 '19