博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ROS入门(八) make_plan的Server连接
阅读量:4701 次
发布时间:2019-06-09

本文共 2220 字,大约阅读时间需要 7 分钟。

在move_base里面,将起始点和终点规划路径并且离散化。

主要是一个叫做make_plan的Service。

 

 

#include 
#include
#include
#include
#include
#include
#define forEach BOOST_FOREACHnav_msgs::GetPlan srv;ros::Publisher goal_pub;ros::ServiceClient plan_client;void callPlanningService(ros::ServiceClient plan_client, nav_msgs::GetPlan &srv){ if(plan_client.call(srv)){ if(!srv.response.plan.poses.empty()) { forEach(const geometry_msgs::PoseStamped &p, srv.response.plan.poses) { ROS_INFO("x = %f, y =%f",p.pose.position.x, p.pose.position.y); } } else { ROS_INFO("EMPTY PLAN."); } } else { ROS_ERROR("Failed to call service."); }}void clicked_point(const geometry_msgs::PointStamped& msg){ //ROS_INFO("Got clicked point:[%f,%f,%f]", msg.pose.x, msg.pose.y, msg.pose.z); nav_msgs::GetPlan srv; move_base_msgs::MoveBaseActionGoal goal; geometry_msgs::PoseStamped goalPos; goalPos.header.frame_id = "map"; goalPos.header.stamp = ros::Time::now(); goalPos.pose.position.x = 1.63; goalPos.pose.position.y = 2.9; goalPos.pose.position.z = 0; goalPos.pose.orientation.x = 0; goalPos.pose.orientation.y = 0; goalPos.pose.orientation.z = 0.115; goalPos.pose.orientation.w = 0.99; srv.request.start.header.stamp = ros::Time::now(); srv.request.start.header.frame_id = "map"; srv.request.start.pose.position.x = msg.point.x; srv.request.start.pose.position.y = msg.point.y; srv.request.start.pose.position.z = 0; srv.request.start.pose.orientation.x = 0; srv.request.start.pose.orientation.y = 0; srv.request.start.pose.orientation.z = 0; srv.request.start.pose.orientation.w = 1; //srv.request.goal.header.frame_id = "map"; srv.request.goal = goalPos; srv.request.tolerance = 0.5; goal.goal.target_pose = goalPos; goal_pub.publish(goal); callPlanningService(plan_client, srv);}int main(int argc, char** argv){ ros::init(argc, argv, "send_goal"); ros::NodeHandle n; goal_pub=n.advertise
("/goal",10); plan_client=n.serviceClient
("/move_base/make_plan"); ros::Subscriber clickedpoint=n.subscribe("/clicked_point", 100, clicked_point); ros::spin(); return 0;}

 

 

 

参考资料:  

Nav_msgs docs:

csdn的make_plan资料:

转载于:https://www.cnblogs.com/TIANHUAHUA/p/8516431.html

你可能感兴趣的文章
POJ2309BST(树状数组)
查看>>
洛谷P2114 起床困难综合症【位运算】【贪心】
查看>>
Ubuntu+caffe训练cifar-10数据集
查看>>
net 把指定 URI 的资源下载到本地
查看>>
js中 $ 未定义 或者 “xxx”未定义
查看>>
Sublime3插件安装
查看>>
[转]大型网站系统架构的演化
查看>>
一个游戏程序员的学习资料
查看>>
非常好的JSUI
查看>>
基于EasyNVR摄像机无插件直播流媒体服务器实现类似于单点登录功能的免登录直播功能...
查看>>
python学习0day
查看>>
课堂练习之检测水军
查看>>
显示和隐藏选项卡
查看>>
函数指针的使用
查看>>
自动化测试的准备
查看>>
E07【餐厅】What would you recommend?
查看>>
HTML基础标签
查看>>
位图数据结构的操作
查看>>
python之路--day23--面向对象高级
查看>>
azkaban用户管理及权限配置
查看>>