Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You have a typo in your code. The second service call should be

unpauseGazebo.call(unpauseSrv);

whereas you have

pauseGazebo.call(unpauseSrv);

which you have already shutdown.

A couple of more suggestions / information (as I have OCD)

You don't need to explicitly call shutdown as per documentation. When the service client goes out of scope, it will be automatically shutdown.

Also, declaring everything on the top makes the code more readable, like this

    ros::ServiceClient pauseGazebo = n_.serviceClient<std_srvs::Empty>("/gazebo/pause_physics");
    ros::ServiceClient unpauseGazebo = n_.serviceClient<std_srvs::Empty>("/gazebo/unpause_physics");
    std_srvs::Empty pauseSrv;
    std_srvs::Empty unpauseSrv;
    char key;

    pauseGazebo.call(pauseSrv);

    std::cout<<"enter q to continue"<<std::endl;

    std::cin>>key;
    if('q' == key)
    {           
        unpauseGazebo.call(unpauseSrv);
        std::cout<<"q is pushed"<<std::endl;
    }