ROS服务中自定义数据类型
生活随笔
收集整理的這篇文章主要介紹了
ROS服务中自定义数据类型
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ROS服務中自定義數據類型
在上一篇文章中,描述了一種兩層封裝的點集傳輸服務消息類型,比較復雜。上一篇文章
事后我就在想何必包兩層,直接在服務中利用提供的數據類型定義數組不就行了。所以動手試了一下:
自定義數據類型
代碼應用
//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");} }總結
以上是生活随笔為你收集整理的ROS服务中自定义数据类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: wamp安装多版本php,WampSer
- 下一篇: php=与-,谈谈PHP中的 -、= 和