/* * rosserial_embeddedlinux service server example * * Advertises a service it offers. Prints the string sent to the service * and responds with an alternating string. * The service request can be sent from the ROS command line with e.g. * $ xxx */ #include #include #include #include ros::NodeHandle nh; using rosserial_examples::Test; #define ROSSRVR_IP "192.168.15.122" int i=0; void svcCallback(const Test::Request & req, Test::Response & res){ if((i++)%2) res.output = "hello"; else res.output = "ros"; printf("Service request message: \"%s\" received, responding with: %s", res.output); } ros::ServiceServer server("test_srv",&svcCallback); int main() { nh.initNode(ROSSRVR_IP); nh.advertiseService(server); while(1) { nh.spinOnce(); sleep(1); } }