自定义全局规划器

一、ros navigation仿真

1.安装相关模块

  • 安装gazobo接口模块
sudo apt-get install ros-noetic-gazebo-ros-pkgs ros-noetic-gazebo-ros-control
  • 安装turtlebot相关模块
sudo apt-get install ros-noetic-turtlebot-*

2.编译navigation源文件

cd catkin_ws_navigation
catkin_make
soure devel/setup.bash

3.打开gazebo

soure devel/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_gazebo turtlebot3_world.launch

4.slam建图

  • 如果有地图了,可以忽略本步骤
soure devel/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping
  • 新建终端,启动键盘控制
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
  • 保存地图
mkdir -p ~/Desktop/map
rosrun map_server map_saver -f ~/Desktop/map

5.navigation

map的路径要注意不要填错了,可以看一下map.yaml里边的路径是什么,是按照这个路径去找map.pgm的。

soure devel/setup.bash
roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=/home/gao/Desktop/map/map.yaml

注意gazobo的环境要保持打开,不然没有map,rviz会报错。

二、turtlebot3仿真

1.下载编译

cd ~/catkin_ws/src/
git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
cd ~/catkin_ws && catkin_make

2.打开gazebo

soure devel/setup.bash
export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_gazebo turtlebot3_world.launch

3.slam建图

soure devel/setup.bash
roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping

4.navigation导航

soure devel/setup.bash
roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=/home/gao/Desktop/map/map.yaml

三、自定义全局规划器

[官方教程](http://wiki.ros.org/action/fullsearch/navigation/Tutorials/Writing A Global Path Planner As Plugin in ROS?action=fullsearch&context=180&value=linkto%3A"navigation%2FTutorials%2FWriting+A+Global+Path+Planner+As+Plugin+in+ROS")

1.拷贝一个功能包

比如拷贝一个navigation中carrot_planner的功能包,文件夹该名为hy_planner。

拷贝功能包

2.launch文件

新建launch文件夹,并新建文件test.launch.

这个test.launch其实就是turtlebot3_navigation中的turtlebot3_navigation.launch

<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"/>
  <arg name="move_forward_only" default="false"/>

  <!-- 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)" />
    <arg name="move_forward_only" value="$(arg move_forward_only)"/>
  </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>

修改launch文件

roscd turtlebot_navigation/
cd launch

3.指定自定义全局规划器

通过turtlebot3_navigation启动ros导航。

可以看到turtlebot3_navigation的launch文件夹中有三个launch文件,需要修改move_base.launch。

turtlebot3_navigation

修改内容只是添加了一行内容,指定了global planner插件

  <!-- move_base -->
  <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen">
    <param name="base_local_planner" value="dwa_local_planner/DWAPlannerROS" />
    <!-- 添加自定义的全局规划器 -->
    <param name="base_global_planner" value="hy_planner/HyPlanner" />
  </node>

4.编译运行

  • 编译
catkin_make
source devel/setup.bash
  • 检查test_planner是否成功注册进ROS系统
#必须source以后,在本终端可以看到自定义的插件
rospack plugins --attrib=plugin nav_core

可用插件[[]()]()

  • 运行

先打开gazobo环境

export TURTLEBOT3_MODEL=burger
roslaunch turtlebot3_gazebo turtlebot3_world.launch

再启动test.launch

#必须source以后,在本终端可以看到自定义的插件,要在本终端启动test.launch
source devel/setup.bash 
roslaunch hy_planner test.launch 
posted @ 2022-03-21 18:27  高ws  阅读(487)  评论(0编辑  收藏  举报