turtlebot3 深度强化学习踩坑

余生颓废 提交于 2020-02-05 07:40:52

1、Anaconda2 安装

ROS 1中使用的是 python2.7,所以在地址: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/#linux 中下载 python2.7版本的Anaconda2 ,安装过程如下:

chmod +x Anaconda2-5.2.0-Linux-x86_64.sh
 
bash Anaconda2-5.2.0-Linux-x86_64.sh

安装完成后,执行下面指令, 如果可以看到 Python 2.7.xx :: Anaconda, Inc…,说明安装成功。

source ~/.bashrc
 
python -V

接下来配置环境变量 PYTHONPATH,编辑 ~/.bashrc ,修改或者添加内容如下:

export PYTHONPATH="/home/wxm/anaconda2/lib/python2.7/dist-packages:$PYTHONPATH  

2、Tensorflow、Keras等安装
本文中用到的机器学习算法是DQN(Deep Q-Learning),基于Tensorflow与Keras开发,为了避免包冲突,在Anaconda中构建虚拟环境(取名为py2):

  conda create -n py2 pip python=2.7

在虚拟环境(envs)中安装Tensorflow、Keras以及ROS依赖包:

source activate py2

pip install -U rosinstall msgpack empy defusedxml netifaces

pip install --ignore-installed --upgrade https://download.tensorflow.google.cn/linux/gpu/tensorflow_gpu-1.8.0-cp27-none-linux_x86_64.whl

pip install keras

source deactivate py2

3、下载并编译源码

本文先使用github中开源的机器学习的源码进行学习,下载编译过程如下:

cd ~/catkin_ws/src/

git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git

git clone https://github.com/ROBOTIS-GIT/turtlebot3.git

git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations

git clone https://github.com/ROBOTIS-GIT/turtlebot3_machine_learning.git

cd ~/catkin_ws && catkin_make

编译成功以后执行下面的脚本,也可以将其添加到~/.bashrc中或者直接source ~/.bashrc

  source /home/wxm/turtlebot3_ws/devel/setup.bash

4、设置参数并运行范例

设置参数:

打开源码文件 turtlebot3/turtlebot3_description/urdf/turtlebot3_burger.gazebo.xacro,修改一下两处:

<xacro:arg name="laser_visual" default="false"/>   # 如果想看到激光扫描线,设置成 `true`
<scan>
<horizontal>
<samples>360</samples>            # 修改成24
<resolution>1</resolution>
<min_angle>0.0</min_angle>
<max_angle>6.28319</max_angle>
</horizontal>
</scan>

打开一个终端,启动turtlebot3 gazebo环境等节点:

roscore
roslaunch turtlebot3_gazebo turtlebot3_stage_1.launch

打开另外一个终端,启动DQN算法等节点:

source activate py2

roslaunch turtlebot3_dqn turtlebot3_dqn_stage_1.launch

注意:运行的时候出现错误:[turtlebot3_dqn_stage_1-1] process has died [pid 8329, exit code 1, cmd /home/wxm/turtlebot3_ws/src/turtlebot3_machine_learning/turtlebot3_dqn/nodes/turtlebot3_dqn_stage_1 __name:=turtlebot3_dqn_stage_1 __log:=/home/wxm/.ros/log/138fed20-2e1c-11ea-a94c-0871908fc9ab/turtlebot3_dqn_stage_1-1.log]. log file: /home/wxm/.ros/log/138fed20-2e1c-11ea-a94c-0871908fc9ab/turtlebot3_dqn_stage_1-1.log*

这是因为tensorflow和keras版本不兼容,所以将之前下载的keras卸载,重新下载:

pip install keras==2.1.5

问题解决。

打开第三个终端,启动数据图形显示节点:

pip install pyqtgraph
 
roslaunch turtlebot3_dqn result_graph.launch
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!