Exercise 2.5b how to import new robot env?


I’m trying to solve the exercise 2.5b

Next, you will need to make sure that the Task Environment is correctly importing and using your new Robot Environment file, my_cartpole_robot_env.py . Also, you will need to modify some references in the Task Environment to the old Robot Environment file.

from my understanding i have to change this line:
from openai_ros.robot_envs import cartpole_env

so i tried changing it to
from my_cartpole_robot_env.robot_envs import cartpole_env

but it returns this error
ImportError: No module named robot_envs
[cartpole_gym-1] process has died [pid 3692, exit code 1, cmd /home/user/catkin_ws/src/my_cartpole_training/src/start_training.py __name:=cartpole_gym __log:=/home/user/.ros/log/a3666ac4-bcfa-11ea-9159-0ea0d695300e/cartpole_gym-1.log].
log file: /home/user/.ros/log/a3666ac4-bcfa-11ea-9159-0ea0d695300e/cartpole_gym-1*.log
all processes on machine have died, roslaunch will exit

i’m not sure how to do this exercise… please help

Hi @is0485pp

the structure in the openai_ros package is different. In an import line you always have to start with the package name, if it’s from a different package. So here it would be:
from 'you_package_name' import my_cartpole_robot_env

thank you for the reply! unfortunately i got a new error thats

ImportError: No module named my_cartpole_training

is there any way i can fix this error? I’ve tried adding ‘.robot_envs’ in the back but it doesnt work either. thank you so much!

Did you compile your workspace and sourced the setup.bash?

i did but it still doesnt work… and this might just be my feeling but the result of the catkin_make was very short compared to the ros 5 days lesson

Base path: /home/user/catkin_ws
Source space: /home/user/catkin_ws/src
Build space: /home/user/catkin_ws/build
Devel space: /home/user/catkin_ws/devel
Install space: /home/user/catkin_ws/install
#### Running command: "make cmake_check_build_system" in "/home/user/catkin_ws/build"
#### Running command: "make -j2 -l2" in "/home/user/catkin_ws/build"

try deleting the build and devel folder and running catkin_make again. Also check that the package names in the package.xml and CMakeLists.txt are correct. Copy pasting those two files from previous packages, can be a common source of mistakes. The package name is defined in these files, NOT in the name of the folder.

hello, I’ve tried deleting both the build and devel and running the catkin_make but it still doesnt work. I didnt change anything in the package.xml and CMakeLists.txt, so they were there from when i did the catkin_create_pkg. am i supposed to modify the files like in actions?

You might have to, all the dependencies have to be met. Did you compile successfully? can you use roscd to move to the package directory?

the compile was successful, but it was as short as i said before and still doesnt work. I can use roscd to move to the my_cartpole_training too

I tried to uncomment these two lines in the CMakeLists.txt catkin_package but it still does not work
LIBRARIES my_cartpole_training
CATKIN_DEPENDS openai_ros rospy

what exactly is the line in your code that throws the error?

its this one
Traceback (most recent call last):
File “/home/user/catkin_ws/src/my_cartpole_training/src/start_training.py”, line 10, in
import my_cartpole_task_env
File “/home/user/catkin_ws/src/my_cartpole_training/src/my_cartpole_task_env.py”, line 3, in
from my_cartpole_training import my_cartpole_robot_env
ImportError: No module named my_cartpole_training

I’m not sure why you get this error, but you could try simply importing it directly, without specifying the package, as it is located in the same. So simply:
import my_cartpole_robot_env

it works now! thank you so much!