博文

目前显示的是标签为“srv”的博文

【ROS学习-11】用C++编写一个简单的服务端和客户端

1. 首先执行 roscd beginner_tutorials 命令,然后创建 src/add_two_ints_server.cpp 服务端源码,内容如下:   #include "ros/ros.h"   #include "beginner_tutorials/AddTwoInts.h"   bool add(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::ServiceServer service = n.advertiseService("add_two_ints", add);     ROS_INFO("Ready to add two ints.");     ros::spin();     return 0; ...

【ROS学习-9】创建ROS msg和srv

1. 关于 msg 和 srv     msg : msg files are simple text files that describe the fields of a ROS message. They are used to generate source code for messages in different languages.     srv : an srv file describes a service. It is composed of two parts: a request and a response.    msg files are stored in the  msg  directory of a package, and srv files are stored in the  srv  directory.    msgs are just simple text files with a field type and field name per line. The field types you can use are: int8, int16, int32, int64 (plus uint*) float32, float64 string time, duration other msg files variable-length array[] and fixed-length array[C]    There is also a special type in ROS:  Header , the header contains a timestamp and coordinate frame information that are commonly used in ROS. You will frequently see the first line in a msg file have  Header header .   ...