Ask Your Question
1

How to read LaserScan by Arduino?

asked 2016-03-09 00:43:41 -0500

Reza1984 gravatar image

updated 2016-03-13 22:47:20 -0500

Hi

I'm using Xtion sensor to get LaserScan data using the following commands:

$ roslaunch turtlebot_bringup minimal.launch
$ roslaunch rtabmap_ros demo_turtlebot_mapping.launch rgbd_odometry:=true
$ roslaunch rtabmap_ros demo_turtlebot_rviz.launch

I can read /scan which is type "sensor_msgs/LaserScan".

I want to use this data in Aurdoino board.

I think, I have to use the following headers in Arduino code :

#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>

and the following codes:

$ ros::NodeHandle nh;
$ ros::Subscriber sub = nh.subscribe<sensor_msgs::LaserScan>("scan", 1000, scanCallback);

Now how I can access to scan array?

I appreciate if you help me.

EDIT:

I could finally find the issue. My Arduino board cannot read large data with high rate of publishing. So I just publish a std_msgs::Float32 message with low publish rate.

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
-1

answered 2016-03-10 22:14:20 -0500

Reza1984 gravatar image

updated 2016-03-13 21:10:21 -0500

I would like to summarize all the issues I faced and how I solved it:

First issue: The following error in uploading the program:

avrdude: ser_recv(): programmer is not responding avrdude: stk500_recv(): programmer is not responding

There were some solution using reset bottom but it didn't work for me. I finally found out I should use "sudo arduino" to lunch the arduino and after that I can easily upload.

Second issue: using "sudo arduino" gave me this error:

fatal error: ros.h: No such file or directory compilation terminated.

Unfortunately methods in internet didn't help me. I just tried to copy ros-lib form sketchbook to "/usr/share/arduino/libraries" and Hallelujah the error was gone! :)

Finally the main part of my code is as follows:

#include <ros.h>
#include <sensor_msgs/LaserScan.h>

void Callback_laser(const sensor_msgs::LaserScan& scan)
{
double minval = scan.ranges[0];

    for(int i=0;i<500;i++)
    {
       if(scan.ranges[i]<minval or minval!=minval)
           minval=scan.ranges[i];
    } 
   Serial.println(minval);
}

ros::NodeHandle nh;
ros::Subscriber<sensor_msgs::LaserScan> laser_subscriber("scan", &Callback_laser);

void setup() {

  nh.initNode();
  nh.subscribe(laser_subscriber);

}

void loop() {

 nh.spinOnce();
 delay(100); 

}

I thought, it works fine but apparently it doesn't! When I put a command in callback function to on the LED it doesn't on the LED. I think the reason is the laserscan data is too large! (Not Sure Though)

Even when I run "Hello World" program in ros-arduino tutorial, hello world with those strange characters are printed!

In the following attached picture you can see the results. right terminal I run "rostopic echo /scan"; left terminal I run "rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0", and top is Serial monitor.

image description

edit flag offensive delete link more
0

answered 2016-03-11 07:08:14 -0500

The strange characters that you refer to are caused when the receive and transmit baud rates on a UART connection don't match up.

Try setting some of the different baud rates and see if the data starts being printed the way you're expecting.

edit flag offensive delete link more

Comments

Thank you for your reply! I tried different baud rates but nothing changed! I think the issue is the Laserscan data is too large and it cannot call the callback function! (just a guess)

Reza1984 gravatar image Reza1984  ( 2016-03-13 20:36:12 -0500 )edit

I should note that, I add a command in callback function to on the LED but it doesn't on it.

Reza1984 gravatar image Reza1984  ( 2016-03-13 20:37:08 -0500 )edit
0

answered 2016-03-09 03:39:48 -0500

MarkyMark2012 gravatar image

Hi,

A good place to look (IMO) is the http://wiki.ros.org/depthimage_to_las... code.

You can find it here - git https://github.com/ros-perception/dep...

Mark

edit flag offensive delete link more

Comments

Thanks for your reply, but I already have access to 2D laserscan data. I don't know how to use it in Arduino.

Reza1984 gravatar image Reza1984  ( 2016-03-09 20:09:49 -0500 )edit

Do you mean you want to write code to access the scan array? If so than what I mean it look at the code in the link above as that will show you what to do

MarkyMark2012 gravatar image MarkyMark2012  ( 2016-03-10 01:48:20 -0500 )edit

Yes, in ros I can write the code but in Arduino that code doesn't work!

Reza1984 gravatar image Reza1984  ( 2016-03-10 01:52:18 -0500 )edit

Okay so what is your set up - what isn't working on Arduino?

MarkyMark2012 gravatar image MarkyMark2012  ( 2016-03-10 02:08:24 -0500 )edit

Sorry I face other issues in working with arduino, after I solve I will reply your comment. Thanks

Reza1984 gravatar image Reza1984  ( 2016-03-10 21:12:10 -0500 )edit
0

answered 2016-03-11 23:00:59 -0500

The serial monitor and rosserial are trying to use the same serial connection. Use one or the other.

edit flag offensive delete link more

Comments

Thank you for your reply! My issue is not that as I also used only one serial connection! I think the issue is the Laserscan data is too large and it cannot call the callback function! (just a guess)

Reza1984 gravatar image Reza1984  ( 2016-03-13 20:35:18 -0500 )edit

I should note that, I add a command in callback function to on the LED but it doesn't on it.

Reza1984 gravatar image Reza1984  ( 2016-03-13 20:37:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-03-09 00:43:41 -0500

Seen: 679 times

Last updated: Mar 13 '16