Tutorials/1.5/plugins/system gui plugin


 * Description:** Describes the process of making a system plugin that is loaded by the GUI.

This tutorial will create a source file that is a system plugin designed to save images into the director `/tmp/gazebo_frames`.

We'll start with the source file. Create a file called `system_gui.cc`

mkdir ~/gazebo_gui_plugin cd ~/gazebo_gui_plugin gedit system_gui.cc

with the following contents:


 * 1) include "gui/Gui.hh"
 * 2) include "rendering/rendering.hh"
 * 3) include "gazebo.hh"

namespace gazebo { class SystemGUI : public SystemPlugin {   public: void Load(int /*_argc*/, char ** /*_argv*/) {   }

private: void Init {     // Get a pointer to the active user camera this->userCam = gui::get_active_camera;

// Enable saving frames this->userCam->EnableSaveFrame(true);

// Specify the path to save frames into this->userCam->SetSaveFramePathname("/tmp/gazebo_frames"); }

private: rendering::UserCameraPtr userCam; private: std::vector connections; };

// Register this plugin with the simulator GZ_REGISTER_SYSTEM_PLUGIN(SystemGUI) }

Both the `Load` and `Init` functions must not block. The `Load` function is called at startup, before Gazebo is loaded. The `Init` function is called after Gazebo has been loaded.

In our `Init` function, we get a pointer to the user camera (the camera used in the graphical interface) and enable saving of frames.

1. Get the user camera

 this->userCam = gui::get_active_camera;

2. Enable save frames

 this->userCam->EnableSaveFrame(true);

3. Set the location to save frames

 this->userCam->SetSaveFramePathname("/tmp/gazebo_frames");


 * 1) Compiling Camera Plugin ###

Create a CMakeLists.txt file

cd ~/gazebo_gui_plugin gedit CMakeLists.txt

Copy the following in the CMakeLists.txt file

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

include (FindPkgConfig) if (PKG_CONFIG_FOUND) pkg_check_modules(GAZEBO gazebo) pkg_check_modules(OGRE OGRE) endif include_directories(${GAZEBO_INCLUDE_DIRS} ${OGRE_INCLUDE_DIRS}) link_directories(${GAZEBO_LIBRARY_DIRS} ${OGRE_LIBRARY_DIRS})

add_library(system_gui SHARED system_gui.cc) target_link_libraries(system_gui ${GAZEBO_libraries} ${OGRE_LIBRARIES})

Move to the build directory, run cmake, and compile. You should end up with a libsystem_gui.so library.

cd build cmake ../ make

Make sure the location of the plugin is in your $GAZEBO_PLUGIN_PATH

export GAZEBO_PLUGIN_PATH=$PWD:$GAZEBO_PLUGIN_PATH


 * 1) Running Plugin ###

You will need to start the server and client separately.

In one terminal:

gzserver

In another terminal

cd ~/gazebo_plugin_tutorial/build gzclient -g libsystem_gui.so

Inside /tmp/gazebo_frames you should see many saved images from the current plugin.