测试和调试环境:Ubuntu 18.04.2 LTS
gym-gazebo支持ROS Melodic(1.0),gym-gazebo2支持ROS Crystal(2.0)
https://github.com/erlerobot/gym-gazebo(ROS 1)
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需要熟悉这些工具。
基本要求
● ROS Melodic:推荐使用Desktop-Full Install,包括Gazebo 9.0.0 (http://wiki.ros.org/melodic/Installation/Ubuntu)。
● Gazebo 9.0.0
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来获得更多选项。
杀死后台进程
有时,在结束或杀死模拟gzserver并rosmaster留在后台后,请确保在开始新测试之前结束它们。
我们建议创建一个别名来终止这些进程。
echo “ alias killgazebogym ='killall -9 rosout roslaunch rosmaster gzserver nodelet robot_state_publisher gzclient' ” >> 〜/ .bashrc
更多详细请参考:https://github.com/erlerobot/gym-gazebo#usage