ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
1

Who publishes the map frame?

asked 2020-05-18 02:15:17 -0600

pravardhan gravatar image

ROS Melodic, Ubuntu18, Gazebo9

Issue: Not able to visualize laser scan data in rviz

Error: No tf data. Actual error: Fixed Frame [map] does not exist

Steps to recreate:

  1. Launch gazebo with ros
    roslaunch gazebo_ros empty_world.launch
  2. Insert Hokuyo laser sensor. Go to the insert tab in gazebo and add the hokuyo model to the world. Also add a few blocks near the sensor (for visualization).
  3. Open rviz
    rviz

Rviz gives the error as mentioned above. I have done rostopic list and saw that there was /laser/scan topic, but there was no /tf topic. I added the LaserScan visualisation to rviz.

I did rostopic echo on /laser/scan and the data was actually being published properly. I am not doing slam or anything, I just want to visualize the scan data in rviz.

Who publishes this map frame? Should I be publishing this? If so, how should I?

edit retag flag offensive close merge delete

Comments

Rviz is a ROS tool and Gazebo does not require ROS to run and does not natively publish ros topics and ros TF's. So you need an interface for using ROS with Gazebo. Following just the steps mentioned above does not provide a rostopic. Running roscore and then rviz just provides these ros topics: /clicked_point /initialpose /move_base_simple/goal /rosout /rosout_agg /tf /tf_static But if you do have a rostopic showing up a laser msg, as you mention, you should also have an URDF model with a plugin definition on it? Could you confirm?

Roberto Z. gravatar image Roberto Z.  ( 2020-05-18 03:08:08 -0600 )edit

The included hokuyo model does use a laser plugin.

<plugin name="laser" filename="libRayPlugin.so" />
    <plugin name="gazebo_ros_head_rplidar_controller" filename="libgazebo_ros_laser.so">
        <topicName>laser/scan</topicName>
        <frameName>map</frameName>
 </plugin>

This is in the sdf of the hokuyo laser. As u can see the frameName is set to map but there is no tf topic being published. You are right that gazebo doesn't require ros to run, but see that I am not opening gazebo from my app drawer, I am opening it with the launch file which will bind gazebo to ros.

pravardhan gravatar image pravardhan  ( 2020-05-18 04:16:42 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-05-19 09:19:31 -0600

Roberto Z. gravatar image

updated 2020-05-19 09:33:05 -0600

In order to spawn a laser sensor in Gazebo and visualize the laser scan in Rviz there are some steps missing. For instance:

You need an URDF file, this is a minimal example (lets call it laser_sensor.urdf):

<?xml version="1.0"?>

<robot name="cube_laser">

  <link name="base_link">
    <visual>
      <geometry>
        <box size="0.2 0.2 0.2"/>
      </geometry>
    </visual>
    <collision>
      <geometry>
        <box size="0.2 0.2 0.2"/>
      </geometry>
    </collision>
  </link>

  <!-- a cube to use as laser sensor geometry -->
  <link name="hokuyo_link">
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 0.1"/>
      </geometry>
    </collision>
    <visual>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
        <box size="0.1 0.1 0.1"/>
      </geometry>
    </visual>
    <inertial>
      <mass value="1e-5" />
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
    </inertial>
  </link>

  <joint name="hokuyo_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="0 0 0.15" rpy="0 0 0"/>
    <parent link="base_link"/>
    <child link="hokuyo_link"/>
  </joint>

    <!-- placeholder for laser sensor plugin-->

    </robot>

You have to add the following Gazebo tag with a plugin that interacts with ROS (put it where the placeholder is):

  <!-- this is a laser sensor-->
  <gazebo reference="hokuyo_link">
      <sensor type="ray" name="laser">
      <pose>0 0 0 0 0 0</pose>
      <visualize>false</visualize>
      <update_rate>40</update_rate>
      <ray>
        <scan>
          <horizontal>
            <samples>720</samples>
            <resolution>1</resolution>
            <min_angle>-1.570796</min_angle>
            <max_angle>1.570796</max_angle>
          </horizontal>
        </scan>
        <range>
          <min>0.10</min>
          <max>30.0</max>
          <resolution>0.01</resolution>
        </range>
      </ray>
      <plugin name="gazebo_ros_laser" filename="libgazebo_ros_laser.so">
        <topicName>laser/scan</topicName>
        <frameName>hokuyo_link</frameName>
      </plugin>
    </sensor>
  </gazebo>

<frameName> must match the name of one link in the URDF file.

Fire up Gazebo:
$ roslaunch gazebo_ros empty_world.launch

Then cd to where you saved your URDF file.
Next spawn the URDF model to Gazebo:

$ rosrun gazebo_ros spawn_model -file laser_sensor.urdf -urdf -z 0.5 -model laser_sensor

Load the robot model to parameter server:
$ rosparam set robot_description --textfile laser_sensor.urdf

To broadcast the robot model (from the URDF description) to the tf transform library run:
$ rosrun joint_state_publisher joint_state_publisher
$ rosrun robot_state_publisher robot_state_publisher

To verify that everything in running:
$ rostopic list
$ rostopic echo tf_static

Then open Rviz.
Select the drop_down for fixed frame and type in "base_link".
Finally add a LaserScan visualization and set the correct topic.

I can recommend starting with these tutorials:

Building a Visual Robot Model with URDF from Scratch
http://wiki.ros.org/urdf/Tutorials/Bu...

Tutorial: Using Gazebo plugins with ROS
http://gazebosim.org/tutorials?tut=ro...

edit flag offensive delete link more

Comments

Thank You! This worked. I understand that the key here was the *_state_publisher nodes. rostopic info showed that the tf topic was indeed published by the state publisher. The only question I have is, this seems like a whole lot of work just to visualize the LaserScan I know I can put all this in a launch file and just use that single file. Anyways, the hokuyo model provided by gazebo is an sdf model, is there any way I can do this with an sdf file? Thanks for ur answer again.

pravardhan gravatar image pravardhan  ( 2020-05-19 20:41:09 -0600 )edit

I am glad that this resolved your question. You are right that the best is to add all commands into one launch file and execute that, and all that should be into one package. You cannot do the same using only a SDF file, you require an URDF file. Having the URDF is central to what robot_state_publisher does. Also you require an ROS-aware plugin, as Gazebo topics are not the same as ROS topics. For instance to get a list of all Gazebo topics use: $ gz topic -l To list all ROS topics use: $ rostopic list

Roberto Z. gravatar image Roberto Z.  ( 2020-05-20 08:58:46 -0600 )edit
0

answered 2020-05-18 03:43:41 -0600

mgruhler gravatar image

If you just want to visualize the data (not localized in a map), set the fixed_frame in rviz to the frame in which the laser scanner is published (or one that is available in the tf tree).

If you want it localized, you obviously need a localization node that should provide the map frame.

edit flag offensive delete link more

Comments

There are no tf frames at all. As u can see in the above comment that the frame is set to map in the plugin, but there are no frames being published, so i cant set fixed_frame to map

pravardhan gravatar image pravardhan  ( 2020-05-18 04:19:28 -0600 )edit

A sensor doesn't broadcast a transform. That is usually done from a URDF/SDF file.

You can use rviz to visualize data in the frame in which the data is published without the need for any transformations. You need to set the fixed_frame to whatever is in you /laser/scan topics header/frame_id section.

You are saying you can echo the topic. Do so, check the frame_id and set the fixed_frame in rviz to that.

Other than that, I second @Roberto Z. that there is no such topic "by default". So maybe you launch something else?

mgruhler gravatar image mgruhler  ( 2020-05-18 06:49:33 -0600 )edit

The frame_id in the /laser/scan topic is indeed set to map. But in rviz the dropdown menu for Fixed Frame is empty. Even typed it in manually, still nothing. I please request u to follow the steps to recreate the error mentioned in the post, I think that will give u an idea of what's happening. On a side note, u mentioned that a transform is usually broadcasted from a URDF/SDF file, how can I do that? Can u point me to some resources?

pravardhan gravatar image pravardhan  ( 2020-05-18 07:10:06 -0600 )edit

@pravardhan I followed the steps you provide (though on kinetic, I don't have a melodic machine at the moment) and there is no laser scan topic whatsoever... You'll always have that error/warning about not having the respective frames as long as you don't have a tf broadcaster (I'll just link to this tutorial for tf and leave it at that).

What I cannot reproduce, however, is that I canot display the scan in rviz, even though there is no transform broadcasted. This works perfectly on my machine (and has done for quite a few years)

You need to make sure to properly configure the scan display though, as the points are, by default pretty small. For a first try set size to something like 0.05, ColorTransformer to FlatColor and choose a suitable Color for your background. Bright red works okay most of the time...

mgruhler gravatar image mgruhler  ( 2020-05-18 07:31:06 -0600 )edit

And yes, the fixed_frame dropdown is empty, when there is no tf broadcasted. You need to type it in manually. (use map and not something like /map...)

mgruhler gravatar image mgruhler  ( 2020-05-18 07:32:02 -0600 )edit

@mgruhler Sorry but I think you misunderstood my issue, It's not that I can't "SEE" the scan properly, so changing the size and the rest won't work. Also, if u are not seeing the /laser/scan topic then there is some issue on your side. Are you able to spawn the hokuyo sensor and see the lasers coming out of it? If not, then u might be using the GPU laser plugin instead of the CPU version, do that and u will see a /laser/scan topic using rostopic list. One last thing, if the dropdown doesn't show map, then I don't think entering it manually will work. Pls correct me if I am wrong.

pravardhan gravatar image pravardhan  ( 2020-05-19 20:51:51 -0600 )edit

Well, I followed your Steps to recreate, now on a brand new melodic machine, and still cannot see the laser scan topic. Hokyuo is obviously spawned and the rays are visualized in gazebo... But in the model there is no plugin related to ROS, only Gazebo... Maybe it really is me...

If the dropdown in rviz doesn't show a frame simply means that there is no tf broadcasted. This still let's you manually type in the exact frame that is in the topic header and lets you visualize it. Though only topics with THAT frame in the heder.

As seeing the other answer resolved your issue (which by the way then spawns a ROS laser plugin), I'll consider this fixed...

mgruhler gravatar image mgruhler  ( 2020-05-20 01:18:11 -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: 2020-05-18 02:15:17 -0600

Seen: 796 times

Last updated: May 19 '20