How to share common lib's in ROS workspace
I'm having several packages in my workspace and I'm currently at the point where a want to avoid code duplicity. At the moment I have package called myproject_common
in which all msg
and srv
files are located. After building the workspace they are properly available in all my other packages. Now I want to my common .py files into the common packages and also make them available. After calling catkin_make
the msg
and srv
classes are available under ./devel/lib/python2.7/dist-packages/
which is quiet nice because this makes them also available in my IDE without the need to import something manually. How can I accomplish this with self written common python files? What do I need to change in my CMakeLists.txt
to get this working
edit:
I separated the msg
/ srv
from the common modules, because the msg
/ srv
stuff work fine so now my pkg with the shared modules is named myproject_common_lib
this is my directory structure
myproject_common_lib
├── CMakeLists.txt
├── package.xml
├── setup.py
└── src
└── myproject_common_lib
├── coordinate.py
├── coordinate.pyc
└── __init__.py
2 directories, 6 files
The content of my __init__.py
looks like this
from coordinate import Coordinate
The content of my setup.py
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
# fetch values from package.xml
setup_args = generate_distutils_setup(
packages=['myproject_common_lib'],
package_dir={'': 'src'},
)
setup(**setup_args)
The content of my CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(myproject_common_lib)
find_package(catkin REQUIRED COMPONENTS
rospy
)
catkin_python_setup()
catkin_package()
include_directories(
$(catkin_INCLUDE_DIRS)
)
When I want to import the shared module I use the following import (which does not work)
from myproject_common_lib.coordinate import Coordinate
The content of my devel
folder looks like this (short version)
devel
├── lib
│ └── python2.7
│ └── dist-packages
│ └── myproject_common_lib
│ ├── __init__.py
│ └── __init__.pyc
└── share
├── myproject_common_lib
│ └── cmake
│ ├── myproject_common_libConfig.cmake
│ └── myproject_common_libConfig-version.cmake
I cannot see any difference to the posted tutorial. Also when watching this video I cannot see any difference :-(
edit 2:
This is what PyCharm sees