[ROS Q&A] 124 – Range sensor does not detect obstacles in Gazebo

Range-sensor-does-not-detect-obstacles-in-Gazebo

Written by Ricardo Tellez

22/05/2018

In this video, we are answering a question about why the range sensor plugin for Gazebo is not detecting obstacles. The answer to that problem will surprise you !!! (ha, ha, ha).

In this posting, we will go through a demo of laser data visualization

NOTE: This article assumes that the audience is familiar with the following:

  • Running scripts on the terminal
  • Ros filesystem layout (what goes where launch dir, src dir etc)
  • RDS Environment (How to launch a project, how to navigate the directories.

Step – 1. Creating a new project

  • Create a new project. Choose an informative name and add some description in the description field.
  • Load the project. (This can take a few moments to a minute depending on your internet)
  • Run the IDE from the Tools menu and verify the filesystem layout it should have a similar structure

root
├── ai_ws
├── catkin_ws
│ ├── build
│ ├── devel
│ └── src
├── notebook_ws
│ ├── default.ipynb
│ └── images
└── simulation_ws
├── build
├── devel
└── src

Step – 2. Cloning the existing source

root
├── ai_ws
├── catkin_ws
│ ├── build
│ ├── devel
│ └── src
│ ├── CMakeLists.txt
│ └── fakeLaserScan
│ ├── CMakeLists.txt
│ ├── launch
│ │ └── fakeLaserScan.launch
│ ├── package.xml
│ ├── README.md
│ └── src
│ ├── fakeLaserScan.cpp
│ ├── listener.cpp
│ └── talker.cpp
├── notebook_ws
│ ├── default.ipynb
│ └── images
└── simulation_ws
├── build
├── devel
└── src

Step – 3. Briefly skim through the code and run it

  • First, we go through the contents of package.xml (located inside the fakeLaserScan directory) which has the following content
    (NOTE comments are removed in this reproduced code snippet for brevity)
<?xml version="1.0"?>
<package>
  <name>beginner_tutorials</name>
  <version>0.0.0</version>
  <description>The beginner_tutorials package</description>

  <maintainer email="user@todo.todo">user</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend> 
  <build_depend>rospy</build_depend> 
  <build_depend>sensor_msgs</build_depend> 
  <build_depend>std_msgs</build_depend> 
  <build_export_depend>roscpp</build_export_depend> 
  <build_export_depend>rospy</build_export_depend> 
  <build_export_depend>sensor_msgs</build_export_depend> 
  <build_export_depend>std_msgs</build_export_depend> 
  <exec_depend>roscpp</exec_depend> 
  <exec_depend>rospy</exec_depend> 
  <exec_depend>sensor_msgs</exec_depend> 
  <exec_depend>std_msgs</exec_depend>

  <export>
  </export>
</package>

 

This file contains various pieces of information about the project such as the package dependencies (roscpprospysensor_msgsstd_msgs) project nameversionlicensemaintainer etc. Some of this information is vital for building the project (like the dependencies). While other information is important from the perspective of sharing one’s work with the community.

In the given contents of the package.xml file, we notice that the project name specified in the file (beginner_tutorials) is different from the directory name (fakeLaserScanner). While this will not cause the project to crash but it is inconsistent with the project naming guideline.

Next, we take a look at the code inside fakeLaserScan.cpp

 

  • This code creates a publisher with the name fakeScan
  • The scan values are being generated inside a for loop (line 15-18 (excluding the blank lines))
  • These scan values are then copied to a LaserScan message (line 20, 32-35)
  • The message is being published at line 36. Also, note that the publish rate is 1 Hz (line 12)

As all seems okay we will go ahead and build the project. On the console browse to the catkin_ws directory and then run

$ catkin_make

This should proceed without any errors.

Next, we launch the project with the following command

$ roslaunch beginner_project fakeLaserScan.launch

This also should proceed without any errors.

Now we will open another console from the Tools menu and verify the topics with following commands

$ rostopic list

Outputs :

/fakeScan
/rosout
/rosout_agg

In the result, we see out topic /fakeScan appears. Further, we can check if the topic is publishing the correct information or not with the following command

$ rostopic info /fakeScan

Outputs

Type: sensor_msgs/LaserScan

Publishers:
* /fakeLaserScan (http://10.8.0.1:42942/)

Subscribers: None

Thus we verified that the topic is indeed publishing a scan message. Lets load rviz to visualize the data.

$ rosrun rviz rviz

First, we will add a laser component to the displays panel as shown here

Click on the ADD button on the bottom left

From the menu that has just appeared, select the laser component (as shown)

  • Once the laser component appears we can select the topic by clicking on the field (as shown)

Now we see that there is an error with the frame field.

To solve that error we will modify the Fixed Frame field in the Global Option component by writing fake_lasaer_frame in the field (as shown)

Also, we need to modify the size setting of the laser component to see the laser scan

  • Finally, we have the scan showing up in the visualization panel.

What we did is essentially telling rviz to use the laser_frame for the global fixed frame as well.

This can be done by remapping with the following line of command

$ rosrun tf static_transform_publisher 0 0 0 0 0 0 1 map fake_laser_frame 10

 

// RELATED LINKS:

* ROS Answers original question: https://answers.ros.org/question/291726/range-sensor-does-not-detect-objects-in-gazebo/

* Robot Ignite Academy: https://goo.gl/vPiuiC

* ROS Development Studio: https://goo.gl/fGnMuv

Topics:
Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This