hi am trying create a map using lidat lite v3 through arduino,but it is not producing any map,my program is written below, can you guys please help me ? am new to ROS
enter code here
#include <ros.h>
#include <Wire.h>
#define LIDARLite_ADDRESS 0x62
#define RegisterMeasure 0x00
#define MeasureValue 0x04
#define RegisterHighLowB 0x8f
#define USB_USBCON
#include <LIDARLite.h>
#include <I2C.h>
#include <sensor_msgs/Range.h>
#include <sensor_msgs/LaserScan.h>
LIDARLite myLidarLite;
ros::NodeHandle nh;
sensor_msgs::LaserScan scan;
ros::Publisher pub_range( "lidar", &scan);
float ranges[7];
char frameid[] = "/my_frame";
int lidarGetRange(void)
{
int val = -1;
Wire.beginTransmission((int)LIDARLite_ADDRESS);
Wire.write((int)RegisterMeasure);
Wire.write((int)MeasureValue);
Wire.endTransmission();
delay(20);
Wire.beginTransmission((int)LIDARLite_ADDRESS);
Wire.write((int)RegisterHighLowB);
Wire.endTransmission();
delay(20);
Wire.requestFrom((int)LIDARLite_ADDRESS, 2);
if(2 <= Wire.available())
{
val = Wire.read();
val = val << 8;
val |= Wire.read();
}
return val;
}
void setup()
{
Serial.begin(57600);
nh.initNode();
nh.advertise(pub_range);
//delay(1000);
myLidarLite.begin(0, true);
myLidarLite.configure(0);
scan.header.frame_id = frameid;
scan.angle_min= 0;
scan.angle_max= 3.14;
scan.angle_increment =1;
scan.range_min = 0.03;
scan.range_max = 4000;
}
void loop()
{
for(int i = 0; i < 7; i++)
{
Serial.println(lidarGetRange());
scan.ranges[i] =lidarGetRange();
pub_range.publish(&scan);
}
nh.spinOnce();
}`enter code here`
Asked by ARUN T S on 2017-10-24 01:49:47 UTC
Answers
I Got the answer. The problem was with array.I had to allocate array
scan.ranges= ranges;
Asked by ARUN T S on 2017-11-02 07:06:25 UTC
Comments
Please format your question properly: a short and to the point title, the main question in the body, and any code or console text formatted using the Preformatted Text button (the one with
101010
on it). As it is, your question is rather hard to read.Asked by gvdhoorn on 2017-10-24 03:00:00 UTC
sorry about that,i formatted my question
Asked by ARUN T S on 2017-10-27 12:23:30 UTC
Lets break this down so you can get the help you need. Does just the arduino and the lidar lite without any of the ROS stuff work? Do you have any other information on where it is not working? You should add these edits to your question.
Asked by psammut on 2017-10-27 13:06:31 UTC
i donot have any idea why it is not working ,am planning to use hector mapping for the mapping
Asked by ARUN T S on 2017-10-27 13:34:33 UTC
i think it is a problem related to arrays
Asked by ARUN T S on 2017-10-28 02:21:09 UTC