Working with ROS services
In this section, we are going to create ROS nodes, which can use the service definition that we defined already. The service nodes we are going to create can send a string message as a request to the server; then, the server node will send another message as a response.
Navigate to mastering_ros_demo_pkg/src
and find the demo_service_server.cpp
and demo_service_client.cpp
nodes.
demo_service_server.cpp
is the server, and its definition is as follows:
#include "ros/ros.h" #include "mastering_ros_demo_pkg/demo_srv.h" #include <iostream> #include <sstream> using namespace std; bool demo_service_callback(mastering_ros_demo_pkg::demo_srv::Request &req, mastering_ros_demo_pkg::demo_srv::Response &res) { ss << "Received Here"; ROS_INFO("From Client [%s], Server says [%s]",req.in.c_str(),res.out.c_str()...