Cant run openai_ros CartPoleStayUp-v0 localy when using openia_ros version 2

I am trying to set up the CartPoleStayUp example from the using ros with openai course on my own laptop. To do this I download both the openai_tutorial_xamples and the cart_pole simulation in a catkin_ws. I then build the catkin p installed the ROS dependencies using rosdep install --from-path ./src --ignore-src --rosdistro=melodic --os=ubuntu:bionic. However when I try to launch the example using the roslaunch cartpole_openai_ros_examples start_training_original_qlearn.launch command I get the following error:

Traceback (most recent call last):
  File "/home/ricks/Development/robot_academy_ws/src/cartpole_openai_ros_examples/scripts/start_training_original_qlearn.py", line 29, in <module>
    env = gym.make('CartPoleStayUp-v0')
  File "/home/ricks/venvs/cart_pole_venv/local/lib/python2.7/site-packages/gym/envs/registration.py", line 142, in make
    return registry.make(id, **kwargs)
  File "/home/ricks/venvs/cart_pole_venv/local/lib/python2.7/site-packages/gym/envs/registration.py", line 86, in make
    spec = self.spec(path)
  File "/home/ricks/venvs/cart_pole_venv/local/lib/python2.7/site-packages/gym/envs/registration.py", line 128, in spec
    raise error.UnregisteredEnv('No registered env with id: {}'.format(id))
gym.error.UnregisteredEnv: No registered env with id: CartPoleStayUp-v0

When I switch the openai_ros to version 1 instead of version 2 the error is not present and the simulation does load succesfully. Can anybody maybe explain to me how to use the Cartpole 3D environment together with openai_ros version 2? In the documentation, it says the robot environment should be downloaded automatically.

I found the solution to my answer inside the openai_ros turtlebot tutorial. When working with version 2 you have to add the following lines to your learning_algorithm yaml file:

    task_and_robot_environment_name: 'CartPoleStayUp-v0'
    ros_ws_abspath: '/home/user/simulation_ws'

Additionally you have to add the following code to your python AI RL script, before using the openai environment:

from openai_ros.openai_ros_common import StartOpenAI_ROS_Environment # Init OpenAI_ROS ENV task_and_robot_environment_name = rospy.get_param('/turtlebot2/task_and_robot_environment_name')
env = StartOpenAI_ROS_Environment(task_and_robot_environment_name)
3 Likes