ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Here is simple code to do this, adapted from the examples at A Gentle Introduction to ROS. The last three lines are key, since they call the service. Remember to #include the relevant .h file for the service you are using.
// This program waits for the clear service to be available
// (potentially waiting for turtlesim to start up), and
// clears the screen.
#include <ros/ros.h>
#include <std_srvs/Empty.h>
int main(int argc, char **argv) {
ros::init(argc, argv, "clear_screen");
ros::NodeHandle nh;
// Wait until the clear service is available, which
// indicates that turtlesim has started up, and has
// set the background color parameters.
ros::service::waitForService("clear"); //this is optional
// Get turtlesim to pick up the new parameter values.
ros::ServiceClient clearClient
= nh.serviceClient<std_srvs::Empty>("/clear");
std_srvs::Empty srv;
clearClient.call(srv);
}