路径规划:从一个点到另一个点,规划出最优的路线。用到service :make_plan (nav_msgs/GetPlan) 
服务名为move_base_node/make_plan 
nav_msgs/GetPlan api:

 # Get a plan from the current position to the goal Pose 

# The start pose for the plan
geometry_msgs/PoseStamped start # The final pose of the goal position
geometry_msgs/PoseStamped goal # If the goal is obstructed, how many meters the planner can
# relax the constraint in x and y before failing.
float32 tolerance
---
nav_msgs/Path plan Compact Message Definition
geometry_msgs/PoseStamped start
geometry_msgs/PoseStamped goal
float32 tolerance
nav_msgs/Path plan

现在学习如何使用 
在工作空间新建package navigation_example

cd ~/catkin_ws/src
catkin_create_pkg navigation_example std_msgs rospy roscpp tf actionlib

CMakeList.txt 中的find_package如下

find_package(catkin REQUIRED COMPONENTS
actionlib
roscpp
rospy
std_msgs
tf
)

在src目录下新建make_plan.cpp

/*
* make_plan.cpp
*
* Created on: Aug 10, 2016
* Author: unicorn
*/
//路线规划代码
#include <ros/ros.h>
#include <nav_msgs/GetPlan.h>
#include <geometry_msgs/PoseStamped.h>
#include <string>
#include <boost/foreach.hpp>
#define forEach BOOST_FOREACH
void fillPathRequest(nav_msgs::GetPlan::Request &request)
{
request.start.header.frame_id ="map";
request.start.pose.position.x = 12.378;//初始位置x坐标
request.start.pose.position.y = 28.638;//初始位置y坐标
request.start.pose.orientation.w = 1.0;//方向
request.goal.header.frame_id = "map";
request.goal.pose.position.x = 18.792;//终点坐标
request.goal.pose.position.y = 29.544;
request.goal.pose.orientation.w = 1.0;
request.tolerance = 0.5;//如果不能到达目标,最近可到的约束
}
//路线规划结果回调
void callPlanningService(ros::ServiceClient &serviceClient, nav_msgs::GetPlan &srv)
{
// Perform the actual path planner call
//执行实际路径规划器
if (serviceClient.call(srv)) {
//srv.response.plan.poses 为保存结果的容器,遍历取出
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_WARN("Got empty plan");
}
}
else {
ROS_ERROR("Failed to call service %s - is the robot moving?",
serviceClient.getService().c_str());
}
} int main(int argc, char** argv)
{
ros::init(argc, argv, "make_plan_node");
ros::NodeHandle nh;
// Init service query for make plan
//初始化路径规划服务,服务名称为"move_base_node/make_plan"
std::string service_name = "move_base_node/make_plan";
//等待服务空闲,如果已经在运行这个服务,会等到运行结束。
while (!ros::service::waitForService(service_name, ros::Duration(3.0))) {
ROS_INFO("Waiting for service move_base/make_plan to become available");
}
/*初始化客户端,(nav_msgs/GetPlan)
Allows an external user to ask for a plan to a given pose from move_base without causing move_base to execute that plan.
允许用户从move_base 请求一个plan,并不会导致move_base 执行此plan
*/
ros::ServiceClient serviceClient = nh.serviceClient<nav_msgs::GetPlan>(service_name, true);
if (!serviceClient) {
ROS_FATAL("Could not initialize get plan service from %s",
serviceClient.getService().c_str());
return -;
}
nav_msgs::GetPlan srv;
//请求服务:规划路线
fillPathRequest(srv.request);
if (!serviceClient) {
ROS_FATAL("Persistent service connection to %s failed",
serviceClient.getService().c_str());
return -;
}
ROS_INFO("conntect to %s",serviceClient.getService().c_str());
callPlanningService(serviceClient, srv);
}

CMakeList中添加

add_executable(make_plan src/make_plan.cpp)
target_link_libraries(make_plan
${catkin_LIBRARIES}
)

编译运行:

cd ~/catkin_ws
catkin_make
source devel/setup.bash
rosrun navigation_example make_plan

运行结果:

1.

2.

参考:

https://blog.csdn.net/yiranhaiziqi/article/details/52891312

https://blog.csdn.net/u013158492/article/details/50483123

https://blog.csdn.net/jack_20/article/details/80292601

http://ask.zol.com.cn/x/5428696.html

ROS中make_plan服务的使用的更多相关文章

  1. ROS学习笔记9-创建ros消息和服务

    该节内容主要来自于官方文档的两个小节:1.使用rosed来编辑2.创建ros消息的服务 先来看rosed: rosedrosed命令是rosbash的一部分,使用rosed可以直接编辑包中的一个文件, ...

  2. 对比几种在ROS中常用的几种SLAM算法

    在此因为要总结写一个文档,所以查阅资料,将总结的内容记录下来,欢迎大家指正! 文章将介绍使用的基于机器人操作系统(ROS)框架工作的SLAM算法. 在ROS中提供的五种基于2D激光的SLAM算法分别是 ...

  3. ROS消息vs服务

    1.ROS包消息/服务模式与要点 从功能上看,ROS包是信息交互和处理的基本单元.根据信息的交互和处理方式,ROS包有以下两大类: 消息发布者与订阅者 服务器与客户端 对于消息模式的包,信息的提供者主 ...

  4. ROS中的日志(log)消息

    学会使用日志(log)系统,做ROS大型项目的主治医生 通过显示进程的运行状态是好的习惯,但需要确定这样做不会影响到软件的运行效率和输出的清晰度.ROS 日志 (log) 系统的功能就是让进程生成一些 ...

  5. ROS中msg和srv文件的区别

    1.msg和srv究竟有什么区别?? msg只是单向的发送和接受. srv包含两个部分:请求和响应. 2.msg和srv简介 msg:msg文件是描述ROS消息字段的简单文本文件.它们用于为不同语言( ...

  6. (转)ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法

    早上同事用PL/SQL连接虚拟机中的Oracle数据库,发现又报了"ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务"错误,帮其解决后,发现很多人遇到过这样的问 ...

  7. 如何在Windows 2003+IIS6的环境下找回应用程序池(application pool)中的服务账号密码

    上一篇文章说了说如何在Win2008+iis7中取出SharePoint管理账号密码的方法. 整个过程简单的讲,就是通过使用要找回密码的账号用来在SharePoint中创建一个临时的Web Appli ...

  8. 关于Oracle报“ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务”错误

    关于Oracle报“ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务”错误原因:listener.ora中没有指定监听服务器名. 如下是解决思路: 尝试1.通过重启服务的方式启动数 ...

  9. 避免在ASP.NET Core中使用服务定位器模式

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:服务定位器(Service Locator)作为一种反模式,一般情况下应该避免使用,在 ...

随机推荐

  1. 【转载】IIS网站如何同时解析带www和不带www的域名

    针对公网上线的网站系统,很多网站的域名会同时含有带www和不带www的域名解析记录,如果需要同时解析带www和不带www的域名信息,则需要在相应的域名解析平台(如阿里云域名解析平台.腾讯云域名解析平台 ...

  2. [ICCV 2019] Weakly Supervised Object Detection With Segmentation Collaboration

    新在ICCV上发的弱监督物体检测文章,偷偷高兴一下,贴出我的poster,最近有点忙,话不多说,欢迎交流- https://arxiv.org/pdf/1904.00551.pdf http://op ...

  3. UI5-技术篇-SAP UI5数据表进行了比较:sap.m.Table与sap.ui.table.Table

    https://a.kabachnik.info/sap.m.table-vs-sap.ui.table.table-features-compared.html SAP UI5数据表进行了比较:sa ...

  4. webdispatch配置

    PRDPISP01:/sapmnt/WIP/profile # su - wipadm PRDPISP01:wipadm 23> cdpro PRDPISP01:wipadm 24> ls ...

  5. 易优cms后台RCE以及任意文件上传漏洞

    前言 EyouCms是基于TP5.0框架为核心开发的免费+开源的企业内容管理系统,专注企业建站用户需求提供海量各行业模板,降低中小企业网站建设.网络营销成本,致力于打造用户舒适的建站体验.易优cms ...

  6. bootstrap table分页limit计算pageIndex和pageSize

    由于bootstrap table的js无法直接获取pageSize和pageIndex的值,只能通过limit进行计算.

  7. 记一次B类地址子网划分

    说明:一般内网地址,没有要求严格的划分之类的.需要按要求严格划分一般都是公网地址 温馨提醒:由于笔者功底不是很深厚,只能说我们保证把数算对用相对简单的方法 现有一个公网ip,B类地址130.3.0.0 ...

  8. pycharm连接数据库

    今天说说如何使用pycharm连接oracle数据库 1.首先你需要安装oracle数据库 2.在pycharm中安装cx_Oracle.在file->settings->Project- ...

  9. Linux 之 搜索

    locate - 文件名搜索命令 用于查找文件 格式为:locate 文件名 该命令用于查找符合条件的文件,它会去保存文件与目录名称的数据库内,查找合乎范本样式条件的文件或目录. 因为该命令是直接在数 ...

  10. linux运维之路配置网络

    前言裸机上装操作系统,想和物理机通信需要设置IP 开机以后: 第一步:setup命令  ——>  NetWork configguation  ---->Device configurat ...