O'Reilly logo

Mastering ROS for Robotics Programming - Second Edition by Jonathan Cacace, Lentin Joseph

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with ROS services

In this section, we are going to create ROS nodes, which can use the services definition that we defined already. The service nodes we are going to create can send a string message as a request to the server and the server node will send another message as a response.

Navigate to mastering_ros_demo_pkg/src, and find nodes with the names demo_service_server.cpp and demo_service_client.cpp.

The 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) { std::stringstream ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required