DFKI-NI / mobipick_labs

Other
4 stars 1 forks source link

ImportError in uplexmo demo. #17

Closed sebastianstock closed 1 year ago

sebastianstock commented 1 year ago

When starting the uplexmo demo in simulation (rosrun tables_demo_planning uplexmo_pick_n_place_demo_node.py) I get an ImportError for PickAndPlaceDomain:

File "/home/sebastian/ros/mobipick_labs/devel/lib/tables_demo_planning/uplexmo_pick_n_place_demo_node.py", line 15, in <module>
    exec(compile(fh.read(), python_script, 'exec'), context)
  File "/home/sebastian/ros/mobipick_labs/src/mobipick_labs/tables_demo_planning/nodes/uplexmo_pick_n_place_demo_node.py", line 24, in <module>
    from pick_n_place_demo_node import PickAndPlaceDomain
ImportError: cannot import name 'PickAndPlaceDomain' from 'pick_n_place_demo_node' (/home/sebastian/ros/mobipick_labs/devel/.private/tables_demo_planning/lib/tables_demo_planning/pick_n_place_demo_node.py)

This happens in a completely new ROS workspace that only used the install and build scripts to install.

sebastianstock commented 1 year ago

It works if it is started directly from Python without rosrun (python nodes/uplexmo_pick_n_place_demo_node.py)

mintar commented 1 year ago

I'm not 100% sure what's going on here, but I dimly remember that any Python code that you want to import should go into the src folder. One node shouldn't import another node.

In the core ROS repos, they take this to the extreme. Usually almost all code is in the src folder, and the nodes in the nodes or scripts folders only have a main that imports and runs the stuff from the src folder. For example:

https://github.com/ros/joint_state_publisher/blob/c3e2ad2c8504cfd428732feb20c3abe64127dff9/joint_state_publisher/scripts/joint_state_publisher

alexander-sung commented 1 year ago

Good to know. Unfortunately, I encounter more and more cases in which Python behaves differently depending on how you do things. In this case, we'll refactor pick_n_place_demo_node.py to pick_n_place_demo.py in src for most of the code and let both nodes import it, right? Just according to Martin's references. Will you do it, @sebastianstock?

sebastianstock commented 1 year ago

Good to know. Unfortunately, I encounter more and more cases in which Python behaves differently depending on how you do things. In this case, we'll refactor pick_n_place_demo_node.py to pick_n_place_demo.py in src for most of the code and let both nodes import it, right? Just according to Martin's references. Will you do it, @sebastianstock?

Yes, that makes sense. I was thinking the same. Importing the pick_n_place_demo_node was not ideal in the first place. I can do that.