Ask Your Question
1

How to map with hector_mapping and just a Lidar

asked 2018-10-09 23:29:49 -0600

IvyKK gravatar image

updated 2018-10-10 21:33:50 -0600

Hi, I just got a lidar (ydlidar x4), and would like to use it to map (just holding the lidar and raspberry pi myself and walk around the room without odometry)..I'm very new to ROS. I have read quite a lot posts...but still could fix the errors..

The lidar is connected to raspberry pi 3, and the scanning data is successfully shown in rviz. But as I tried with hector _slam, I got an error:

[ INFO] [1539142958.281154496]: lookupTransform base_link to laser_frame timed out. Could not transform laser scan into base_frame.
[ WARN] [1539142958.855603123]: No transform between frames /map and /base_link available after 20.009138 seconds of waiting. This warning only prints once.

To start with hector_slam, I roslaunch the all_node.launch file (from another tutorial) below:

<launch>

  <include file="$(find ydlidar)/launch/lidar.launch" />
  <node pkg="tf" type="static_transform_publisher" name="map_to_odom" 
    args="0.0 0.0 0.0 0 0 0.0 /odom /base_link 40" />
  <node pkg="tf" type="static_transform_publisher" name="base_frame_laser" 
    args="0.0 0.0 0.0 0 0 0.0 /base_link /laser_frame 40" />
  <include file="$(find hector_mapping)/launch/mapping_default.launch" />
  <node pkg="rviz" type="rviz" name="rviz" args="-d $(find ydlidar)/launch/lidar.rviz" />
  <include file="$(find hector_geotiff)/launch/geotiff_mapper.launch" />

</launch>

While for the mapping default.launch:

<?xml version="1.0"?>

<launch>
  <arg name="tf_map_scanmatch_transform_frame_name" default="scanmatcher_frame"/>
  <arg name="base_frame" default="base_link"/>
  <arg name="odom_frame" default="base_link"/>
  <arg name="pub_map_odom_transform" default="true"/>
  <arg name="scan_subscriber_queue_size" default="5"/>
  <arg name="scan_topic" default="scan"/>
  <arg name="map_size" default="2048"/>

  <node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">

    <!-- Frame names -->
    <param name="map_frame" value="map" />
    <param name="base_frame" value="$(arg base_frame)" />
    <param name="odom_frame" value="$(arg odom_frame)" />

    <!-- Tf use -->
    <param name="use_tf_scan_transformation" value="true"/>
    <param name="use_tf_pose_start_estimate" value="false"/>
    <param name="pub_map_odom_transform" value="$(arg pub_map_odom_transform)"/>

    <!-- Map size / start point -->
    <param name="map_resolution" value="0.050"/>
    <param name="map_size" value="$(arg map_size)"/>
    <param name="map_start_x" value="0.5"/>
    <param name="map_start_y" value="0.5" />
    <param name="map_multi_res_levels" value="2" />

    <!-- Map update parameters -->
    <param name="update_factor_free" value="0.4"/>
    <param name="update_factor_occupied" value="0.7" />    
    <param name="map_update_distance_thresh" value="0.2"/>
    <param name="map_update_angle_thresh" value="0.9" />
    <param name="laser_z_min_value" value = "-1.0" />
    <param name="laser_z_max_value" value = "1.0" />

    <!-- Advertising config --> 
    <param name="advertise_map_service" value="true"/>

    <param name="scan_subscriber_queue_size" value="$(arg scan_subscriber_queue_size)"/>
    <param name="scan_topic" value="$(arg scan_topic)"/>
     <!-- Debug parameters -->
    <!--
      <param name="output_timing" value="false"/>
      <param name="pub_drawings" value="true"/>
      <param name="pub_debug_output" value="true"/>
    -->
    <param name="tf_map_scanmatch_transform_frame_name" value="$(arg tf_map_scanmatch_transform_frame_name)" />
      </node>
    </launch>

For your information, here's my tf tree:

image description

Please, anyone knows how to solve this?

=========================================================

After changing the all_nodes.launch file:

 <launch>

  <include file="$(find ydlidar)/launch/lidar.launch" />
  <node pkg="tf" type="static_transform_publisher" name="map_to_odom" 
    args="0.0 0.0 0.0 0 0 0.0 /odom /map 40" />
  <node pkg="tf" type="static_transform_publisher" name="odom_to_baselink" 
        args="0.0 0.0 0.0 0 0 0.0 /odom /base_link 40" />
  <node pkg="tf" type="static_transform_publisher" name="base_frame_laser" 
args="0.0 0.0 ...
(more)
edit retag flag offensive close merge delete

Comments

@IvyKK: in the future: could you please attach images directly to your posts? That way the question is not dependent on the existence of some off-site file (or file hosting company).

I've give you enough karma to do that yourself, but I've already done it here.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-10 02:11:24 -0600 )edit

@gvdhoorn: Thank you so much!! Yes, I tried to upload the pic, but found that I didn't have enough karma. Thanks for offering!

IvyKK gravatar image IvyKK  ( 2018-10-10 02:47:40 -0600 )edit

hi can you plz help me build the same projekt

kal gravatar image kal  ( 2019-04-10 09:34:24 -0600 )edit

1 Answer

Sort by » oldest newest most voted
3

answered 2018-10-10 01:49:56 -0600

Delb gravatar image

updated 2018-10-10 05:26:20 -0600

Directly looking at your tf tree you can say that something is wrong : you should have all your frames connected with each other. The most surprising thing is the frame base_footprint not connected with anything, yet you didn't defined it.

The issue is inside <include file="$(find ydlidar)/launch/lidar.launch" /> if you look at the content of lidar.launch here there is this node launched too :

 <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser4"
args="0.2245 0.0 0.2 0.0 0.0  0.0 /base_footprint /laser_frame 40" />

This node does the work for you to set the static transform base_footprint -> laser_frame but then you redifine a new parent to laser_frame :

<node pkg="tf" type="static_transform_publisher" name="base_frame_laser" 
    args="0.0 0.0 0.0 0 0 0.0 /base_link /laser_frame 40" />

You have two options here :

  • Instead of including the lidar.launch only copy/paste the ydlidar node and params part to put it in your launch file (ie removing the static_transform_publisher node)
  • Instead of creating a static transform base_link -> laser_frame change it to base_link -> base_footprint.

EDIT:

You have inverted the frames, map is the parent of odom. Your launch file should be :

 <launch>

    <node name="ydlidar_node"  pkg="ydlidar"  type="ydlidar_node" output="screen">
      <param name="port"         type="string" value="/dev/ydlidar"/>  
      <param name="baudrate"     type="int"    value="115200"/>
      <param name="frame_id"     type="string" value="laser_frame"/>
      <param name="angle_fixed"  type="bool"   value="true"/>
      <param name="low_exposure"  type="bool"   value="false"/>
      <param name="heartbeat"    type="bool"   value="false"/>
      <param name="resolution_fixed"    type="bool"   value="true"/>
      <param name="angle_min"    type="double" value="-180" />
      <param name="angle_max"    type="double" value="180" />
      <param name="range_min"    type="double" value="0.08" />
      <param name="range_max"    type="double" value="16.0" />
      <param name="ignore_array" type="string" value="" />
      <param name="samp_rate"    type="int"    value="9"/>
      <param name="frequency"    type="double" value="7"/>
  </node>
  <node pkg="tf" type="static_transform_publisher" name="map_to_odom" 
    args="0.0 0.0 0.0 0 0 0.0 /map /odom 40" />
  <node pkg="tf" type="static_transform_publisher" name="odom_to_basefootprint" 
        args="0.0 0.0 0.0 0 0 0.0 /odom /base_footprint 40" />
  <node pkg="tf" type="static_transform_publisher" name="base_footprint_to_base_link" 
        args="0.0 0.0 0.0 0 0 0.0 /base_footprint /base_link 40" />
 <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser" 
        args="0.2245 0.0 0.2 0.0 0.0 0.0 /base_link /laser_frame 40" />
  <include file="$(find hector_mapping)/launch/mapping_default.launch" />
  <node pkg="rviz" type="rviz" name="rviz" args="-d $(find ydlidar)/launch/lidar.rviz" />
  <include file="$(find hector_geotiff)/launch/geotiff_mapper.launch" />

</launch>

I've removed the <include file="$(find ydlidar)/launch/lidar.launch" /> because you hsould have map -> odom -> base_footprint -> base_link -> laser_frame instead of map -> odom -> base_link -> base_footprint -> laser_frame.

edit flag offensive delete link more

Comments

Hi Delb I have tried out the 2nd approach but I still got an error: [ WARN] [1539155871.583634796]: No transform between frames /map and /base_link available after 20.005473 seconds of waiting.

IvyKK gravatar image IvyKK  ( 2018-10-10 02:55:58 -0600 )edit

so I tried to insert: <node pkg="tf" type="static_transform_publisher" name="map_to_odom" args="0.0 0.0 0.0 0 0 0.0 /odom /map 40"/> This time all frames are connected, no error, but it only shows the scanning data, not the map, could you advise what the problem is? (tf tree placed in question)

IvyKK gravatar image IvyKK  ( 2018-10-10 03:00:10 -0600 )edit

Delb, Thank you! There is no more error showing now, however the map is still not showing... The tf tree now has map connected to -> odom->base_footprint->base_link->laser_frame and also map->scanmatcher_frame...(I also put the summary in the terminal if you would like to have a look)

IvyKK gravatar image IvyKK  ( 2018-10-10 21:28:12 -0600 )edit

I tried to put in <node pkg="rviz" type="rviz" name="rviz" args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/> it looks like it lacks the mapping rviz, and it shows the mapping data too. gonna need some time to play around with that. Thanks!

IvyKK gravatar image IvyKK  ( 2018-10-10 22:19:30 -0600 )edit

It's normal to have another branch in the tf tree only with the scan_matcher, and if you don't see everything in rviz it's because the rviz configuration isn't correctly done (not by you but the default file).

Delb gravatar image Delb  ( 2018-10-11 01:22:02 -0600 )edit
1

Click on "Add" in the Displays panel and go to the tab "By topic" you'll see all the availables topics and you should be able to add the map. You can also directly check the OccupancyGrid values with rostopic echo to see if there aren't only -1.

Delb gravatar image Delb  ( 2018-10-11 01:23:26 -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

2 followers

Stats

Asked: 2018-10-09 23:29:49 -0600

Seen: 2,242 times

Last updated: Oct 10 '18