ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
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;
pauseGazebo.call(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.
2 | No.2 Revision |
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;
pauseGazebo.call(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 ?
This should work no ?