ROS开发笔记(7)——利用amcl、move_base 进行导航、基于Python编写巡逻机器人导航代码

本文主要是介绍ROS开发笔记(7)——利用amcl、move_base 进行导航、基于Python编写巡逻机器人导航代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在前期构建地图的基础上,本文将利用 amcl(自适应蒙特卡洛定位算法)来在地图中定位机器人,然后在此基础上利用move_base 在地图中对机器人导航。主要内容如下:

1、amcl(自适应蒙特卡洛定位算法)节点基本原理

2、move_base 节点基本工作原理

3、在地图中定位机器人

4、在rivz中导航

5、编写代码导航

1、amcl(自适应蒙特卡洛定位算法)节点基本原理

1.1、粒子云与pose估计值

amcl算法是一种粒子滤波算法,其维护一堆的位姿(pose)值用粒子(下图中机器人周围的绿色点状物的便是粒子云)表示,每个粒子具有一个概率值,概率越大代表机器人处于这个pose的可能性越大,按概率加权平均就得到了机器人pose的估计值。

1.2、运动预测更新

随着机器人的移动,各个粒子也跟随着机器人里程计数据一起运动更新。

1.3、量测更新

实际量测值:实际的机器人的传感器数据(如激光扫描scan数据)。

理想量测值:基于地图模型map数据可以算出如果机器人就处于某个粒子pose时,理想的传感器数据应该是什么样的。

如果某个粒子的|理想量测值-实际量测值| 比较小,那么这个粒子关联的概率值就要大,反之小,这样对粒子云的概率值进行更新,随着时间的推进,概率过小的粒子将被剔除,概率大的保留并重采样,这样粒子云的分布就发生了变化,如果定位算法收敛,其分布会逐步集中,中心收敛到真实pose附近。

 

amcl 节点信息如下:

wsc@wsc-pc:~$ rosnode list
/amcl
/gazebo
/gazebo_gui
/map_server
/move_base
/robot_state_publisher
/rosout
/rviz
/turtlebot3_teleop_keyboard
wsc@wsc-pc:~$ rosnode info amcl
--------------------------------------------------------------------------------
Node [/amcl]
Publications: * /amcl/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /amcl/parameter_updates [dynamic_reconfigure/Config]* /amcl_pose [geometry_msgs/PoseWithCovarianceStamped]* /particlecloud [geometry_msgs/PoseArray]* /rosout [rosgraph_msgs/Log]* /tf [tf2_msgs/TFMessage]Subscriptions: * /clock [rosgraph_msgs/Clock]* /initialpose [geometry_msgs/PoseWithCovarianceStamped]* /scan [sensor_msgs/LaserScan]* /tf [tf2_msgs/TFMessage]* /tf_static [tf2_msgs/TFMessage]Services: * /amcl/get_loggers* /amcl/set_logger_level* /amcl/set_parameters* /global_localization* /request_nomotion_update* /set_mapcontacting node http://wsc-pc:46609/ ...
Pid: 12958
Connections:* topic: /rosout* to: /rosout* direction: outbound* transport: TCPROS* topic: /tf* to: /amcl* direction: outbound* transport: INTRAPROCESS* topic: /tf* to: /move_base* direction: outbound* transport: TCPROS* topic: /tf* to: /rviz* direction: outbound* transport: TCPROS* topic: /particlecloud* to: /rviz* direction: outbound* transport: TCPROS* topic: /clock* to: /gazebo (http://wsc-pc:33887/)* direction: inbound* transport: TCPROS* topic: /tf* to: /amcl (http://wsc-pc:46609/)* direction: inbound* transport: INTRAPROCESS* topic: /tf* to: /gazebo (http://wsc-pc:33887/)* direction: inbound* transport: TCPROS* topic: /tf* to: /robot_state_publisher (http://wsc-pc:41277/)* direction: inbound* transport: TCPROS* topic: /tf_static* to: /robot_state_publisher (http://wsc-pc:41277/)* direction: inbound* transport: TCPROS* topic: /scan* to: /gazebo (http://wsc-pc:33887/)* direction: inbound* transport: TCPROS* topic: /initialpose* to: /rviz (http://wsc-pc:45675/)* direction: inbound* transport: TCPROSwsc@wsc-pc:~$ 

 

2、move_base 节点基本工作原理

参考链接:http://wiki.ros.org/move_base?distro=melodic

move_base综合了地图、定位系统、传感器及里程计数据,规划一条从当前位置到目标位置goal的路径。

1、navigation goal

通过 MoveBaseAction , MoveBaseGoal等实现,MoveBaseGoal封装了目标pose数据,客服端程序将MoveBaseGoal类型数据发送给MoveBaseAction服务端启动导航过程。

2、global planner

全局规划器 利用地图与规划算法规划一条从当前位置到目标位置的最优路径。

3、local planner

可以利用传感器数据识别不在地图中障碍物信息,如果本地规划行不通,会请求重新进行全局规划。

move_base与其他组件的相关接口描述如下:

 

rosnode info move_base
--------------------------------------------------------------------------------
Node [/move_base]
Publications: * /cmd_vel [geometry_msgs/Twist]* /move_base/DWAPlannerROS/cost_cloud [sensor_msgs/PointCloud2]* /move_base/DWAPlannerROS/global_plan [nav_msgs/Path]* /move_base/DWAPlannerROS/local_plan [nav_msgs/Path]* /move_base/DWAPlannerROS/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/DWAPlannerROS/parameter_updates [dynamic_reconfigure/Config]* /move_base/DWAPlannerROS/trajectory_cloud [sensor_msgs/PointCloud2]* /move_base/NavfnROS/plan [nav_msgs/Path]* /move_base/current_goal [geometry_msgs/PoseStamped]* /move_base/feedback [move_base_msgs/MoveBaseActionFeedback]* /move_base/global_costmap/costmap [nav_msgs/OccupancyGrid]* /move_base/global_costmap/costmap_updates [map_msgs/OccupancyGridUpdate]* /move_base/global_costmap/footprint [geometry_msgs/PolygonStamped]* /move_base/global_costmap/inflation_layer/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/global_costmap/inflation_layer/parameter_updates [dynamic_reconfigure/Config]* /move_base/global_costmap/obstacle_layer/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/global_costmap/obstacle_layer/parameter_updates [dynamic_reconfigure/Config]* /move_base/global_costmap/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/global_costmap/parameter_updates [dynamic_reconfigure/Config]* /move_base/global_costmap/static_layer/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/global_costmap/static_layer/parameter_updates [dynamic_reconfigure/Config]* /move_base/goal [move_base_msgs/MoveBaseActionGoal]* /move_base/local_costmap/costmap [nav_msgs/OccupancyGrid]* /move_base/local_costmap/costmap_updates [map_msgs/OccupancyGridUpdate]* /move_base/local_costmap/footprint [geometry_msgs/PolygonStamped]* /move_base/local_costmap/inflation_layer/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/local_costmap/inflation_layer/parameter_updates [dynamic_reconfigure/Config]* /move_base/local_costmap/obstacle_layer/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/local_costmap/obstacle_layer/parameter_updates [dynamic_reconfigure/Config]* /move_base/local_costmap/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/local_costmap/parameter_updates [dynamic_reconfigure/Config]* /move_base/parameter_descriptions [dynamic_reconfigure/ConfigDescription]* /move_base/parameter_updates [dynamic_reconfigure/Config]* /move_base/result [move_base_msgs/MoveBaseActionResult]* /move_base/status [actionlib_msgs/GoalStatusArray]* /rosout [rosgraph_msgs/Log]Subscriptions: * /clock [rosgraph_msgs/Clock]* /map [nav_msgs/OccupancyGrid]* /move_base/cancel [unknown type]* /move_base/global_costmap/footprint [geometry_msgs/PolygonStamped]* /move_base/goal [move_base_msgs/MoveBaseActionGoal]* /move_base/local_costmap/footprint [geometry_msgs/PolygonStamped]* /move_base_simple/goal [geometry_msgs/PoseStamped]* /odom [nav_msgs/Odometry]* /scan [sensor_msgs/LaserScan]* /tf [tf2_msgs/TFMessage]* /tf_static [tf2_msgs/TFMessage]Services: * /move_base/DWAPlannerROS/set_parameters* /move_base/NavfnROS/make_plan* /move_base/clear_costmaps* /move_base/get_loggers* /move_base/global_costmap/inflation_layer/set_parameters* /move_base/global_costmap/obstacle_layer/set_parameters* /move_base/global_costmap/set_parameters* /move_base/global_costmap/static_layer/set_parameters* /move_base/local_costmap/inflation_layer/set_parameters* /move_base/local_costmap/obstacle_layer/set_parameters* /move_base/local_costmap/set_parameters* /move_base/make_plan* /move_base/set_logger_level* /move_base/set_parameterscontacting node http://wsc-pc:41569/ ...
Pid: 12968
Connections:* topic: /rosout* to: /rosout* direction: outbound* transport: TCPROS* topic: /cmd_vel* to: /gazebo* direction: outbound* transport: TCPROS* topic: /move_base/goal* to: /move_base* direction: outbound* transport: INTRAPROCESS* topic: /move_base/NavfnROS/plan* to: /rviz* direction: outbound* transport: TCPROS* topic: /move_base/local_costmap/footprint* to: /rviz* direction: outbound* transport: TCPROS* topic: /move_base/DWAPlannerROS/global_plan* to: /rviz* direction: outbound* transport: TCPROS* topic: /move_base/DWAPlannerROS/local_plan* to: /rviz* direction: outbound* transport: TCPROS* topic: /clock* to: /gazebo (http://wsc-pc:33887/)* direction: inbound* transport: TCPROS* topic: /tf* to: /gazebo (http://wsc-pc:33887/)* direction: inbound* transport: TCPROS* topic: /tf* to: /robot_state_publisher (http://wsc-pc:41277/)* direction: inbound* transport: TCPROS* topic: /tf* to: /amcl (http://wsc-pc:46609/)* direction: inbound* transport: TCPROS* topic: /tf_static* to: /robot_state_publisher (http://wsc-pc:41277/)* direction: inbound* transport: TCPROS* topic: /move_base_simple/goal* to: /rviz (http://wsc-pc:45675/)* direction: inbound* transport: TCPROS* topic: /map* to: /map_server (http://wsc-pc:33113/)* direction: inbound* transport: TCPROS* topic: /scan* to: /gazebo (http://wsc-pc:33887/)* direction: inbound* transport: TCPROS* topic: /odom* to: /gazebo (http://wsc-pc:33887/)* direction: inbound* transport: TCPROS* topic: /move_base/goal* to: /move_base (http://wsc-pc:41569/)* direction: inbound* transport: INTRAPROCESS

3、在地图中定位机器人

这一步需要启动以下文件:

需要启动的文件

roslaunch turtlebot3_gazebo turtlebot3_world.launch

roslaunch turtlebot3_navigation turtlebot3_navigation.launch

roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

其中 turtlebot3_navigation turtlebot3_navigation.launch 启动文件中启动了map_server 、amcl 、move_base等节点,注意根据自己情况配置好map_file参数(map文件位置),否则会报找不到地图文件。另外,启动move_base节点时一开始报了一个错误“costmap params Invalid argument "/map" passed to canTransform”,根据错误提示,解决方法是,参数配置文件 global_costmap_params.yaml 与 global_costmap_params.yaml 中类似于 “global_frame:  /map ” 改为    “global_frame:  map ”,两个文件中各需要修改两处地方。

<launch><!-- Arguments --><arg name="model" default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]"/><arg name="map_file" default="$(find turtlebot3_navigation)/maps/map.yaml"/><arg name="open_rviz" default="true"/><!-- Turtlebot3 --><include file="$(find turtlebot3_bringup)/launch/turtlebot3_remote.launch"><arg name="model" value="$(arg model)" /></include><!-- Map server --><node pkg="map_server" name="map_server" type="map_server" args="$(arg map_file)"/><!-- AMCL --><include file="$(find turtlebot3_navigation)/launch/amcl.launch"/><!-- move_base --><include file="$(find turtlebot3_navigation)/launch/move_base.launch"><arg name="model" value="$(arg model)" /></include><!-- rviz --><group if="$(arg open_rviz)"> <node pkg="rviz" type="rviz" name="rviz" required="true"args="-d $(find turtlebot3_navigation)/rviz/turtlebot3_navigation.rviz"/></group>
</launch>

为了使算法收敛,初始位置误差不要太大,初始误差大小可以看激光传感器数据与地图障碍物信息的位置误差,启动roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch手动驱动机器人行走,可以使得观察数据多样化加速amcl的收敛。具体操作过程看下面的动图。

4、在rivz中导航

以下是在rivz中导航操作过程的动图:

整个系统节点交连图如下:

5、编写代码导航

通过编程实现两个目标点间来回巡逻的机器人导航代码及注释如下:

#!/usr/bin/env python
#-*- coding:utf-8   -*-import rospy
import actionlib
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
import tf# 巡逻点
waypoints=[[(1.6,0.5,0.0),(0.0,0.0,100.0)],[(-1.8,-0.6,0.0),(0.0,0.0,180.0)]
]
def goal_pose(pose):goal_pose=MoveBaseGoal()goal_pose.target_pose.header.frame_id="map"goal_pose.target_pose.pose.position.x=pose[0][0]goal_pose.target_pose.pose.position.y=pose[0][1]goal_pose.target_pose.pose.position.z=pose[0][2]# r, p, y  欧拉角转四元数x,y,z,w=tf.transformations.quaternion_from_euler(pose[1][0],pose[1][1],pose[1][2])goal_pose.target_pose.pose.orientation.x=xgoal_pose.target_pose.pose.orientation.y=ygoal_pose.target_pose.pose.orientation.z=zgoal_pose.target_pose.pose.orientation.w=wreturn goal_poseif __name__ == "__main__": #节点初始化rospy.init_node('patrol')#创建MoveBaseAction clientclient=actionlib.SimpleActionClient('move_base',MoveBaseAction)#等待MoveBaseAction server启动client.wait_for_server()while not rospy.is_shutdown():for pose in waypoints:goal=goal_pose(pose)client.send_goal(goal)client.wait_for_result()

下面是巡逻时的动图:

这篇关于ROS开发笔记(7)——利用amcl、move_base 进行导航、基于Python编写巡逻机器人导航代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/378402

相关文章

python中列表list切分的实现

《python中列表list切分的实现》列表是Python中最常用的数据结构之一,经常需要对列表进行切分操作,本文主要介绍了python中列表list切分的实现,文中通过示例代码介绍的非常详细,对大家... 目录一、列表切片的基本用法1.1 基本切片操作1.2 切片的负索引1.3 切片的省略二、列表切分的高

基于Python实现一个PDF特殊字体提取工具

《基于Python实现一个PDF特殊字体提取工具》在PDF文档处理场景中,我们常常需要针对特定格式的文本内容进行提取分析,本文介绍的PDF特殊字体提取器是一款基于Python开发的桌面应用程序感兴趣的... 目录一、应用背景与功能概述二、技术架构与核心组件2.1 技术选型2.2 系统架构三、核心功能实现解析

Flutter监听当前页面可见与隐藏状态的代码详解

《Flutter监听当前页面可见与隐藏状态的代码详解》文章介绍了如何在Flutter中使用路由观察者来监听应用进入前台或后台状态以及页面的显示和隐藏,并通过代码示例讲解的非常详细,需要的朋友可以参考下... flutter 可以监听 app 进入前台还是后台状态,也可以监听当http://www.cppcn

通过Python脚本批量复制并规范命名视频文件

《通过Python脚本批量复制并规范命名视频文件》本文介绍了如何通过Python脚本批量复制并规范命名视频文件,实现自动补齐数字编号、保留原始文件、智能识别有效文件等功能,听过代码示例介绍的非常详细,... 目录一、问题场景:杂乱的视频文件名二、完整解决方案三、关键技术解析1. 智能路径处理2. 精准文件名

基于Python开发PDF转Doc格式小程序

《基于Python开发PDF转Doc格式小程序》这篇文章主要为大家详细介绍了如何基于Python开发PDF转Doc格式小程序,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 用python实现PDF转Doc格式小程序以下是一个使用Python实现PDF转DOC格式的GUI程序,采用T

Python使用PIL库将PNG图片转换为ICO图标的示例代码

《Python使用PIL库将PNG图片转换为ICO图标的示例代码》在软件开发和网站设计中,ICO图标是一种常用的图像格式,特别适用于应用程序图标、网页收藏夹图标等场景,本文将介绍如何使用Python的... 目录引言准备工作代码解析实践操作结果展示结语引言在软件开发和网站设计中,ICO图标是一种常用的图像

使用Python开发一个图像标注与OCR识别工具

《使用Python开发一个图像标注与OCR识别工具》:本文主要介绍一个使用Python开发的工具,允许用户在图像上进行矩形标注,使用OCR对标注区域进行文本识别,并将结果保存为Excel文件,感兴... 目录项目简介1. 图像加载与显示2. 矩形标注3. OCR识别4. 标注的保存与加载5. 裁剪与重置图像

使用Python实现表格字段智能去重

《使用Python实现表格字段智能去重》在数据分析和处理过程中,数据清洗是一个至关重要的步骤,其中字段去重是一个常见且关键的任务,下面我们看看如何使用Python进行表格字段智能去重吧... 目录一、引言二、数据重复问题的常见场景与影响三、python在数据清洗中的优势四、基于Python的表格字段智能去重

Python中如何控制小数点精度与对齐方式

《Python中如何控制小数点精度与对齐方式》在Python编程中,数据输出格式化是一个常见的需求,尤其是在涉及到小数点精度和对齐方式时,下面小编就来为大家介绍一下如何在Python中实现这些功能吧... 目录一、控制小数点精度1. 使用 round() 函数2. 使用字符串格式化二、控制对齐方式1. 使用

Python如何快速下载依赖

《Python如何快速下载依赖》本文介绍了四种在Python中快速下载依赖的方法,包括使用国内镜像源、开启pip并发下载功能、使用pipreqs批量下载项目依赖以及使用conda管理依赖,通过这些方法... 目录python快速下载依赖1. 使用国内镜像源临时使用镜像源永久配置镜像源2. 使用 pip 的并