Robotics StackExchange | Archived questions

Lost sync with device, restarting...

I have an arduino ros code for my project but I always get this error when I run this code. I have no idea what's wrong with this code. Can someone help me


[ERROR] [WallTime: 1484729320.445844] Lost sync with device, restarting...
[INFO] [WallTime: 1484729320.458178] Setup publisher on gripper/force [gripper_driver/force]

Oh, and one more my subscriber topic never published to the list of rostopic I attached the code for my project too :

#define USE_USBCON
#include 
#include 
#include 
#include 
#include 
#define pumpSensor 1
#define pumpOut 7

//Pump Imput
bool pump_input = false;

//Force Sensor
float force1=0;
float force2=0;
float rest_m= 2700; //in ohm
float v_supply=5;
float rest1= 10000;
float rest2= 1000;

const float p1l= 1217.7;
const float p2l= -2941.6;
const float p3l= 2928.9;
const float p4l= 157.2 ;
const float p5l= 2.4420;

const float p1h= 0.8532;
const float p2h= -14.6476;
const float p3h= 405.0821;
const float p4h= 914.0176;
const float p5h= -1.3282;

float rest_fsr1=0;
float cond_fsr1=0;
float rest_fsr2=0;
float cond_fsr2=0;

/******************* ROS configuration  *******************/
ros::NodeHandle                     nh;

gripper_driver::force               force_msg;

ros::Publisher force_publisher("gripper/force", &force_msg); 

void publishForce(){
  float v_in1=(float)analogRead(A1)/1023*5;
  float v_in2=(float)analogRead(A2)/1023*5;

  //for fsr1
  rest_fsr1= (v_supply*rest_m/v_in1)-rest_m;  // >>>>>>>>>>>>>>>>>>>>>> rest_far undefined <<<<<<<<<<<<<<<<<<<<
  rest_fsr1=rest_fsr1/1000;
  cond_fsr1=1/rest_fsr1; //in k ohm           // >>>>>>>>>>>>>>>>>>>>>> cond_far undefined <<<<<<<<<<<<<<<<<<<<

  //low-high borderline C=0.8(1/kohm) or R=1.25 kohm
  if(rest_fsr1<1250){
    force1=p1l*pow(cond_fsr1,4) + p2l*pow(cond_fsr1,3) + p3l*pow(cond_fsr1,2) + p4l*cond_fsr1;
  }
  else{
    force1=p1h*pow(cond_fsr1,4) + p2h*pow(cond_fsr1,3) + p3h*pow(cond_fsr1,2) + p4h*cond_fsr1;
  }

  //for fsr2
  rest_fsr2= (v_supply*rest_m/v_in2)-rest_m;  // >>>>>>>>>>>>>>>>>>>>>> rest_far undefined <<<<<<<<<<<<<<<<<<<<
  rest_fsr2=rest_fsr2/1000;
  cond_fsr2=1/rest_fsr2; //in k ohm           // >>>>>>>>>>>>>>>>>>>>>> cond_far undefined <<<<<<<<<<<<<<<<<<<<

  //low-high borderline C=0.8(1/kohm) or R=1.25 kohm
  if(rest_fsr2<1250){
    force2=p1l*pow(cond_fsr2,4) + p2l*pow(cond_fsr2,3) + p3l*pow(cond_fsr2,2) + p4l*cond_fsr2;
  }
  else{
    force2=p1h*pow(cond_fsr2,4) + p2h*pow(cond_fsr2,3) + p3h*pow(cond_fsr2,2) + p4h*cond_fsr2;
  }
  
  force_msg.force1=force1;
  force_msg.force2=force2;
  force_publisher.publish(&force_msg);
  return;
}

void set_pump_input(const std_msgs::Bool &set_pump_input){
  pump_input    = set_pump_input.data;
 }

ros::Subscriber pump_in_subscriber("gripper/pump_input", &set_pump_input);

void setup() {
  // put your setup code here, to run once:
  pinMode(pumpOut, OUTPUT);
  
  nh.initNode();

  nh.subscribe(pump_in_subscriber);

  nh.advertise(force_publisher);
  
}

void loop() {
  // put your main code here, to run repeatedly:

   publishForce();
   
  if(pump_input){
    digitalWrite(pumpOut, HIGH);
  }
  else{
    digitalWrite(pumpOut, LOW);
  }
  
  // >>>>> Maybe put a short delay here <<<<<
  nh.spinOnce();
  delay(1000);
}

This is my updated code, the simple implementation to get bogus data. Now this thing is working after i added the logger.


#define USE_USBCON
#include 
#include 
#include 
#include 
#include 
#define pumpSensor 1
#define pumpOut 7

float force1=0;
float force2=0;

bool pump_input=false;


/******************* ROS configuration  *******************/
ros::NodeHandle                     nh;

std_msgs::Bool                              boolean_msg;
gripper_driver::force                       force_msg;

ros::Publisher force_publisher("gripper/force", &force_msg);

void set_pump_input(const std_msgs::Bool &set_pump_input){
  //char str[]= "SETTTT!!!!";
  //nh.loginfo(str);
  
  pump_input  = set_pump_input.data;
 }

ros::Subscriber pump_in_subscriber("gripper/pump_input", &set_pump_input);

void publishForce(){
  char str[]= "inside publishforce()";
  nh.loginfo(str);
  
  force1=1;
  force2=2;
  force_msg.force1=force1;
  force_msg.force2=force2;
  force_publisher.publish(&force_msg);

  char str1[]= "publishforce() finish";
  nh.loginfo(str1);
  return;
}


void setup() {
  // put your setup code here, to run once:
  pinMode(pumpSensor, INPUT);
  pinMode(pumpOut, OUTPUT);
  
  nh.initNode();

  nh.getHardware()->setBaud(57600);
  nh.advertise(force_publisher);

  nh.subscribe(pump_in_subscriber);

  char str[]= "setup finish";
  nh.loginfo(str);
}

void loop() {
  // put your main code here, to run repeatedly:
  char str[]= "in loop";
  nh.loginfo(str);
  
  publishForce();

  if(pump_input){
    digitalWrite(pumpOut, HIGH);
  }
  else{
    digitalWrite(pumpOut, LOW);
  }

  delay(100);

  char str1[]= "end loop";
  nh.loginfo(str1);
  
  nh.spinOnce();
}

Asked by calvintanct on 2017-01-18 04:00:27 UTC

Comments

Can you get a minimal implemention of this working? So just a simple loop publishing bogus values?

Asked by gvdhoorn on 2017-01-18 06:40:32 UTC

okay i will try and give you an update, thanksss!!

Asked by calvintanct on 2017-01-18 23:51:36 UTC

i have updated the code and still the error occurs. My arduino can work with simple hello world but this one cannot.

Asked by calvintanct on 2017-01-19 03:22:58 UTC

So do any of the rosserial examples work for you? If not, then it would appear there is something not setup correctly.

Asked by gvdhoorn on 2017-01-19 03:51:53 UTC

the hello world from the ros_lib example is working, and somehow for this updated code i edited just now is working too, but I don't know why adding logger make this thing works. it's still weird i cannot troubleshoot it

Asked by calvintanct on 2017-01-19 04:29:59 UTC

when you first run rosserial, does arduino publish any topics and then you get this error ? or you don't get any topics from arduino ?

Asked by roborag on 2017-01-24 03:45:15 UTC

I'm facing the same problem ! in my case, I do have topics from the arduino at first but I'm getting this error after that... do you know what should be done to fix this ?

Asked by Jasmin on 2017-05-19 06:41:01 UTC

Answers