Skip to content

Commit 132b35b

Browse files
author
Felix Widmaier
committed
Fix README markdown.
1 parent cffd12c commit 132b35b

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

README.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,38 @@ Using Boost::Python with catkin
22
===============================
33

44
This is a minimal example of how to use Boost::Python in a catkin package.
5-
As there is little helpful documentation about this topic on the internet, I try to summarize
6-
all necessary steps here.
5+
As there is little helpful documentation about this topic on the internet, I
6+
try to summarize all necessary steps here.
77

8-
First you need some C++ code. `src/mycpplib.cpp` contains a simple hello world function that is
9-
made available for Python using Boost::Python. (see documentation of Boost::Python for more
10-
details on how to use it).
8+
First you need some C++ code. `src/mycpplib.cpp` contains a simple hello world
9+
function that is made available for Python using Boost::Python. (see
10+
documentation of Boost::Python for more details on how to use it).
1111

12-
To compile it and make it available for python, some configuration in the CMakeLists.txt has to
13-
be done:
12+
To compile it and make it available for python, some configuration in the
13+
CMakeLists.txt has to be done:
1414

1515

1616
Configure cmake
1717
---------------
1818

1919
1. You need Boost::Python and the path to the python include dirs:
20+
2021
find_package(Boost REQUIRED COMPONENTS python)
2122
find_package(PythonLibs REQUIRED) # sets ${PYTHON_INCLUDE_DIRS}
23+
2224
Make sure to add them to the include directories:
25+
2326
include_directories(
2427
${catkin_INCLUDE_DIRS}
2528
${Boost_INCLUDE_DIRS}
2629
${PYTHON_INCLUDE_DIRS}
2730
)
28-
2. uncomment `catkin_python_setup()`. This will set up the destination path of the python
29-
module. You also need a basic _setup.py_ in the packages root directory.
31+
32+
2. uncomment `catkin_python_setup()`. This will set up the destination path of
33+
the python module. You also need a basic _setup.py_ in the packages root
34+
directory.
3035
3. add a library:
36+
3137
add_library(mycpplib SHARED
3238
src/mycpplib.cpp
3339
)
@@ -40,45 +46,50 @@ Configure cmake
4046
PREFIX ""
4147
LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION}
4248
)
43-
The last command is important because it will change the destination of the compiled library
44-
from `/catkin_ws/devel/lib/` to `/catkin_ws/devel/lib/python2.7/dist-packages/` so it can be
45-
found by python.
46-
Also don't forget the `SHARED` in `add_library`.
49+
50+
The last command is important because it will change the destination of the
51+
compiled library from `/catkin_ws/devel/lib/` to
52+
`/catkin_ws/devel/lib/python2.7/dist-packages/` so it can be found by
53+
python. Also don't forget the `SHARED` in `add_library`.
4754

4855

4956
Use the module
5057
--------------
5158

52-
After you compiled the package, you should be able to use the wrapped module in Python:
59+
After you compiled the package, you should be able to use the wrapped module in
60+
Python:
5361

54-
import boostpy_test.libmycpplib as cpp
55-
cpp.hello()
62+
import boostpy_test.libmycpplib as cpp
63+
cpp.hello()
5664

5765

5866
Boost::Python and ROS::NodeHandle
5967
---------------------------------
6068

61-
When using ROS, there is one important thing to keep in mind: Assume you have a ROS node written
62-
in Python, that uses some C++ code via Boost::Python.
63-
If the C++ code needs a `ros::NodeHandle`, for example to fetch some parameters from the
64-
parameter server, it will crash, because the `rospy.init_node()' does **not** initialize roscpp!
69+
When using ROS, there is one important thing to keep in mind: Assume you have a
70+
ROS node written in Python, that uses some C++ code via Boost::Python. If the
71+
C++ code needs a `ros::NodeHandle`, for example to fetch some parameters from
72+
the parameter server, it will crash, because the `rospy.init_node()` does
73+
**not** initialize roscpp!
6574

66-
To get around this, you need the _MoveIt ROS planning interface_ which is available in the ROS
67-
repos (`sudo apt-get install ros-groovy-moveit-ros-planning-interface`). Once installed, add
68-
the following code to your Python node:
75+
To get around this, you need the _MoveIt ROS planning interface_ which is
76+
available in the ROS repos
77+
(`sudo apt-get install ros-groovy-moveit-ros-planning-interface`).
78+
Once installed, add the following code to your Python node:
79+
80+
from moveit_ros_planning_interface._moveit_roscpp_initializer import roscpp_init
81+
roscpp_init('node_name', [])
6982

70-
from moveit_ros_planning_interface._moveit_roscpp_initializer import roscpp_init
71-
roscpp_init('node_name', [])
72-
7383
Now everything should work fine.
7484

85+
7586
References
7687
----------
7788

7889
Some references that were helpful for me in one or the other way:
7990

80-
* This page, that I unfortunatly only found after I figured most of it out by myself, should
81-
explain everything...
91+
* This page, that I unfortunatly only found after I figured most of it out by
92+
myself, should explain everything...
8293
http://wiki.ros.org/ROS/Tutorials/Using%20a%20C%2B%2B%20class%20in%20Python
8394
* Boost::Python documentation: http://www.boost.org/doc/libs/1_57_0/libs/python/doc/index.html
8495
* Using Boost::Python with cmake: https://www.preney.ca/paul/archives/107

0 commit comments

Comments
 (0)