Publish LaserScan from Arduino
Hello,
I am using an arduino Mega to publish LaserScan message. But I have a weird result, when i run this code:
#include <ros.h>
#include <sensor_msgs/LaserScan.h>
ros::NodeHandle nh;
// Laser Scan
sensor_msgs::LaserScan lidar_msg;
ros::Publisher lidar_pub("/laser_scan", &lidar_msg);
float ranges[10] = {0};
float intensities[10] = {0};
void setup()
{
// Initialize ROS node handle, advertise and subscribe the topics
nh.initNode();
nh.getHardware()->setBaud(57600);
nh.advertise(lidar_pub);
// Set LaserScan Definition
lidar_msg.header.frame_id = "lidar";
lidar_msg.angle_min = 0.0; // start angle of the scan [rad]
lidar_msg.angle_max = 3.14*2; // end angle of the scan [rad]
lidar_msg.angle_increment = 3.14*2/360; // angular distance between measurements [rad]
lidar_msg.range_min = 0.3; // minimum range value [m]
lidar_msg.range_max = 50.0; // maximum range value [m]
}
void loop(){
// simple loop to generate values
for (int i=0 ; i<10 ; ++i){
ranges[i] = 1.0*i;
}
lidar_msg.ranges = ranges;
lidar_msg.header.stamp = nh.now();
lidar_pub.publish(&lidar_msg);
nh.spinOnce();
}
Then, I launch rosserial node to start serial communication:
$ rosrun rosserial_python serial_node.py /dev/ttyUSB2
[INFO] [1519508591.451838]: ROS Serial Python Node
[INFO] [1519508591.468653]: Connecting to /dev/ttyUSB2 at 57600 baud
[INFO] [1519508593.624826]: Note: publish buffer size is 512 bytes
[INFO] [1519508593.625218]: Setup publisher on /laser_scan [sensor_msgs/LaserScan]
But when, i echo the topic, I didn't get any values in ranges:
---
header:
seq: 112
stamp:
secs: 1519508602
nsecs: 77765016
frame_id: "lidar"
angle_min: 0.0
angle_max: 6.28000020981
angle_increment: 0.0174444448203
time_increment: 0.0
scan_time: 0.0
range_min: 0.300000011921
range_max: 50.0
ranges: []
intensities: []
---
Any idea ?
matt