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

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 [closed]

asked 2017-10-24 01:49:47 -0600

ARUN T S gravatar image

updated 2017-11-03 12:58:14 -0600

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`
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by ARUN T S
close date 2017-11-02 07:07:03.508796

Comments

4

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-24 03:00:00 -0600 )edit

sorry about that,i formatted my question

ARUN T S gravatar image ARUN T S  ( 2017-10-27 12:23:30 -0600 )edit
1

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.

psammut gravatar image psammut  ( 2017-10-27 13:06:31 -0600 )edit

i donot have any idea why it is not working ,am planning to use hector mapping for the mapping

ARUN T S gravatar image ARUN T S  ( 2017-10-27 13:34:33 -0600 )edit

i think it is a problem related to arrays

ARUN T S gravatar image ARUN T S  ( 2017-10-28 02:21:09 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-11-02 07:06:25 -0600

ARUN T S gravatar image

I Got the answer. The problem was with array.I had to allocate array

scan.ranges= ranges;
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-10-24 01:49:47 -0600

Seen: 477 times

Last updated: Nov 03 '17