Skip to main content

Gazebo Troubleshooting

· 3 min read
Wei Bingchuan
PhD Student

Some common bugs for gazebo.

Despite the popularity of many new simulators such as coppeliasim, Issac Gym, etc, Gazebo is still widely used due to its ROS-friendly features.

However, since the release of Gazeb Ign, the support for Gazebo Classic is terminated. Since Gazebo Ign is not mature now and has few using examples to be learned from, this blog mainly aims at Gazebo Classic.

Startup

When you start gazebo from ROS launch, you may find gazebo is not started or not started properly. As far as I know, this may be caused by the following problem:

  1. No source

    Though there is no instruction for sourcing gazebo, I suggest sourcing setup.sh for gazebo:

    source /usr/share/gazebo/setup.sh
  2. A background gazebo process is running:

    htop # sudo apt install htop

    Check whether there is a process named gzserver of gzclient. If true, shut down them, using F9 + 9

  3. gzserver and gzclient not properly setup

    Gazboe comprises of gzserver(The background process to do simulation) and the gzclient(The GUI you see on your screen). Some launch file will directly launch gazebo using one launch action, but I strongly recommend setup gzserver and gzclient seperately, and set the headless parameter to be dynamically configured. One example is:

    start_gazebo_server_cmd = ExecuteProcess(
    condition=IfCondition(use_simulator),
    cmd=['gzserver', '-s', 'libgazebo_ros_init.so',
    '-s', 'libgazebo_ros_factory.so', world],
    output='screen')

    start_gazebo_client_cmd = ExecuteProcess(
    condition=IfCondition(PythonExpression(
    [use_simulator, ' and not ', headless])),
    cmd=['gzclient'],
    output='screen')
  4. Port error

    Sometimes you will see an error about port such as Fast_RTPS, this is because your another process is using this port or you set the weired network proxy. I suggest restart your computer and turn down your proxy and try again.

Simultaion

  1. No model loaded

    Check your log carefully, typically this bug is caused by wrong urdf model or wrong spawn service call. Gazbo11 uses the following way to call spawn_entity service:

    spawn_entity_cmd = Node(package='gazebo_ros', executable='spawn_entity.py',
    namespace=namespace,
    arguments=[
    "-topic", namespace + "/robot_description",
    '-entity', robot['name'],
    '-robot_namespace', robot['name'], #launch.substitutions.LaunchConfiguration('robot_name'),
    '-x', str(robot['x_pos']),
    '-y', str(robot['y_pos']),
    '-z', str(robot['z_pos']),
    ],
    parameters=[{'use_sim_time': use_sim_time}],
    output='screen')
  2. Packages with xxxStamped message doesn't work

    This is typically caused by the clock. When you use a simulator(Not Only Gazebo!), you shoud set use_sim_time to True for All Your Nodes!!!:

    Your_node = Node(package='xxx', executable='xxx',
    namespace=namespace,
    arguments=[
    xxx
    ],
    parameters=[{'use_sim_time': use_sim_time}],
    output='screen')

    When you enable use_sim_time, you must be sure there is actually a clock signal on the topic /Clock:

    ros2 topic echo /Clock

    For Gazebo, you can insert a plugin to publish its clock to this topic:

    bridge = Node(
    package='ros_gz_bridge',
    executable='parameter_bridge',
    arguments=[
    '/clock@rosgraph_msgs/msg/Clock@gz.msgs.Clock', # Works fine
    ],
    output='screen'
    )
  3. Some services lost or not found

    This is mainly caused by plugin not installed or not enabled. There are serveral places for plugin use:

    • Sensor plugin in model urdf
          <gazebo reference="$(arg namespace)/imu_link">
      <sensor name="imu_sensor" type="imu">
      <plugin filename="libgazebo_ros_imu_sensor.so" name="imu_plugin">
      <ros>
      <namespace>$(arg namespace)/imu</namespace>
      <remapping>~/out:=$(arg namespace)/imu</remapping>
      </ros>
      <initial_orientation_as_reference>false</initial_orientation_as_reference>
      <frame_name>$(arg namespace)/imu_link</frame_name>
      </plugin>
      xxx
      </imu>
      </sensor>
      </gazebo>
    • Model plugin in model urdf
    <gazebo>
    <plugin name="turtlebot3_diff_drive" filename="libgazebo_ros_diff_drive.so">
    xxx
    </plugin>

    <plugin name="turtlebot3_joint_state" filename="libgazebo_ros_joint_state_publisher.so">
    xxx
    </plugin>
    </gazebo>
    • World plugin in .sdf file
    <plugin name="gazebo_ros_state" filename="libgazebo_ros_state.so">
    <ros>
    <namespace>/gazebo</namespace>
    </ros>

    <update_rate>10.0</update_rate>
    </plugin>

    This world plugin provides services such as getEntityState

Conclusion

Troubleshooting for gazebo is a hot topic Robotcis.stackexchange. I strongly suggest the deprecation for gazebo and use more elegant simulator.