ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

[ERROR] [1519470945.359482]: Lost sync with device, restarting...

asked 2018-02-24 05:59:35 -0500

beso gravatar image

updated 2018-03-06 01:57:47 -0500

jayess gravatar image

hello everyone i have this error when i connect xbee s1 to my arduino to send sensors data i am using ROS kinetic with ubuntu 16.04

my code

#include <Wire.h>

#include <dht.h>

#include <ros.h>

#include <std_msgs/Float32.h>

#include <sensor_msgs/Temperature.h>

#include <sensor_msgs/RelativeHumidity.h>

//**************************************************************
#define DHT11_PIN 6

float temp ; 

float hum ; 

const int trigPin = 9;

const int echoPin = 10;

float sensorReading =0; 

dht DHT;

long duration;

int distance;

//***********************************************************

std_msgs::Float32 sonar_msg;

sensor_msgs::Temperature temp_msg;

sensor_msgs::RelativeHumidity humidity_msg;

ros::Publisher pub_temp("temperature", &temp_msg);

ros::Publisher pub_humidity("humidity", &humidity_msg);

ros::Publisher pub_sonar("sonar", &sonar_msg);

ros::NodeHandle nh;

//********************************************************

void setup(){

  Serial.begin(57600);

  Wire.begin(); 

  nh.initNode();

  nh.advertise(pub_temp);

  nh.advertise(pub_humidity);

  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

  pinMode(echoPin, INPUT); // Sets the echoPin as an Input

  nh.initNode();

  nh.advertise(pub_sonar);

}

 //**************************************************************

void loop()
{ 
nh.spinOnce();
 if (millis()-last_time>=100){

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;


  int chk = DHT.read11(DHT11_PIN);

  temp = DHT.temperature;

  hum = DHT.humidity; 

  temp_msg.temperature = DHT.temperature ;

  humidity_msg.relative_humidity = DHT.humidity ; 

  pub_temp.publish( &temp_msg);

  nh.spinOnce();

  pub_humidity.publish( &humidity_msg);

  sonar_msg.data = distance;

  pub_sonar.publish(&sonar_msg);

 last_time=millis();
 }

}

HERE IS THE ERROR

ERROR badeaa@badeaa-VPCEA22FX:~/sketchbook/libraries$ rosrun rosserial_python serial_node.py /dev/ttyACM1 
[INFO] [1519548036.306024]: ROS Serial Python Node 
[INFO] [1519548036.313912]: Connecting to /dev/ttyACM1 at 57600 baud 
[INFO] [1519548039.022223]: Note: publish buffer size is 512 bytes 
[INFO] [1519548039.023157]: Setup publisher on temperature [sensor_msgs/Temperature] 
[INFO] [1519548039.027670]: Setup publisher on humidity [sensor_msgs/RelativeHumidity] 
[INFO] [1519548039.033109]: Setup publisher on sonar [std_msgs/Float32] 
[ERROR] [1519548071.706710]: Lost sync with device, restarting... 
[ERROR] [1519548086.708586]: Lost sync with device, restarting...
edit retag flag offensive close merge delete

Comments

Can you please update your question with a copy and paste of the entire error that you're getting using the preformatted text (101010) button?

jayess gravatar image jayess  ( 2018-02-25 02:11:44 -0500 )edit

I updated it right now

beso gravatar image beso  ( 2018-02-25 02:45:19 -0500 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2018-02-25 09:43:08 -0500

Wolf gravatar image

Do not use Serial.println with rosserial --> serial connection is used for the communication for the serial node with the device, so other outputs will cause trouble and won't end up to the console. Use nh.log_info , nh.log_warn etc. if you want to print something to the console of the serial_node.py and to rosout.

See: http://wiki.ros.org/rosserial/Overvie...

Further it would be better not to delay for such a long time as serial_node and device have to sync. This is done in nh.spinOnce(). If you want something to be done e.g. only each second, remember a time stamp and then enter in the loop only accordingly but call spinOnce each time.

E.g.:

uint last_time_action_done_millis = 0;

void loop()
{
  if ( millis() > last_time_action_done_millis + 1000 )
  {
     last_time_action_done_millis = millis();

     // do stuff you want to do once per second
  }

  // call nh.spinOnce() each time in loop
  nh.spinOnce();
}
edit flag offensive delete link more

Comments

i updated my code but still have the same error. any recommendations !!!

beso gravatar image beso  ( 2018-03-04 05:12:47 -0500 )edit
0

answered 2018-03-04 05:54:23 -0500

can you include the rest of your code (setup and any initial declarations)

edit flag offensive delete link more

Comments

sure, i updated it have a look please

beso gravatar image beso  ( 2018-03-04 06:29:05 -0500 )edit

I don't know that it is the problem, but having

nh.initNode();

twice in setup may be problematic - delete the second one and see if that helps

nickw gravatar image nickw  ( 2018-03-04 06:34:21 -0500 )edit

i deleted it but have the same error, just when i connect rx &tx of xbee to arduino board

beso gravatar image beso  ( 2018-03-04 06:48:12 -0500 )edit

Can you clarify what you mean by that - do things work fine if you are using the usb-serial connection rather than the xbee?

nickw gravatar image nickw  ( 2018-03-04 07:02:45 -0500 )edit

which dht library are you using ?

nickw gravatar image nickw  ( 2018-03-04 07:10:15 -0500 )edit

my code is working fine without connection with xbee s1

beso gravatar image beso  ( 2018-03-08 00:41:18 -0500 )edit

It seems most likely that the issue is with your xbee module configuration then - are you able to get any serial communication to work with them - try some of the arduino communication examples

nickw gravatar image nickw  ( 2018-03-10 00:32:44 -0500 )edit

yes i think so thanks so much for your help

beso gravatar image beso  ( 2018-03-12 03:46:31 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-24 05:59:35 -0500

Seen: 822 times

Last updated: Mar 06 '18