How to include my python modules in ROS project
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?
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...
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. 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.
@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?
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 withpip
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 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.
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 ..
.. 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.