前言
一、环境搭建
1.1 配置代理(虚拟机情况下可配置)
1.1.1 安装代理
sudo apt-get install proxychains
1.1.2 修改配置文件
对/etc/proxychains.conf
进行修改为宿主机代理服务的ip和端口
socks5 192.xxx.xxx.xxx 1080
对/usr/bin/proxychains
修改export LD_PRELOAD=libproxychains.so.3
获取路径:find /usr/lib/ -name libproxychains.so.3 -print
改为export LD_PRELOAD=刚刚获得的路径
。
想要走代理时只需要在命令前加上proxychains即可
#!/bin/sh
echo "ProxyChains-3.1 (http://proxychains.sf.net)"
if [ $# = 0 ] ; then
echo " usage:"
echo " proxychains <prog> [args]"
exit
fi
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libproxychains.so.3
exec "$@"
1.1.3 配置系统
1.1.4 配置宿主机
配置代理服务允许局域网连接。
1.2安装ROS
buntu18.04下安装ROS melodic版本。
1.2.1 配置源
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
可用国内源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
1.2.2 设置密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
1.2.3 更新系统
sudo apt-get update
sudo apt-get upgrade
1.2.4 安装ROS
sudo apt-get install ros-melodic-desktop-full
1.2.5 安装ROS其他依赖
sudo apt-get install ros-melodic-turtlebot3 ros-melodic-turtlebot3-description ros-melodic-turtlebot3-gazebo ros-melodic-turtlebot3-msgs ros-melodic-turtlebot3-slam ros-melodic-turtlebot3-teleop
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install rospack-tools
1.2.6初始化
# 可使用代理 sudo proxychains rosdep init
sudo rosdep init
rosdep update
1.2.7 添加环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
1.2.8 安装SLAM相关ROS包
- karto建图方法
# 目前激光SLAM的建图方法有很多中,turtlebot3支持gmapping、cartographer、hector、karto、frontier_exploration,
# 而ROS Melodic版本官方的软件源里只有karto
$ sudo apt-get install ros-melodic-slam-karto
- gmapping建图方法
编译安装OpenSlam
git clone https://github.com/ros-perception/openslam_gmapping
mkdir build
cd build
cmake ..
sudo make install
sudo ldconfig #有时候源码编译安装一些第三方库后依然会出现找不到动态链接库的情况,一般这个命令可以解决
编译slam_gmapping
cd ~/catkin_ws/src
git clone https://github.com/ros-perception/slam_gmapping
cd ~/catkin_ws
catkin_make
- 导航包
sudo apt-get install ros-melodic-navigation
1.3 下载gazebo官方models
git clone https://github.com/osrf/gazebo_models
cd gazebo_models
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=~/.gazebo ..在这里插入图片描述
sudo make install
二、Slam建立地图
2.1 键盘控制Turtlebot生成地图
export TURTLEBOT3_MODEL=burger #每开一个新的终端都要设置一下这个环境变量,除了burger也可以是waffle或waffle_pi
#这里也可以选择其他的环境,或者自己搭建一个虚拟环境
roslaunch turtlebot3_gazebo turtlebot3_house.launch
#建图时要切换到这个终端,用键盘控制turtlebot运动
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
#这里也可以选择其他的slam方法
roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=karto
terminate called after throwing an instance of ‘boost::filesystem::filesystem_error’
what(): boost::filesystem::create_directory: Permission denied: “/home/ad/.gazebo/server-11345”
sudo chmod +777 -R ~/
VMware: vmw_ioctl_command error Invalid argument.处理办法:
export SVGA_VGPU10=0
- 环境地图
- Slam构建地图
- Slam构建地图结束
2.2 保存地图
mkdir -p ~/my_slam_map
rosrun map_server map_saver -f ~/my_slam_map/my_house_map
生成pgm文件和yaml文件
pgm文件就是位图,黑色是不可达区域,白色是可达区域,灰色的未知区域。
yaml地图描述文件
image: /home/ad/my_slam_map/my_house_map.pgm
resolution: 0.050000
origin: [-7.497450, -5.326276, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196
- image: 地图文件的路径,可以是绝对路径,也可以是相对路径
- resolution: 地图的分辨率, 米/像素
- origin: 地图左下角的 2D 位姿(x,y,yaw), 这里的yaw是逆时针方向旋转的(yaw=0 表示没有旋转)。目前系统中的很多部分会忽略yaw值。
- occupied_thresh: 占用概率大于这个阈值的的像素,会被认为是完全占用。
- free_thresh: 占用概率小于这个阈值的的像素,会被认为是完全自由。
- negate: 是否颠倒 白/黑 、自由/占用 的意义(阈值的解释不受影响)
三、TurtleBot使用地图导航
roslaunch turtlebot3_gazebo turtlebot3_house.launch
roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=/home/ad/my_slam_map/my_house_map.yaml
原地打转:
[ WARN] [1630823252.287698863, 672.739000000]: DWA planner failed to produce path.
[ WARN] [1630823257.499623513, 677.925000000]: Clearing both costmaps to unstuck robot (3.00m).
[ WARN] [1630823262.654706350, 683.025000000]: Rotate recovery behavior started.
[ WARN] [1630823274.205836222, 694.525000000]: Clearing both costmaps to unstuck robot (1.84m).
[ WARN] [1630823279.319384869, 699.626000000]: Rotate recovery behavior started.
ROS turtlebot navigation导航过程中,算法规划出了路径,但是机器人原地打转。问题在于当机器人有旋转的动作时,所有的可选轨迹就会变很短,从而导致机器人的速度变得很小。如果提高了机器人的速度上限,可以在某种程度上增加机器人有旋转动作时的移动速度
解决办法:
提高acc_lim_x, acc_lim_theta, and acc_lim_trans的参数值(非常大的值,甚至可能实现不了,如10-30)
rosrun rqt_reconfigure rqt_reconfigure
ROS navigation实质是Global planning计算出路径,DWA来执行。因此DWA更像是一个控制器controlle,而不是planner。
[ERROR] [1630823290.932810001, 711.177000000]: Aborting because a valid plan could not be found. Even after executing all recovery behaviors