Note: For ROS Fuerte.
(!) Please ask about problems and questions regarding this tutorial on answers.gazebosim.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Gazebo Plugin Intro

Description: A basic tutorial that shows users how to create a gazebo plugin.

Tutorial Level: BEGINNER

Users are highly discouraged from using the documentation and tutorials for Gazebo on this page. Gazebo is now a stand alone project at gazebosim.org. See documentation there, thanks!

  • /!\ Disclaimer; as of now (12/28/2012), this tutorial doesn't work with catkin since the dependency (gazebo pkg) is not yet catkinized.

Install ROS

Install the simulator_gazebo stack.

Create a Gazebo Plugin

Create a ROS package in a scratch workspace and add its path to `ROS_PACKAGE_PATH

$ roscreate-pkg gazebo_tutorials gazebo

$ catkin_create-pkg gazebo_tutorials gazebo

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:`pwd`

Create a very simple plugin as described here and save the file as gazebo_tutorials/src/simple_world_plugin.cpp:

#include "gazebo.hh"
#include "common/common.h"
#include <stdio.h>

namespace gazebo
{
  class HelloWorld : public WorldPlugin
  {
    public: HelloWorld() : WorldPlugin() 
            {
              printf("Hello World!\n");
            }

    public: void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
            {
            };

  };
  GZ_REGISTER_WORLD_PLUGIN(HelloWorld)
}

Update gazebo_tutorials/CMakeLists.txt by adding the following lines:

rosbuild_add_library(gazebo_tutorials src/simple_world_plugin.cpp)

add_executable(gazebo_tutorials src/simple_world_plugin.cpp)
target_link_libraries(gazebo_tutorials ${catkin_LIBRARIES})

Update gazebo_tutorials/manifest.txt by adding the following block:

  <export>
    <gazebo plugin_path="${prefix}/lib" gazebo_media_path="${prefix}" />
  </export>

Compiling the Plugin

rosmake gazebo_tutorials

Creating a World file

Save the following file as gazebo_tutorials/worlds/hello.world:

<?xml version="1.0"?> 
<gazebo version="1.0">
  <world name="default">
    <!-- A ground plane -->
    <include filename="ground_plane.model"/>

    <!-- A global light source -->
    <include filename="sun.light"/>

    <!-- reference to your plugin -->
    <plugin name="gazebo_tutorials" filename="libgazebo_tutorials.so"/>
  </world>
</gazebo>

Running the plugin

Create the following launch file gazebo_tutorials/launch/hello.launch:

<launch>
  <!-- set use_sim_time flag -->
  <param name="/use_sim_time" value="true" />
  <node name="gazebo" pkg="gazebo" type="gazebo" args="$(find gazebo_tutorials)/worlds/hello.world" respawn="false" output="screen"/>
  <node name="gazebo_gui" pkg="gazebo" type="gui" respawn="false" output="screen"/>
</launch>

and finally,

roslaunch gazebo_tutorials hello.launch

Wiki: simulator_gazebo/Tutorials/GazeboPluginIntro (last edited 2013-06-19 00:05:57 by davetcoleman)