Created
May 4, 2018 11:27
-
-
Save jdumont0201/1711adf74ddb88c3642ed3c997faab9c to your computer and use it in GitHub Desktop.
Minimal ROS Service server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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