How to include my python modules in ROS project

asked 2018-11-15 05:41:53 -0600

kump gravatar image

I am working on a project consisting of several ROS package. The goal of the project is to provide all functionality for a robot and is meant to be developed by a team of people. Therefor, I would like all the parts of the project to be accessible from a git repository and easily install and run on any new computer. My own python modules that I might need to use inside those packages therefor needs to be located in the git and accessible from there without any external action. It all needs to be defined inside the packages (no ~/.bashrc modifications).

So far, I have a git repository containing files like this:

├── robot_control
│   ├── package.xml 
│   ├── CMakeLists.txt
│   └── ...
│
├── robot_teleop
│   ├── package.xml 
│   ├── CMakeLists.txt
│   └── ...
│
├── robot_description
│   ├── package.xml 
│   ├── CMakeLists.txt
│   ├── urdf 
│   ├── meshes
│   └── tests
│       ├── test_robot.py (import robot_utils)
│       ├── test_robot.test
│       └── robot_utils (soft symlink <../../lib/robot_utils>)
└── lib
    └── robot_utils
        ├── __init__.py
        └── my_module.py

And I plan to simply put the relative soft symbolic links to every folder containing python scripts that needs to use my python module. This way I think nothing can broke when cloning the project on other computers, but it seems ugly. It seems there should be a better way.

What would you recommend?

edit retag flag offensive close merge delete

Comments

Yes, this is ugly. Why do you want to have this lib folder in there?

The ROS way would be to make robot_utils a ROS package that does only provide the python modules and each package that needs them specifies the dependency towards it.

This way you can getrid of the symlink...

mgruhler gravatar image mgruhler  ( 2018-11-15 08:13:16 -0600 )edit

The ROS way would be to make robot_utils a ROS package that does only provide the python modules

or keep robot_utils as a stand-alone Python library. Then make all ROS pkgs that use it depend on that library.

No need to make a ROS pkg out of robot_utils per se. It's all regular Python.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-15 11:07:48 -0600 )edit

@gvdhoorn. I totally agree.

I specifically left this out and only talked about making it a ROS package as this is all contained in a single repository. I don't see much benefit in having it a non-ROS python library then.

mgruhler gravatar image mgruhler  ( 2018-11-16 00:52:54 -0600 )edit

@gvdhoorn yes, that's what I wanted to do initially, but couldn't find a way how to connect the library to the script in a ROS package without modifying system paths. What do you mean by "make all ROS pkgs (...) depend on that library"? What should this look like?

kump gravatar image kump  ( 2018-11-16 02:04:23 -0600 )edit
1

There is no ROS specific side to this: just make sure you can install your modules as you would normally do with Python (setup.py, use with pip etc).

At that point you can use them just as any other Python module, and your ROS packages should also just be able to do import robot_utils.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-16 02:17:00 -0600 )edit

@gvdhoorn ok, I have managed to make a installable module out of my robot_utils library, but that would require every new ROS-package-user to install this module from that specific folder. I want it to run after first pull without any other interventions.

kump gravatar image kump  ( 2018-11-16 03:53:46 -0600 )edit

That would be impossible in any case, as regardless of whether you make robot_utils a ROS package or not, you'll always have to build the workspace with your other ROS packages.

If building your workspace is acceptable, then making robot_utils a ROS package would be an option.

But ..

gvdhoorn gravatar image gvdhoorn  ( 2018-11-16 03:56:29 -0600 )edit

.. personally I find this an overoptimisation. Setup of a development/runtime environment is typically only done once per user and unless you have really complex dependencies and many, many packages, a few well documented commands -- that can even be copy-pasted -- should not be too difficult.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-16 03:57:33 -0600 )edit