Skip to content

4. Setting Up Lidar and creating a Map

manthan99 edited this page Jul 11, 2019 · 1 revision

Setting Up and running the Lidar

We are using an RP Lidar A2 for obtaining the scans of the surroundings. The Lidar publishes the data at a frequency of 12 Hz. The launch file has already been configured and here are the important parameters. The file is located in the racecar/RPLidar_Hector_SLAM/rplidar_ros directory.

<launch>
  <node name="rplidarNode"          pkg="rplidar_ros"  type="rplidarNode" output="screen">
  <param name="serial_port"         type="string" value="/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0"/>  
  <param name="serial_baudrate"     type="int"    value="115200"/>
  <param name="frame_id"            type="string" value="laser"/>
  <param name="inverted"            type="bool"   value="false"/>
  <param name="angle_compensate"    type="bool"   value="true"/>
  </node>
</launch>

On launching this file, the 2D laser scan will be published on the /scan topic. Run the following command to view the laser_Scan in Rviz.

sudo chmod 777 /dev/tty*
roslaunch rplidar_ros view_rplidar.launch

Creating a map using Hector-Slam

The launch file is already configured to generate a map of the environment -racecar/RPLidar_Hector_SLAM/hector_slam/hector_slam_launch/launch/tutorial.launch

<launch>

  <arg name="geotiff_map_file_path" default="$(find hector_geotiff)/maps"/>

  <param name="/use_sim_time" value="false"/>

  <node pkg="rviz" type="rviz" name="rviz"
    args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/>

  <include file="$(find hector_mapping)/launch/mapping_default.launch"/>

  <include file="$(find hector_geotiff)/launch/geotiff_mapper.launch">
    <arg name="trajectory_source_frame_name" value="scanmatcher_frame"/>
    <arg name="map_file_path" value="$(arg geotiff_map_file_path)"/>
  </include>

</launch>

It is advised to go through the following two tutorials which explaining the setup of Hector Slam and the method to generate a map from the logged data.

  1. Setup
  2. Creating map

To Generate a map, follow these steps-

1.Launch the transform by the following command -

roslaunch tf tf_car.launch

2.Launch the Lidar node -

sudo chmod 777 /dev/tty*
roslaunch rplidar_ros view_rplidar.launch

3.Launch the hector slam launch file -

roslaunch hector_slam tutorial.launch

The launch file reads in a bag file which recorded all of the topics. Hector SLAM only needs the /scan topic (which contains the laser scans) in order to simultaneously map and localize. Note that no odometry data is used, whereas more advanced mapping packages such as Google Cartographer have the option to use odometry data and even IMU data.

4.Now move the robot slowly around the area to be mapped. It can be done using the manual mode. For that run the teleop_control file-

roslaunch teleop teleop_control.launch

5.Once the whole map is generated it has to be saved by running the following command -

rostopic pub syscommand std_msgs/String "savegeotiff"

By default, geotiff maps are saved to the 'hector_slam/hector_geotiff/maps' folder. If this folder is not present, the map will not be generated so manually create this directory if doing for the first time.