ROS、OpenAI和Gazebo机器人与人工智能仿真与实践教研杂记(一)安装配置

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ZhangRelay/article/details/89702997

时间:2019年4月30日,将2018-2019-1学期,也就是2018年秋学期的一些工作文字稿转录为博文。

课程教学实践环境:

系统:Ubuntu 18.04.2 LTS + ROS Melodic(1.0)1.14.3 ~ 1943 + ROS  Crystal(2.0)0.6.1 ~ 541 etc.

仿真:Gazebo 9.8.0 + V-Rep 3.6.1 + Webots 2019a.1 etc.

实物:Cozmo/Vector + Leap Motion + Joystick + Camera + Microphone + Speaker + Phone(ios&android)+ Arduino etc.

镜像:ROS2Go ver2.0 + 实验楼ROS + Exbot ROS iso indigo&kinetic etc.

书籍:ROS机器人高效编程 + ROS机器人项目开发11例 etc.

编程:Matlab 2018a + Python 2.7 + Python 3.6 + C++ etc.

智能:Tensorflow + Caffe + OpenAI etc.

语音:科大讯飞 + 百度语音 + Sphinx etc.

2015-2019全部涉及软硬件平台更多,均在博客中有记录和介绍,此处不再赘述。

先以gym-gazebo为例,简要说明一下:

测试和调试环境:Ubuntu 18.04.2 LTS,其余如上文所述。

gym-gazebo支持ROS Melodic(1.0),gym-gazebo2支持ROS Crystal(2.0)

  1. https://github.com/erlerobot/gym-gazebo(ROS 1)
  2. https://github.com/AcutronicRobotics/gym-gazebo2 (ROS 2)

 


版本问题:将gazebo-8代码替换给gezbo-9:

Could not open file[/usr/share/gazebo-8/worlds/empty_bullet.world]


使用Gazebo的Open gym扩展,下面以ROS Melodic为例介绍:

An OpenAI gym extension for using Gazebo known as gym-gazebo

This work presents an extension of the initial OpenAI gym for robotics using ROS and Gazebo. A whitepaper about this work is available at https://arxiv.org/abs/1608.05742. Please use the following BibTex entry to cite our work:

@article{zamora2016extending,
  title={Extending the OpenAI Gym for robotics: a toolkit for reinforcement learning using ROS and Gazebo},
  author={Zamora, Iker and Lopez, Nestor Gonzalez and Vilches, Victor Mayoral and Cordero, Alejandro Hernandez},
  journal={arXiv preprint arXiv:1608.05742},
  year={2016}
}

论文发表和简要介绍如上。

gym-gazebo is a complex piece of software for roboticists that puts together simulation tools, robot middlewares (ROS, ROS 2), machine learning and reinforcement learning techniques. All together to create an environment whereto benchmark and develop behaviors with robots. Setting up gym-gazebo appropriately requires relevant familiarity with these tools.

Code is available "as it is" and currently it's not supported by any specific organization. Community support is available here. Pull requests and contributions are welcomed.

gym-gazebo是一个复杂的机器人软件软件,它将模拟仿真工具,机器人中间件(ROS,ROS 2),机器学习和强化学习技术结合在一起。共同创造一个环境,用机器人来评估和开发行为。正确设置gym-gazebo需要熟悉这些工具。

目录

安装

Ubuntu 18.04

基本要求

ROS Melodic相关的依赖

sudo apt-get install \
python-pip python3-vcstool python3-pyqt4 \
pyqt5-dev-tools \
libbluetooth-dev libspnav-dev \
pyqt4-dev-tools libcwiid-dev \
cmake gcc g++ qt4-qmake libqt4-dev \
libusb-dev libftdi-dev \
python3-defusedxml python3-vcstool \
ros-melodic-octomap-msgs        \
ros-melodic-joy                 \
ros-melodic-geodesy             \
ros-melodic-octomap-ros         \
ros-melodic-control-toolbox     \
ros-melodic-pluginlib	       \
ros-melodic-trajectory-msgs     \
ros-melodic-control-msgs	       \
ros-melodic-std-srvs 	       \
ros-melodic-nodelet	       \
ros-melodic-urdf		       \
ros-melodic-rviz		       \
ros-melodic-kdl-conversions     \
ros-melodic-eigen-conversions   \
ros-melodic-tf2-sensor-msgs     \
ros-melodic-pcl-ros \
ros-melodic-navigation \
ros-melodic-sophus

安装Python包:

sudo pip install gym
sudo apt-get install python-skimage
sudo pip install h5py
pip install tensorflow-gpu (if you have a gpu if not then just pip install tensorflow)
sudo pip install keras

安装gym-gazebo:

cd ~
git clone https://github.com/erlerobot/gym-gazebo
cd gym-gazebo
sudo pip install -e .

运行bash文件,构建ros工作区:

cd gym-gazebo/gym_gazebo/envs/installation
bash setup_melodic.bash

执行示例

运行qlearn的示例:

终端1

cd gym-gazebo/gym_gazebo/envs/installation/
bash turtlebot_setup.bash

终端2

cd gym-gazebo/examples/turtlebot
python circuit_turtlebot_lidar_qlearn.py

运行dqn的示例:

终端1

cd gym-gazebo/gym_gazebo/envs/installation/
bash turtlebot_nn_setup.bash

终端2

cd gym-gazebo/examples/turtlebot
python circuit_turtlebot_lidar_qlearn.py

 

用法

建造并安装gym-gazebo

库的根目录中:

sudo pip install -e .

运行环境

  • 加载与要启动的机器人对应的环境变量。例如加载Turtlebot:
cd gym_gazebo/envs/installation
bash turtlebot_setup.bash

注意:所有设置脚本都可用 gym_gazebo/envs/installation

  • 运行可用的任何示例examples/。例如:
cd examples/turtlebot
python circuit2_turtlebot_lidar_qlearn.py

显示仿真模拟

要在模拟过程中查看Gazebo中发生的情况,请运行gazebo客户端。为了启动gzclient并能够将其连接到运行gzserver

  1. 打开一个新终端。
  2. 获取相应的设置脚本,这将更新GAZEBO_MODEL_PATH变量:例如source setup_turtlebot.bash
  3. 导出gazebo_env提供的GAZEBO_MASTER_URI。您将看到在每个脚本执行开始时打印的变量。例如export GAZEBO_MASTER_URI=http://localhost:13853

注意:现在需要此指令,因为gazebo_env为GAZEBO_MASTER_URI创建了一个随机端口,允许同时运行多个模拟实例。如果您不打算启动多个实例,可以从环境中删除以下两行:

os.environ [ “ ROS_MASTER_URI ” ] = “ http:// localhost:” + self.port
os.environ [ “ GAZEBO_MASTER_URI ” ] = “ http:// localhost:” + self.port_gazebo

最后,启动gzclient。

gzclient

显示奖励细节

通过运行以下脚本显示显示当前奖励历史记录的图表:

cd examples/utilities
python display_plot.py

提示:使用--helpflag来获得更多选项。

杀死后台进程

有时,在结束或杀死模拟gzserverrosmaster留在后台后,请确保在开始新测试之前结束它们。

我们建议创建一个别名来终止这些进程。

echo  “ alias killgazebogym ='killall -9 rosout roslaunch rosmaster gzserver nodelet robot_state_publisher gzclient' ”  >>  〜/ .bashrc

更多详细内容查看英文原文链接!!! 


 

展开阅读全文

没有更多推荐了,返回首页