[ERROR] [1571394602.587660]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino

asked 2019-10-18 05:57:52 -0600

mohan97 gravatar image

I'm getting this error when trying to run this code. The other codes from ros_lib and my personal codes are not giving me any such errors. I tried using different cables which didn't work out as well.

#include <ros.h>
#include <geometry_msgs/Pose2D.h>

ros::NodeHandle node;
geometry_msgs::Pose2D odom;
ros::Publisher odom_pub("odom", &odom);

int clicks = 0;
float distance_per_revolution = (2 * PI * 5);
float distance_per_click = distance_per_revolution / 900;
int wheel_base = 15;
float left_distance;
float right_distance;

int encoderA;
int encoderB;

void setup() {
  //variables
  Serial.begin(57600);
  node.initNode();
  node.advertise(odom_pub);
}

void loop() {
  left_distance = distance_of_wheel(2, 4);
  right_distance = distance_of_wheel(3, 5);
  odom.x = (left_distance + right_distance) / 2;
  odom.y = (left_distance - right_distance) / wheel_base;
  odom_pub.publish(&odom);
  node.spinOnce();
  delay(500);
}

float distance_of_wheel(int encoderA, int encoderB) {
  while (1) {
    attachInterrupt(digitalPinToInterrupt(encoderA), count, RISING);
    float distance = distance_per_click * clicks;
  }

}

void count() {
  if (digitalRead(encoderB) == LOW) {
    clicks ++;
  }
  else {
    clicks --;
  }
}
edit retag flag offensive close merge delete

Comments

i think its possibly because of Serial.begin(57600); comment that and check

kallivalli gravatar image kallivalli  ( 2019-10-19 02:09:29 -0600 )edit

Thank you kallivalli for the suggestion. I tried that and it shows the same error, and anyway I have a different code running properly even though it has Serial.begin(57600);

mohan97 gravatar image mohan97  ( 2019-10-19 02:46:22 -0600 )edit