Skip to content

Instantly share code, notes, and snippets.

@jdumont0201
Created May 4, 2018 11:27
Show Gist options
  • Save jdumont0201/1711adf74ddb88c3642ed3c997faab9c to your computer and use it in GitHub Desktop.
Save jdumont0201/1711adf74ddb88c3642ed3c997faab9c to your computer and use it in GitHub Desktop.
Minimal ROS Service server
#include "ros/ros.h" #include "std_srvs/Empty.h" // Import the service message header file generated from the Empty.srv message
bool my_callback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res){
//process some action
ROS_INFO("My_callback has been called");
return true;
}
int main(int argc, char **argv){
ros::init(argc, argv, "service_server");
ros::NodeHandle nh;
ros::ServiceServer my_service = nh.advertiseService("/my_service", my_callback); // create the Service called // my_service with the defined // callback
ros::spin(); // mantain the service open.
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment