turtlebot3 Slam+nvigation仿真 ROS-lunar

来源:互联网 发布:矩阵计算 线性代数 编辑:程序博客网 时间:2024/06/06 23:59

Date: 2017.09.06
Author: SuperDeveloper
Description: Slam simulation

说明: Slam 初学笔记,搭建slam仿真环境
环境:ubuntu16.04 LTS ,ROS lunar

创建工作空间:

$ mkdir –p /home/work/ros/src$ cd /home/work/ros/src$ catkin_init_workspace

然后进入ros目录(src的上层目录)

$ cd ..$ catkin_make

执行完后会多出几个文件夹,包含devel

$ echo “source ~/work/ros/src ” > ~/.bashrc

这样就不用每次打开命令窗口都导入一次路径

安装Turtlebot3
安装依赖包:

$ sudo apt-get install ros-indigo-navigation

然后在WIKI搜索gmapping,在主页上找到源代码链接

$ cd ~/work/src$ git clone  https://github.com/ros-perception/slam_gmapping.git 

同样在WIKI上找到hector-mapping

$ git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam.git

仔细查看WIKI会发现hector-mapping依赖openslam_gmapping,点击找到链接

$ git clone https://github.com/ros-perception/openslam_gmapping.git

下载软件包:

依然在src目录

$ git clone https://github.com/ROBOTIS-GIT/turtlebot3.git$ git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git$ git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git$ git clone https://github.com/ros-teleop/teleop_twist_keyboard.git

回到上一级目录

$ cd ..$ catkin_make

编译完成即可

启动机器人仿真环境

打开Terminal

$ export TURTLEBOT3_MODEL=”burger”

每次打开Termina运行turtlebot3相关的包都要执行一次上诉指令。
启动gazebo

$ roslaunch turtlebot3_gazebo turtlebot3_world.launch

用TAB键可自动补全,如果不能补全说明软件没安装上,或者没有导入工作空间的setup.bash,参考本文前面部分
启动rviz

$ roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch

启动SLAM

打开Terminal

$ roscore$ roslaunch turtlebot3_slam  turtlebot3_slam.launch

点击rviz的Add按钮,添加一个Map类型,topic输入/map,勾选刷新
打开一个Terminal

$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py

通过键盘进行控制,进行控制前请阅读Terminal里的操作说明
I 前进
U 左转
O 右转

M ,<, >, 后退

nvigation自主导航

在SLAM创建地图完成后保存地图

$ rosrun mapserver mapsaver –f ~/work/ros/test_map

启动nvigation

$ roslaunch turtlebot3_nvigation turtlebot3_nvigation.launch map_file=~/work/ros/test_map.yaml

然后在rviz中用global箭头设定目标位置和方向,停止之前的键盘输入,开始自动导航

记录数据:
进入需要保存数据的目录,打开Terminal

$ rosbag record –a

停止录入直接ctrl+c
停止之前打开的除roscore 和rviz之外的命令窗口,回放数据

$ rosbag play 2017-10****.bag
原创粉丝点击