Ask Your Question
1

ros2: C++ and Python in same package. Is it possible?

asked 2018-07-26 09:35:07 -0500

Anis gravatar image

Hi

In ROS1, it was possible to have Python script in any package that contains C++ or Python, but in ROS2, it seems we need separate packages for Python and C++, which I do not find practical.

Is there any reason of not having the possibility to create one package for both C++ and Python?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-07-26 10:06:53 -0500

sloretz gravatar image

It is possible to create a package having multiple programming languages. rclpy is a ROS 2 package containing both python and C. The same could be done with C++ and python.

In ROS 1 using catkin and calling catkin_python_setup() in a CMakeLists.txt causes a setup.py file to be called, but the CMake code has to be there even if the package has no C or C++ code. In ROS 2 a package can be pure python.

edit flag offensive delete link more

Comments

1

In ROS 2 a CMake project can install Python packages and modules (see https://github.com/ament/ament_cmake/... ) but it does provide a mechanism to invoke a setup.py file.

Dirk Thomas gravatar imageDirk Thomas ( 2018-07-26 11:36:15 -0500 )edit

While that could be implemented similar as it is in catkin it is fairly complex and the catkin implementation as several severe limitations. Therefore it hasn't been done until now.

Dirk Thomas gravatar imageDirk Thomas ( 2018-07-26 11:37:03 -0500 )edit

can we build demo_nodes_cpp and demo_nodes_py into one project as demo_nodes_test and run "ros2 run demo_nodes_test listener.py"(run python listener) or " ros2 run demo_nodes_test listener "(run c++ listener) ? I don't know how to install python executable with ament_cmake .

lxbeyond gravatar imagelxbeyond ( 2018-08-09 02:42:17 -0500 )edit
0

answered 2018-12-23 23:50:02 -0500

tanyouliang gravatar image

It can be done. I created a sample ROS2 pkg with .cpp and .py script in it, setup.py is not required in this case. Here, the CMakeLists.txt needs to be slightly modified, and an empty __init__.py is used. You can refer to my sample code here:

https://github.com/tanyouliang95/MySa...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-07-26 09:35:07 -0500

Seen: 651 times

Last updated: Jul 26 '18