Understanding the catkin, CMakeList, setup.py build flow in Python

asked 2014-10-07 08:46:24 -0500

alainh gravatar image

I'm running Hydro on a Beaglebone Black (since there are no Debian builds for the embedded platform I hacked together my own, the details of which you can find here for reference).

I've been trying to build a simple Python script which publishes IMU data from an I2C interface and uses the the sensor_msgs and geometry_msgs libraries. Currently my project structure is as followed:

~/ros_catkin_ws/src/mypkg
|-- myscript.py 
|-- package.xml
|-- CMakeList.txt
|-- setup.py
+-- src
    +-- mypkg
        +-- myscript.py

In my actual code mypkg is named imuraw_gy88.

package.xml

<package>
    <name>imuraw_gy88</name>
    <version>0.0.1</version>
    <description>
        This package reads raw {accelero/gryo/magno}meter data from the GY88 and publishes it
    </description>
    <maintainer email="email">name</maintainer>
    <license>BSD</license>

    <author>name</author>

    <buildtool_depend>catkin</buildtool_depend>

    <build_depend>rospy</build_depend>
    <build_depend>sensor_msgs</build_depend>
    <build_depend>geometry_msgs</build_depend>
    <build_depend>std_msgs</build_depend>

    <run_depend>rospy</run_depend>
    <run_depend>sensor_msgs</run_depend>
    <run_depend>geometry_msgs</run_depend>
    <run_depend>std_msgs</run_depend>
</package>

CMakeList.txt

## I stripped all comments from this one for readability

cmake_minimum_required(VERSION 2.8.3)
project(imuraw_gy88)

find_package(catkin REQUIRED COMPONENTS
  rospy sensor_msgs geometry_msgs 
)


catkin_python_setup()
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES imuraw_gy88
  CATKIN_DEPENDS rospy sensor_msgs geometry_msgs
#  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

 install(PROGRAMS
   imuraw_gy88.py 
   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
 )

setup.py

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

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

setup(**d)

myscript.py (imuraw_gy88.py)

""" Only including the header for this example as all the other code is application specific """
import rospy
import sensor_msgs.msg # IMU data type
from std_msgs.msg import Header # Header to contain timestamp information
from geometry_msgs.msg import Vector3 # Standard Vector form for ROS

In its current state, using catkin_make_isolated --install --pkg mypkg does cause my package to build. However, what I'm lacking is an understand of whats going on exactly.

Questions

  • There appears to be some redundancy with setup.py. What is it doing? What is it responsible for?
  • Does package.xml actually help the compiler understand the dependencies? Or is it just there for documentation?
  • Why does the Python bits of this need to be run through catkin_make? In particular, how does CMakeList tell Python how to link up dependencies to other packages?
  • What is the correct project structure and workflow for using catkin + Python in ROS?

I would greatly appreciate any guide on how exactly this build system works!

Thank you for your time. :)

edit retag flag offensive close merge delete