ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
8

Best practices for setting up catkin_make install for python nodes

asked 2013-04-15 07:19:06 -0500

updated 2014-01-28 17:16:11 -0500

ngrennan gravatar image

I am currently updating my code from rosbuild to catkin as I switch from Fuerte to Groovy.

Current setup: Ubuntu 12.04, Groovy

I am looking for best practices for packages with python nodes and libraries.

This is my current file structure:

/groovy-workspace
    /build
    /devel
    /install
    /src
       /my_meta_pkg
           /my_pkg_A
           /my_pkg B
           /my_pkg_etc...

Under /my_pkg_A:

/scripts
    my_node.py
    my_API.py (my_node imports my_API)
    __init__.py
setup.py
__init__.py
package.xml
CMakeLists.txt

setup.py:

#!/usr/bin/env python

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

d = generate_distutils_setup(
    packages=['my_pkg_A'],
    package_dir={'': 'src'}
)

setup(**d)

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(my_pkg_A)

# Load catkin and all dependencies required for this package
set(CATKIN_DEPS std_msgs geometry_msgs rospy)
set(SYS_DEPS python-serial python-sys)
find_package(catkin REQUIRED COMPONENTS ${CATKIN_DEPS})

# Install python scripts using distutils
catkin_python_setup()

catkin_package(
    DEPENDS ${SYS_DEPS}
    CATKIN_DEPENDS ${CATKIN_DEPS}
)

install(PROGRAMS scripts/my_node.py scripts/my_API.py
  DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
)

When I run

catkin_make install

in /groovy-workspace, it fails during the make sequence with the error

error: package directory 'src/my_pkg_A' does not exist

I have deduced that it is looking for the python scripts in the python workspace

/groovy-workspace/src/my_meta_pkg/my_pkg_A/src/my_pkg_A

Would it be best practice to create this directory and move my_node.py, my_API.py, and __init__.py to this directory? Or should I change setup.py to look at /scripts and what would be the best way to do this? Or is there a different way everything should be structured to follow ROS best practices?

Thanks for the help!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
7

answered 2013-04-15 07:25:36 -0500

William gravatar image

updated 2013-04-15 07:26:57 -0500

Your setup.py is setup to look for the API in src, if you want it to look in scripts then change it to look like this:

#!/usr/bin/env python

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

d = generate_distutils_setup(
    packages=['my_pkg_A'],
    package_dir={'': 'scripts'}
)

setup(**d)

It would be best practice, however, to separate your API and scripts into different folders and the src folder is a good place to place your API files.

edit flag offensive delete link more

Comments

I made this change and it returns the error:error: package directory 'scripts/my_pkg_A' does not exist. Should there be a folder /my_pkg_A/scripts/my_pkg_A? Is that where I should place my_node.py? Would this result in being able to use rosrun my_pkg_A my_node.py after sourcing the install setup?

Brendan Andrade gravatar image Brendan Andrade  ( 2013-04-15 07:31:50 -0500 )edit

So, in python the "name" of your API (package) is the name of the folder containing the __init__.py, so yeah you probably want a sub folder for src which is the name of your package.

William gravatar image William  ( 2013-04-15 07:36:57 -0500 )edit

Would that be considered "best practice" for ROS packages with python nodes?

Brendan Andrade gravatar image Brendan Andrade  ( 2013-04-15 08:39:08 -0500 )edit

Probably so, rosbuild could handle scripts directly under src/, but catkin is not completely compatible in that respect.

joq gravatar image joq  ( 2013-04-15 08:43:22 -0500 )edit

how about adding srv and msg files... how should they be imported?

215 gravatar image 215  ( 2016-11-23 04:59:46 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2013-04-15 07:19:06 -0500

Seen: 8,428 times

Last updated: Apr 15 '13