用C++编写一个简单的服务端和客户端

1.首先执行roscd beginner_tutorials命令,然后创建src/add_two_ints_server.cpp服务端源码,内容如下:

  #include "ros/ros.h"
  #include"beginner_tutorials/AddTwoInts.h"

  booladd(beginner_tutorials::AddTwoInts::Request &req,
          beginner_tutorials::AddTwoInts::Response &res)
  {
      res.sum = req.a + req.b;
      ROS_INFO("request: x=%ld,y=%ld", (long int)req.a, (long int)req.b);
      ROS_INFO("sending back response:[%ld]", (long int)res.sum);
      return true;
  }

  int main(int argc, char **argv)
  {
      ros::init(argc, argv,"add_two_ints_server");
      ros::NodeHandle n;
      ros

你可能感兴趣的:(ROS,linux,ubuntu,机器人,ROS)