Creating a map with just LIDAR using hector_slam

Charlotte Dorn
3 min readFeb 7, 2020

This tutorial uses resources from Technische Universität Darmstadt’s github.

The necessary files can be found here: https://github.com/tu-darmstadt-ros-pkg/hector_slam/tree/melodic-devel/hector_slam_launch/launch and cloned by running

git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam.git

SLAM, Simultaneous Localization and Mapping, allows for the creation of and navigation through maps with just LIDAR.

This tutorial is based on the car design for F1/10, a 1/10th scale autonomous racing competition. One strategy for this competition is to create a map of the track and then navigate through it with a path following algorithm.

The computer we are using is a Jetson TX2 Development Kit, running Ubuntu 16.04 and ROS Kinetic. The LIDAR we will be using is Hokuyo UST-10LX, although this should work with any LIDAR scanner that can publish to /scan.

How NOT to Get Odometry

When I first started mapping, I tried using the vesc for odometry. Theoretically, by receiving the motor commands, one could gauge how far the car has traveled and in what direction. When actually running this node; however, it proved to be wildly inaccurate and a lot of calculations of parameters would be needed to make it functional.

I had set the following parameters based on this link:

rosparam set speed_to_erpm_gain -1664
rosparam set speed_to_erpm_offset 0
rosparam set steering_angle_to_servo_gain 1
rosparam set steering_angle_to_servo_offset 0.22
rosparam set wheelbase 0.34
rosrun vesc_ackermann vesc_to_odom.node

Also, attempting to get odometry from a Razor 9dof IMU by Sparkfun was a lost cause.

Optional: Starting with a ROS Bag

Recording a ROS bag is useful if you want to drive your car around an area with teleop and then create a map using that data afterward. This also allows you to run the data any number of times while practicing mapping.

Start by running all the main nodes necessary for teleop.

Our team neatly packaged all of these into one file called start_tmux_car … _with_joy.sh. Otherwise, the following need to be run one at a time.

roscore
rosrun vesc_driver vesc_node
rosrun urg_node urg_node _ip_address:=XXX.XXX.X.XXX

The following commands should be run to publish a transformation from map to laser and record the actual time.

Rosrun tf static_transform_publisher 0 0 0 0 0 0 1.0 map laser 10
Rosparam set use_sim_time false

Then to start recording, run:

cd Desktop/testing
Rosbag record -O tutorial.bag /scan /tf

After you’ve finished recording, run

Rosrun map_server map_saver -f <map name>

and then close the ROS bag recording with Ctrl+C.

Make Your Map in RVIZ

Startup Rviz (ROS Visualization) by running:

Rviz
Roscd hector_slam_launch/launch
Roslaunch tutorial.launch
Rosbag play tutorial.bag --clock
Rosrun map_server map_server -f <map name>

If you’re using a pre-recorded bag:

rosparam set use_sim_time true
rosbag play tutorial.bag --clock

If you are running this in real-time:

rosparam set use_sim_time false

This program launches mapping_demo.rviz, mapping_default.launch, and geotiff_mapper.launch.

However, in mapping_default.launch, some changes need to be made before this will work.

  • Default base_frame and odom_frame needs to be set to base_frame
<arg name=”base_frame” default=”base_frame”/>
<arg name=”odom_frame” default=”base_frame”/>

After running for a bit, Rviz should show something like this

Et violá!

More info…

Hector_mapping:

This node subscribes to the scan topic and potential reset messages and publishes map_metadata, map, slam_out_pose, and poseupdate.

It requires a tf transform:

<the frame attached to incoming scans> → base_frame

And if “pub_map_odom_transform” is true, it will transform map to odom.

--

--