Ask Your Question

Synchronous communication with gazebo

asked 2015-06-20 23:08:02 -0500

AbdealiJK gravatar image


I am trying to implement a robot controller using ros + gazebo - So, what I want it to tell gazebo a particular command and then gazebo should return the state after 1 second. And after that it should pause itself.Now, I do some processing and again give a command - and it should again run for only 1 second.

I need my actions to be used for equal amounts of time.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-06-21 02:01:16 -0500

tfoote gravatar image

To get that level of control of gazebo's flow you will need to write a plugin for gazebo. I suggest you ask for help on

edit flag offensive delete link more

answered 2017-06-01 11:02:44 -0500

TTDM gravatar image

updated 2017-06-02 06:46:10 -0500

Since a google search with the 3 words, gazebo, pause and ros leads to here. I will just drop the few lines needed to pause/unpause gazebo in command/cpp and python ( it took me 3 hours to do it in cpp and despite it being a little out of the scope of the question, it may save this time to a few people). Note that at the end I propose a solution to solve this particular problem without the need to create a plugin.

To (un)pause in command line :

rosservice call gazebo/(un)pause_physics

Those who know how to use services should already know the following but for those who never used services before ( like me ) :

in cpp :

#include <std_srvs/Empty.h>

ros::ServiceClient pauseGazebo = nh.serviceClient<std_srvs::Empty>("/gazebo/(un)pause_physics");
std_srvs::Empty emptySrv;;

in Python ( available here )

from std_srvs.srv import Empty
(un)pause = rospy.ServiceProxy('/gazebo/(un)pause_physics', Empty)

That's for pausing and upausing gazebo.

For this particular problem :

The gazebo ros communication include as services - get_model_state,
- apply_body_wrench, apply_joint_effort, /gazebo/set_model_state and there is also the parameter /use_sim_time

With that it should be possible to do what was asked without writing a plugin. I must say that even if it's possible, I'm not sure if it's advised to process like this instead of creating a plugin for complex interactions with gazebo.

Edit : Indeed @gvdhoorn, It allows to stop the simulation during the processing time of any message ( which is what i thought the OP wanted before your comment) but to do the opposite ( which is having a simulation running but no processing ) is indeed not as straight forward with those services.

I belive it's possible to do what's requested but that it may be very unpractical to do : A "time_managment" node which would subscribe at the command and publish a boolean ROS_FREEZE read by all the other nodes should do the job no ?

  • In the node where the command is published, when the command is published, send at the same time a gazebo "unpause". In the "time_managment" node, receiving the command should trigger the publication of a ROS_FREEZE = TRUE.
  • All the other nodes running should subscribe on this topic and either enter a loop waiting for another message on this particular topic or individually changing the way all the other callbacks work when ROS_FREEZE = true -after 1s,the time_namagment node should send a ROS_FREEZE=false allowing one processing step and the same time a call to the rosservice to "pause" gazebo.
  • then on the next issued command, the cycle can restart.

This should work no ?

edit flag offensive delete link more


It's good to draw attention to the services that Gazebo exposes for controlling the simulation, but those cannot be considered a proper solution to what the OP is asking for here: a way to implement a lock-step execution pattern between all involved nodes & Gazebo.

gvdhoorn gravatar image gvdhoorn  ( 2017-06-02 05:26:35 -0500 )edit

indeed, I answered in my edit, what do you think about it ?

TTDM gravatar image TTDM  ( 2017-06-07 07:44:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-06-20 23:08:02 -0500

Seen: 2,919 times

Last updated: Jun 02 '17