hi am using Arduino Mega with LIDAR Lite V3 to create a map but it get restaring after some time
`
`#define USB_USBCON
#define LIDARLite_ADDRESS 0x62
#define RegisterMeasure 0x00
#define MeasureValue 0x04
#define RegisterHighLowB 0x8f
#include <ros.h>
#include <Wire.h>
#include <LIDARLite.h>
#include <I2C.h>
#include <sensor_msgs/Range.h>
#include <sensor_msgs/LaserScan.h>
#include <std_msgs/UInt16MultiArray.h>
#include <std_msgs/Int16MultiArray.h>
#include <Timer.h>
LIDARLite myLidarLite;
#include <Servo.h>
float pos;
int i;
Servo myservo;
ros::NodeHandle nh;
sensor_msgs::LaserScan scan;
ros::Publisher pub_range( "scan", &scan);
float ranges[100];
char frameid[] = "/base_link";
float lidarGetRange(void)
{
int val = -1;
Wire.beginTransmission((int)LIDARLite_ADDRESS); // transmit to LIDAR-Lite
Wire.write((int)RegisterMeasure); // sets register pointer to (0x00)
Wire.write((int)MeasureValue); // sets register pointer to (0x00)
Wire.endTransmission(); // stop transmitting
delay(20); // Wait 20ms for transmit
Wire.beginTransmission((int)LIDARLite_ADDRESS); // transmit to LIDAR-Lite
Wire.write((int)RegisterHighLowB); // sets register pointer to (0x8f)
Wire.endTransmission(); // stop transmitting
delay(20); // Wait 20ms for transmit
Wire.requestFrom((int)LIDARLite_ADDRESS, 2); // request 2 bytes from LIDAR-Lite
if(2 <= Wire.available()) // if two bytes were received
{
val = Wire.read(); // receive high byte (overwrites previous reading)
val = val << 8; // shift high byte to be high 8 bits
val |= Wire.read(); // receive low byte as lower 8 bits
}
return val;
}
void setup()
{
nh.getHardware()->setBaud(74880);
Serial.begin(74880);
nh.initNode();
delay(1000);
nh.advertise(pub_range);
myLidarLite.begin(0, true);
myLidarLite.configure(0);
scan.header.stamp=nh.now();
scan.ranges_length=100;
scan.ranges= ranges;
myservo.attach(9);
}
void loop()
{
for(i = 0,pos=0; i<100,pos<=180; i++,pos=pos+1.8)
{
scan.header.frame_id = frameid;
scan.angle_max= 3.14;
scan.angle_min= 0;
scan.scan_time=0.0381;
scan.angle_increment =0.0314;
scan.time_increment=0.039;
scan.range_min = 0;
scan.range_max = 40000;
ranges[i] =lidarGetRange()/100;
scan.ranges[i] =ranges[i];
pub_range.publish(&scan);
myservo.write(pos);
}
nh.spinOnce();
}
Initially it works fine but after some time it shows error, Error is like
[ERROR] [1510517471.428006]: Lost sync with device, restarting...
and while it restarting it also stops the servo
also tried various baud rates