After setting up controlled simulation stepping in a pure Gazebo environment (here), we’ll now move towards integrating the plugin in a ROS-Gazebo simulation. For this post, the codebase for the plugin is unchanged and only a few lines of code are needed to get this working. You can find the source for this post here.
There are two tutorials I recommend reading through. The first covers the basics of using Gazebo plugins with ROS while the second provides a better overview of integrating Gazebo plugins with ROS.
Step the World with ROS
The code needed to integrate our plugin from the previous post requires the following insertion/modifications.
Insert the following line into the package.xml file located in src/world_step/ between the export tags:
<gazebo_ros plugin_path="${prefix}/lib" gazebo_media_path="${prefix}"/>
Add/modify the following lines to your CMakelists.txt located in src/world_step/:
find_package(catkin REQUIRED COMPONENTS roscpp gazebo_ros ) find_package(gazebo REQUIRED) include_directories(${Boost_INCLUDE_DIR} ${catkin_INCLUDE_DIRS} ${GAZEBO_INCLUDE_DIRS}) link_directories(${GAZEBO_LIBRARY_DIRS}) add_library(world_step src/plugins/world_step.cc) target_link_libraries(world_step ${catkin_LIBRARIES} ${GAZEBO_LIBRARIES})
These two changes should be all that’s needed to build the plugin from the previous example, provided you correctly move the world_step.cc file into this project of course.
Launching the environment requires you to build the project using the following:
catkin_make source devel/setup.sh
The enter the following command to start ROS-Gazebo:
roslaunch world_step world_step.launch
If all goes well, you should see something like the image below with the iterations and simulation time corresponding to each other and updating roughly every second of real world time. In the terminal where you called roslaunch you should see the repeating message “Publishing OnUpdate.” which is printed each time the simulation is stepped.
Future Extensions
Now that we can step the world programmatically, the next steps are to integrate logic to start and terminate a simulation after a set amount of time and begin writing the evolutionary framework to launch many simulations.