Robotics StackExchange | Archived questions

Rviz map position issue

I mapped the willow garage office using Gmapping and saved the map using the map_server node. My launch file has the following fragment to load the saved map:

<!-- Map Server -->
    <arg name='map' value='$(find my_bot)/maps/willow_garage_map.yaml'/>
    <node name="map_server" pkg="map_server" type="map_server" output="screen" args='$(arg map)'/>

But I get the strangest results in rviz. The map and the robot are located quite a distance away from each other.

image description

My robot with lidar detecting "invisible walls"

image description

My robot and map seem to want a divorce

I would appreciate some help to understand what I've done wrong and how I can unite robot and map so I can carry out some path planning and navigation.

UPDATE #1 :

Contents of willowgaragemap.yml :

image: willow_garage_map.pgm
resolution: 0.050000
origin: [-100.000000, -100.000000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

I also discovered the Map display of Rviz has an configured with the /map topic geneates an error. I confirmed the map topic exists and also has data published into it.

image description

UPDATE #2 :

image description

rosrun tf tf_echo map odom

Failure at 157.725000000
Exception thrown:"map" passed to lookupTransform argument target_frame does not exist. 
The current list of frames is:
Frame hokuyo_link exists with parent chasis.
Frame chasis exists with parent odom.
Frame left_camera exists with parent chasis.
Frame overwatch_camara exists with parent chasis.
Frame right_camera exists with parent chasis.

Failure at 157.725000000
Exception thrown:"map" passed to lookupTransform argument target_frame does not exist. 
The current list of frames is:
Frame hokuyo_link exists with parent chasis.
Frame chasis exists with parent odom.
Frame left_camera exists with parent chasis.
Frame overwatch_camara exists with parent chasis.
Frame right_camera exists with parent chasis.

Failure at 158.725000000
Exception thrown:"map" passed to lookupTransform argument target_frame does not exist. 
The current list of frames is:
Frame hokuyo_link exists with parent chasis.
Frame chasis exists with parent odom.
Frame left_camera exists with parent chasis.
Frame overwatch_camara exists with parent chasis.
Frame right_camera exists with parent chasis.
Frame wheel_left_aft exists with parent chasis.
Frame wheel_left_fore exists with parent chasis.
Frame wheel_right_aft exists with parent chasis.
Frame wheel_right_fore exists with parent chasis.

And . . . (my base_link is called chasis)

rosrun tf tf_echo odom chasis

At time 298.426
- Translation: [0.001, -0.019, 0.350]
- Rotation: in Quaternion [0.000, 0.000, -0.033, 0.999]
            in RPY (radian) [0.000, 0.000, -0.066]
            in RPY (degree) [0.000, 0.000, -3.776]
At time 298.426
- Translation: [0.001, -0.019, 0.350]
- Rotation: in Quaternion [0.000, 0.000, -0.033, 0.999]
            in RPY (radian) [0.000, 0.000, -0.066]
            in RPY (degree) [0.000, 0.000, -3.776]
At time 299.426
- Translation: [0.001, -0.019, 0.350]
- Rotation: in Quaternion [0.000, -0.000, -0.033, 0.999]
            in RPY (radian) [0.000, -0.000, -0.066]
            in RPY (degree) [0.000, -0.000, -3.789]
At time 300.426
- Translation: [0.001, -0.019, 0.350]
- Rotation: in Quaternion [-0.000, 0.000, -0.033, 0.999]
            in RPY (radian) [-0.000, 0.000, -0.066]
            in RPY (degree) [-0.000, 0.000, -3.802]
At time 301.426
- Translation: [0.001, -0.019, 0.350]
- Rotation: in Quaternion [-0.000, 0.000, -0.033, 0.999]
            in RPY (radian) [-0.000, 0.000, -0.067]
            in RPY (degree) [-0.000, 0.000, -3.814]
At time 302.426
- Translation: [0.001, -0.019, 0.350]
- Rotation: in Quaternion [-0.000, 0.000, -0.033, 0.999]
            in RPY (radian) [-0.000, 0.000, -0.067]
            in RPY (degree) [-0.000, 0.000, -3.827]

UPDATE #3 :

<?xml version="1.0"?>
<launch>
    <!-- PARAMETERS -->
    <param name="robot_description" command="$(find xacro)/xacro $(find my_bot)/urdf/cleaner.xacro"/>

    <!-- RVIZ -->
    <node name='robot_state_publisher' pkg='robot_state_publisher' type='robot_state_publisher'/>
    <node name='joint_state_publisher_gui' pkg='joint_state_publisher_gui' type='joint_state_publisher_gui'/>
    <node name='rviz' pkg='rviz' type='rviz'/>

    <!-- GAZEBO -->
    <include file='$(find gazebo_ros)/launch/willowgarage_world.launch'/>
    <node name='my_bot' pkg='gazebo_ros' type='spawn_model' args='-urdf -model sweeper -param robot_description'/>

    <!--- Run AMCL --> 
    <include file="$(find amcl)/examples/amcl_omni.launch" />

    <!-- Map Server -->
    <arg name='map' value='$(find my_bot)/maps/willow_garage_map.yaml'/>
    <node name="map_server" pkg="map_server" type="map_server" output="screen" args='$(arg map)'/>

</launch>

Asked by sisko on 2021-02-04 06:25:05 UTC

Comments

what is the content of willow_garage_map.yaml ?
Specifically, what is the value for the field origin in that file?
Also, could your run rostopic echo /map_metadata and post the output?
And what is the initial pose of your robot in gazebo? Is it at x=0, y=0 or somewhere else?

Asked by Roberto Z. on 2021-02-04 09:07:22 UTC

Try using the set_pose button at the top of the RVIZ GUI to give your robot an initial location. You have to realize that your robot doesn't magically know things about its position in the world, you must be very deliberate to tell it those things

Asked by JackB on 2021-02-04 18:04:54 UTC

@Roberto: Thanks for your input. I updated my question with more data including the contents of willow_garage_map.yaml. I confirmed /map and /map_metadata have content. map_metadata below:

rostopic echo /map_metadata 
map_load_time: 
  secs: 0
  nsecs:   6000000
resolution: 0.0500000007451
width: 4000
height: 4000
origin: 
  position: 
    x: -100.0
    y: -100.0
    z: 0.0
  orientation: 
    x: 0.0
    y: 0.0
    z: 0.0
    w: 1.0

I did alter the position values of x & y to zero but when I launched rviz my model still was not in the map.

Asked by sisko on 2021-02-04 19:55:43 UTC

@JackB: Thanks for your input. Are you refering to the 2D pose estimate button? I tried that but I got no particle filters. That might be a different issue to tacle.

Asked by sisko on 2021-02-04 19:58:09 UTC

From the data I can see that your map origin appears to be ok! [-100,-100,0]
Maybe it is an offset caused by your TF's, how does your TF tree structure looks like?
What are the numerical values of the transformation from map to odom, and from odom to base_link?
rosrun tf tf_echo map odom
rosrun tf tf_echo odom base_link

Asked by Roberto Z. on 2021-02-05 03:47:05 UTC

@Roberto: I aded the TF tree and the other requested data to the update#2 section of my question

Asked by sisko on 2021-02-05 07:17:46 UTC

You don't have the tf between map and odom, what are you using for the localization of the robot ? The node map_server doesn't localize the robot in the map, you need AMCL for example.

Asked by Delb on 2021-02-05 07:40:05 UTC

Yes agree,I think Rviz is missing the transform between map and odom. You need to broadcast a transform between map and odom.

As a quick fix try this:
rosrun tf static_transform_publisher 0 0 0 0 0 0 map odom 100

or add a static transform to your launch file:
<node pkg="tf2_ros" type="static_transform_publisher" name="odom_wrt_map_tf" args="0 0 0 0 0 0 map odom" />

Also it is necessary to correctly configure Rviz's Global Options. What is value for the field Fixed Frame under “Global Options."?

It should be set to map

Asked by Roberto Z. on 2021-02-05 08:36:09 UTC

@sisko the reason that the 2D pose estimate button didn't work is because you aren't running a localization strategy. Run AMCL to do what you want.

Asked by JackB on 2021-02-05 08:40:44 UTC

Thank you all for your responses. I added my launch file to update#3 which includes an AMCL node. I expected that amcl node to help with my localization needs and to provide particle filters when I use the "2D pose estimate" button.

Asked by sisko on 2021-02-05 19:44:14 UTC

@Roberto: You and @Delb were absolutely right. Adding a static_state_publisher repositioned my model precisely where it needed to be. BUT in answer to Delbs' question, I was using an AMCL node in my launch file for localization but something clearly wasn't working. First hint it was going to give me trouble was when the Rviz particle filters didn't showup. I added my launch file to my question.

Asked by sisko on 2021-02-05 19:59:10 UTC

You should add the whole amcl launch file instead of the include. But it seems that you are not setting the parameter of amcl base_frame_id which is base_link by default, according to your tf tree you don't have a frame base_link so it might be the reason of your issue. Check the amcl wiki for the list of the parameters to verify you have them set propperly.

Asked by Delb on 2021-02-08 03:40:12 UTC

I'm glad you got it working!

Asked by Roberto Z. on 2021-02-10 12:36:19 UTC

Answers