Gym and Gazebo

2 minute read


  • Getting familiar with the tools we will be using
  • Write some definitions about the tools.
  • Install the tools.
  • Reproduce an example.


OpenAI Gym

OpenAI Gym is a framework to test and developed reinforcement learning algorithms, it includes many environments like the Atari games [1].



Is an open-source 3D robotics simulator, and it is integrated with ROS [2] .

Behaviour Studio

Is a tool that will benchmark different algorithms for autonomous driving using Jderobot tools [3].

Using Behaviour Studio, Gym and Gazebo

I used the installation guide from Ignacio Arranz’s master thesis repository. I only pasted here the installation commands, there are more for display and running environments in the Ignacio’s repository I mentioned before [5].


ROS Melodic and Gazebo 9.0 in Ubuntu 18.04

ROS wiki

sudo sh -c 'echo "deb $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc


git clone
cd 2019-tfm-ignacio-arranz/gym-gazebo
virtualenv -p python3 gazebo-gym
source gazebo-gym/bin/activate
pip install -r requirements.txt
pip install -e .

Adding more packages needed

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                       \

Problems encountered


I got this error, because my tf2_ros was working with python2

ImportError: dynamic module does not define module export function (PyInit__tf2)

I tried many possible solutions like these.

Attempted solution

Then reading other solutions I found out that my problem might have been caused because I was using conda, so I did a clean docker installation and it worked!.

Environment variables

Loading the environment variables returned this message

bash formula1_setup.bash
cp: cannot stat '../assets/urdf/kobuki_nn_urdf/urdf/': No such file or directory                       
cp: cannot stat '../assets/meshes/lidar_lite_v2_withRay.dae': No such file or directory

I found the missing files in the gym-gazebo repository from erlerobot, so I copied to the Ignacio’s repository and the bash ran correctly now.

git clone
cp -r gym-gazebo/gym_gazebo/envs/assets/meshes/ 2019-tfm-ignacio-arranz/gym-gazebo/gym-gazebo/envs/assets/
cp -r gym-gazebo/gym_gazebo/envs/assets/urdf/ 2019-tfm-ignacio-arranz/gym-gazebo/gym-gazebo/envs/assets/

Python 2 syntax

In order to run the code using python3 a few changes were made like changing xrange for range.

Environment variable not set

RLException: Invalid <arg> tag: environment variable 'GYM_GAZEBO_WORLD_CIRCUIT_F1' is not set.

Arg xml is <arg default="$(env GYM_GAZEBO_WORLD_CIRCUIT_F1)" name="world_file"/>
The traceback for the exception was written to the log file
export GYM_GAZEBO_WORLD_CIRCUIT_F1=/root/2019-tfm-ignacio-arranz/gym-gazebo/gym_gazebo/envs/assets/worlds/


Turtlebot example

cd gym_gazebo/envs/installation
bash setup_melodic.bash
bash turtlebot_setup.bash
cd agents/turtlebot


Formula 1 example

cd gym_gazebo/envs/installation
bash setup_melodic.bash
bash formula1_setup.bash
cd agents/f1


Stopping the training

echo "alias killgazebogym='killall -9 rosout roslaunch rosmaster gzserver nodelet robot_state_publisher gzclient'" >> ~/.bashrc


I opened an issue for the missing files issue.


[1] Greg Brockman, et al. “OpenAI Gym” 2016.

[2] Andrew Howard, et al. “Gazebo” 2002 at the University of Southern California.

[3] Jderobot, BehaviorStudio (BehaviorSuite)

[4] Ignacio Arranz’s master thesis repository

[5] Gym-gazebo

[6] OpenCV with python3