Hi, i canot publish an array to ros from arduino ide.
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();
}`
We're all here to help so no need for the "plz help"
Make sure you're not using the same serial port for ROS and for
Serial.println(..)
). That will not work.Also: make sure you have a large enough buffer on the Arduino side (
LaserScan
msgs are big), and search ROS Answers for similar Q&As. There have been a few.make sure you are adding ros header at the top of the code.
So in general: @ARUN T S: in order for us to all stop guessing what migth be wrong here, please update your question to include the relevant (and required) information. See wiki/Support.
i edited my question ,this is my full program, can u guys find out what is the error in my program? am trying to create a map of surroundings with a lidar lite v3 using hector slam
I see a
Serial.println(lidarGetRange());
and use of ROS in the same program. Have you made sure that those two are not using the same serial port?Also: please see the support guidelines: we cannot ..
.. help you because all you wrote was "I canot publish". Does that mean that everything appears to work, but there are no messages? Are you getting error messages printed on your console? Is
rosserial
complaining about desyncs? Etc.Getting error message when i tries to establish serial publication between arduino and ros
When i remove for loop no error