#include <ros/ros.h>
#include <begin/my_srv.h>
#include<iomanip>
bool judge(begin::my_srv::Request &req, begin::my_srv::Response &res){
if ((req.req%2)) res.velocity.linear.x = 1.0;
else res.velocity.linear.x = 2.0;
ROS_INFO_STREAM(req.req);
ROS_INFO_STREAM(std::setprecision(2) << std::fixed<< "SENDING BACK : " << res.velocity.linear.x );
return true;
}
int main(int argc, char **argv){
ros::init(argc, argv, "server");//server是节点的名字
ros::NodeHandle n;
ros::ServiceServer service = n.advertiseService("service" , judge);
//service 是服务的名字
ROS_INFO_STREAM("ready to judge!");
ros::spin();//ros::spinOnce()的用法参考浅谈P70、155
//如果除了服务调用之外还有其他任务要做,用spinOnce
return 0;
}