#include <gazebo/common/Plugin.hh>#include <ros/ros.h>namespacegazebo{classWorldPluginTutorial:publicWorldPlugin{public:WorldPluginTutorial():WorldPlugin(){}voidLoad(physics::WorldPtr_world,sdf::ElementPtr_sdf){// Make sure the ROS node for Gazebo has already been initialized if(!ros::isInitialized()){ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized, unable to load plugin. "<<"Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");return;}ROS_INFO("Hello World!");}};GZ_REGISTER_WORLD_PLUGIN(WorldPluginTutorial)}
CMakeLists.txtをアップデートする
gazebo_tutorials/CMakeLists.txtを開き、以下のようにしてください。:
1234567891011121314151617181920212223
cmake_minimum_required(VERSION2.8.3)project(gazebo_tutorials)# Load catkin and all dependencies required for this packagefind_package(catkinREQUIREDCOMPONENTSroscppgazebo_ros)# Depend on system install of Gazebofind_package(gazeboREQUIRED)link_directories(${GAZEBO_LIBRARY_DIRS})include_directories(${Boost_INCLUDE_DIR}${catkin_INCLUDE_DIRS}${GAZEBO_INCLUDE_DIRS})add_library(${PROJECT_NAME}src/simple_world_plugin.cpp)target_link_libraries(${PROJECT_NAME}${catkin_LIBRARIES}${GAZEBO_LIBRARIES})catkin_package(DEPENDSroscppgazebo_ros)
<?xml version="1.0" ?><sdfversion="1.4"><worldname="default"><include><uri>model://ground_plane</uri></include><include><uri>model://sun</uri></include><!-- reference to your plugin --><pluginname="gazebo_tutorials"filename="libgazebo_tutorials.so"/></world></sdf>
<launch><!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched --><includefile="$(find gazebo_ros)/launch/empty_world.launch"><argname="world_name"value="$(find gazebo_tutorials)/worlds/hello.world"/><!-- more default parameters can be changed here --></include></launch>