Can't get sonar range from Gazebo model.

asked 2018-04-20 16:56:25 -0500

John Bessire gravatar image

updated 2018-04-21 14:45:53 -0500

I am trying to use rospy to get the range from a Gazebo sonar model.

rosdistro: kinetic
rosversion: 1.12.13
gazebo version: 7.12.0

This is the rospy program to get the range.

#!/usr/bin/env python
import sys
import rospy
from sensor_msgs.msg import Range 

rospy.init_node("robot_sonar", anonymous=True)

def callback(msg):
    print "Message = ", msg.range

sub_sonar1 = rospy.Subscriber("/sonar1", Range, callback)

r = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
   print "Waiting"
  r.sleep()

This is the Gazebo model for the sonar

  <link name='link'>
    <pose frame=''>0.2 0 0.2 0 -0 0</pose>
    <gravity>0</gravity>
    <sensor name='sonar1' type='sonar'>
      <pose frame=''>0.2 0 0 0 1.5707 3</pose>
      <sonar>
        <min>0</min>
        <max>10</max>
        <radius>0.3</radius>           
      </sonar>

      <always_on>1</always_on>
      <update_rate>30</update_rate>
      <visualize>1</visualize>
      <topic>sensor_msgs/Range</topic>
    </sensor>
    <self_collide>0</self_collide>
    <inertial>
      <inertia>
        <ixx>1</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>1</iyy>
        <iyz>0</iyz>
        <izz>1</izz>
      </inertia>
      <mass>1</mass>
    </inertial>
    <kinematic>0</kinematic>
  </link>

I think the Gazebo model is not publishing the range topic correctly which I think must be set up correctly to publish the range to rospy. The Gazebo model has topic tags in the XML and below is some of the parameters I tried.

<topic>Range</topic>
<topic>sonar/Range</topic>
<topic>sensor_msgs/Range</topic>

Edit 1: Added rostopic list

/clock
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/set_link_state
/gazebo/set_model_state
/gazebo_gui/parameter_descriptions
/gazebo_gui/parameter_updates
/robot_sonar/cmd_vel
/robot_sonar/odom
/rosout
/rosout_agg
/tf
edit retag flag offensive close merge delete

Comments

Can you please provide a link to the documentation that you used to set this up? There are quite some "Gazebo sonar plugins" available, so it would be good to know which one in particular you're using.

gvdhoorn gravatar imagegvdhoorn ( 2018-04-21 00:53:26 -0500 )edit

If it is this one, that hasn't been merged yet.

But seeing the <pose frame> in there this would seem to be SDF, which would make it a Gazebo question.

Also note: Gazebo plugins do not publish to ROS topics.

gvdhoorn gravatar imagegvdhoorn ( 2018-04-21 01:00:15 -0500 )edit

I am using an Gazebo SDF plug-in which has this format link text. I have also tried a sensor similar to the link you posted. Hector plug-ins and the Hokyo laser plug-in were all tried without any success.

John Bessire gravatar imageJohn Bessire ( 2018-04-21 13:58:29 -0500 )edit

SDF plugins are Gazebo plugins. Those don't publish to ROS topics, but to Gazebo topics. Only plugins specifically made as ROS Gazebo plugins will work.

gvdhoorn gravatar imagegvdhoorn ( 2018-04-21 14:16:24 -0500 )edit

I have also tried a sensor similar to the link you posted. Hector plug-ins and the Hokyo laser plug-in were all tried without any success.

As always "without any success" is not enough to help you. What happened? What was the output of rostopic list after loading those plugins?

gvdhoorn gravatar imagegvdhoorn ( 2018-04-21 14:17:43 -0500 )edit

The post has been edited to add rostopic list.

John Bessire gravatar imageJohn Bessire ( 2018-04-21 14:46:41 -0500 )edit

As you can see, there is no sonar topic there, only the default Gazebo topics I would expect.

As I wrote above: Gazebo plugins only work in Gazebo, they do not publish to ROS. Only plugins in gazebo_ros_plugins/gazebo_ros_pkgs publish ROS msgs.

Could you please add a snippet of how you ..

gvdhoorn gravatar imagegvdhoorn ( 2018-04-22 04:10:24 -0500 )edit

.. tried to integrate the hector or hokuyo plugins? As mentioned earlier "without any success" is not something I can use to help you.

Edit: some nuance: of course, the hector plugins also publish to ROS topics.

gvdhoorn gravatar imagegvdhoorn ( 2018-04-22 04:11:49 -0500 )edit