Ask Your Question

Use data from IR sensor to build a costmap

asked 2014-12-18 06:31:37 -0600

dawid.wolski gravatar image

updated 2015-01-12 04:02:20 -0600


I'm working on Turtlebot2. I will use cover for my robot, so I moved Kinect to the front of the robot to make a smaller holes in cover. But now I have a blind area in front of the robot, between 0 and 45 cm. I decided to mount some IR sensors. I made transformation for (yet) only one sensor

#include <ros/ros.h>
#include <tf/transform_broadcaster.h>

int main(int argc, char** argv){
  ros::init(argc, argv, "irring_tf");
  ros::NodeHandle n;

  ros::Rate r(100);

  tf::TransformBroadcaster broadcaster;

        tf::Transform(tf::Quaternion(0, 0, 0, 1), tf::Vector3(0.135, 0.0, 0.2)),
        ros::Time::now(),"base_link", "base_irring"));

next I receive data from sensor and publish it as a LaserScan message (I create two points from one sensor, because I will use this code for more sensors, in this case it is no matter)

    ros::Time scan_time = ros::Time::now(); 
    sensor_msgs::LaserScan scan;
    scan.header.stamp = scan_time;
    scan.header.frame_id = "base_irring";
    scan.angle_min = -0.05;     //rad
    scan.angle_max = 0.05;      //rad
    scan.angle_increment = 0.10 / num_readings;     //rad
    scan.time_increment = (1 / laser_frequency) / (num_readings);   //sec
    scan.range_min = 0.20;       //meters
    scan.range_max = 1.15;     //meters

    for(unsigned int i = 0; i < num_readings; ++i){
      scan.ranges[i] = atof(buf) / 100.0;   //data from arduino
//      scan.intensities[i] = 1; //data from arduino


It works, I can visualize data in correct place using Rviz (white line is data from Kinect, red dots data are taken from IR sensor)

Next I want to use this data to build costmap, so I add to costmap_common_params.yaml my irring_scan, changed map_type from voxel to costmap (because I want to clear obstacles detected by IR sensors by Kinect, I want to use 2d map)

max_obstacle_height: 0.60  # assume something like an arm is mounted on top of the robot

# Obstacle Cost Shaping (
# robot_radius: 0.20  # distance a circular robot should be clear of the obstacle (kobuki: 0.18)
footprint: [[-0.25, 0.25], [0.25, 0.25], [0.25, -0.25], [-0.25, -0.25]]  # if the robot is not circular

map_type: costmap

  enabled:              true
  max_obstacle_height:  0.6
  origin_z:             0.0
  z_resolution:         0.2
  z_voxels:             2
  unknown_threshold:    15
  mark_threshold:       0
  combination_method:   1
  track_unknown_space:  true    #true needed for disabling global path planning through unknown space
  obstacle_range: 2.5
  raytrace_range: 3.0
  origin_z: 0.0
  z_resolution: 0.2
  z_voxels: 2
  publish_voxel_map: false
  observation_sources:  scan bump irring_scan
    data_type: LaserScan
    topic: scan
    marking: true
    clearing: true
    min_obstacle_height: 0.25
    max_obstacle_height: 0.35
    data_type: LaserScan
    sensor_frame: base_link
    topic: irring_scan
    marking: true
    clearing: true
    min_obstacle_height: 0.25
    max_obstacle_height: 0.35
    data_type: PointCloud2
    topic: mobile_base/sensors/bumper_pointcloud
    marking: true
    clearing: false
    min_obstacle_height: 0.0
    max_obstacle_height: 0.15
  # for debugging only, let's you see the entire voxel grid

#cost_scaling_factor and inflation_radius were ...
edit retag flag offensive close merge delete


Hi, so with regards to the "Edit", did you finally successfully implemented the mapping with IR sensor(s)? may i ask what IR sensors (make and model) did you use? im trying to practice the same implementation on my Turtlebot. Thanks!

sobot gravatar image sobot  ( 2015-05-03 14:25:24 -0600 )edit

Hi, sorry for my late response, but now I'm not working with the robot. Yes, my mapping using IR sensors and other sensors works well. I use 9 Sharp GP2Y0A21YK or similar sensors. For me the most important parameter is the minimal range.

dawid.wolski gravatar image dawid.wolski  ( 2015-06-10 03:58:09 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-06-10 15:46:12 -0600

jorge gravatar image

Hi, we added both an IR ring and a sonar ring to the turtlebot. Code for the sonar ring using and Arduino Mega can be found here. I use Bosch drivers to interface with arduino. There's also code to read Sharp IR (is basically the same, apart that the sonars need to be triggered). And 3D models to nicely mount a ring on the TB2 can be downloaded here

Hope this helps.

edit flag offensive delete link more


Thank you!

sobot gravatar image sobot  ( 2015-06-17 09:29:57 -0600 )edit

I have changed the way I interact with the arduino, because as I read 15 sensors, using a Bosch driver for each one makes reading very slow. I have now wrote my own very simple arduino firmware that collects all data and send through serial port. The driver just read it at convert into ROS Range msg

jorge gravatar image jorge  ( 2015-06-18 05:58:41 -0600 )edit

answered 2016-04-28 12:22:50 -0600

Emilien gravatar image

hi, i want to use IR sensor as laser_scan. can you give me your code arduino please?

edit flag offensive delete link more


how can i use this packae please? i am beginner on ROS. I will use IR sensor and Arduino UNO

Emilien gravatar image Emilien  ( 2016-04-28 16:02:16 -0600 )edit

mmm... if you are beginner, I would suggest you to use rosserial_arduino instead. Is easier and fully documented. See the tutorias: . Your case is tutorial 9

jorge gravatar image jorge  ( 2016-04-28 17:07:49 -0600 )edit

yes i already see this tutorial and i test my IR with arduino and rosserial and all is OK. now i want to convert range data of IR to Laser scan in order to build a map in rviz.

Emilien gravatar image Emilien  ( 2016-04-29 02:28:47 -0600 )edit

jack, I suggest you start a new question so others will see it rather than posting it as an answer.

Airuno2L gravatar image Airuno2L  ( 2016-04-29 09:45:32 -0600 )edit

I know but here we are on the right road, i already put my question but i dont get a reponse;

Emilien gravatar image Emilien  ( 2016-04-29 11:31:30 -0600 )edit

can you post the link to the new question?

jorge gravatar image jorge  ( 2016-05-01 08:48:01 -0600 )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


Asked: 2014-12-18 06:31:37 -0600

Seen: 2,751 times

Last updated: Apr 28 '16