0
$\begingroup$

Rosanswers logo

I'm running hydro and switching over from new rosbuild to using catkin. I read through the catkin conceptual overview and tutorials but have trouble implementing.

I'm trying to get the tilting hokuyo set up. I 'catkinized' the hrl_hardware_drivers but having trouble with the hrl_lib. It wasn't included in the package so I found it externally. When I run:

rosrun hrl_hokuyo hokuyo_processing.py

It goes me the error:

src/hrl_hokuyo/hokuyo_processing.py", line 43, in import hrl_lib.transforms as tr ImportError: No module named hrl_lib.transforms

I believe the cmakelist and package.xml file was edit appropriately to include hrl_lib. I want to do it right and not just add the hrl_lib folder into the directory.

Thanks!

Heres is the cmake

cmake_minimum_required(VERSION 2.8.3)
project(hrl_hokuyo)

find_package(catkin REQUIRED COMPONENTS hokuyo_node sensor_msgs rospy hrl_lib)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

catkin_package(
    DEPENDS hokuyo_node sensor_msgs rospy hrl_lib
    CATKIN_DEPENDS # TODO
    INCLUDE_DIRS # TODO
    LIBRARIES # TODO
)

Here is the package.xml

<package>
  <name>hrl_hokuyo</name>
  <version>1.0.0</version>
  <description>Python class that uses hokuyo_node from ros-pkg to get scans from
  UTMs and player to get scans from URGs.</description>
  <maintainer email=""></maintainer>

  <license>New BSD</license>

  <url type="website"></url>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>hokuyo_node</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>hrl_lib</build_depend>

  <run_depend>hokuyo_node</run_depend>
  <run_depend>sensor_msgs</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>hrl_lib</run_depend>

</package>

Edit #1

I'm still having trouble with it. Is the hrl_lib package just a folder with the python files in it? This doesn't feel right since there are other folders with the library as well. Here is my structure:

/path_to_workspace/
    /src
        /hrl_hokuyo
            /setup.py
            /src
                /hrl_hokuyo
                /hrl_lib

Thanks for the quick response and breaking it down for me.

Edit#2

I didn't edit it much except just setting the path.

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

d = generate_distutils_setup(
    packages=['hrl_lib'],
    package_dir={'/path_to_directory_containing_hrl_lib/': 'src'}
)

setup(**d)

Originally posted by pwong on ROS Answers with karma: 447 on 2013-10-22

Post score: 0


Original comments

Comment by pwong on 2013-10-22:
Thanks for the comment and telling me the preferred method to posting responses!

Comment by William on 2013-10-22:
Can you post your setup.py? It is likely that you are not declaring your packages correctly.

Comment by William on 2013-10-22:
Another option is for you to push this to github (or something similar) and point me to it.

Comment by pwong on 2013-10-22:
I'll work on putting this onto github

Comment by William on 2013-10-22:
I think you have the package_dir wrong, see my edit to my question and this: http://docs.python.org/2/distutils/setupscript.html#listing-whole-packages

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

In order to export python libraries you need to do two things:

  • Setup a setup.py file describing which Python packages your package has
  • Call the catkin_python_setup() macro in your CMakeLists.txt

Reference: http://docs.ros.org/api/catkin/html/user_guide/setup_dot_py.html

The setup.py should be in the root of your package and look like this:

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

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

setup(**d)

Where...

    packages=['mypkg'],

'mypkg' is the name of the python package you want, in your case probably 'hrl_lib', and...

    package_dir={'': 'src'}

'src' is the folder in your package where you keep these packages, so your folder structure would be:

/path/to/my/package
                   /setup.py
                   /src
                       /hrl_lib
                               /__init__.py
                               ...

And in your CMakeLists.txt you need to call before catkin_package(...):

catkin_python_setup()

Also, get rid of these lines:

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

This was someting that rosbuild had you do, but you shouldn't do this in catkin.

EDIT:

I would expect your setup.py to look like this:

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

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

setup(**d)

Originally posted by William with karma: 17335 on 2013-10-22

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by pwong on 2013-10-23:
Without the package path at package_dir it works. Thank you!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.