日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ROS服务中自定义数据类型

發(fā)布時間:2025/3/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ROS服务中自定义数据类型 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

ROS服務(wù)中自定義數(shù)據(jù)類型

在上一篇文章中,描述了一種兩層封裝的點集傳輸服務(wù)消息類型,比較復(fù)雜。上一篇文章
事后我就在想何必包兩層,直接在服務(wù)中利用提供的數(shù)據(jù)類型定義數(shù)組不就行了。所以動手試了一下:

自定義數(shù)據(jù)類型


代碼應(yīng)用

//server端 #include "ros/ros.h" #include "gm_ros_package/objectPosition.h" #include "gm_ros_package/test.h"bool process_position(gm_ros_package::test::Request &req,gm_ros_package::test::Response &res) { // ROS_INFO("x:%f,y:%f,z:%f",req.points.point[0].x,req.points.point[0].y,req.points.point[0].z);for(int i =0;i < 2;i ++){ROS_INFO("x:%f,y:%f,z:%f",req.points[i].x,req.points[i].y,req.points[i].z);}res.back = 12;return true; }int main(int argc,char** argv) {ros::init(argc,argv,"recive_positon_node");ros::NodeHandle nh;ros::ServiceServer service = nh.advertiseService("object_position",process_position);ROS_INFO("wait the position message!");ros::spin();return 0; } //client端 #include "ros/ros.h" #include "gm_ros_package/objectPosition.h" #include "gm_ros_package/Points.h" #include "geometry_msgs/Point.h" #include "gm_ros_package/test.h" #include <iostream> using namespace std;int main(int argc,char** argv) {ros::init(argc,argv,"send_position_node");ros::NodeHandle nh;ros::ServiceClient client = nh.serviceClient<gm_ros_package::test>("object_position");gm_ros_package::test position;gm_ros_package::Points points;geometry_msgs::Point point[2];cout << "test" << endl;point[0].x = 1.0;point[0].y = 2.0;point[0].z = 3.0;point[1].x = 11.0;point[1].y = 21.0;point[1].z = 3.10;cout << "test1" << endl;std::vector<geometry_msgs::Point> ar(point,point+2);// points.point = ar;// position.request.points = points;position.request.points = ar;cout << "baxk" << endl;if(client.call(position)){ROS_INFO("the progress is :%ld",position.response.back);}else{ROS_ERROR("Fail to call service");} }

總結(jié)

以上是生活随笔為你收集整理的ROS服务中自定义数据类型的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。