ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How should I best add a python node to a cpp package?

asked 2014-04-30 13:18:34 -0600

blakeh gravatar image

updated 2022-01-22 16:16:26 -0600

Evgeny gravatar image

I have built a C++ package that integrates with turtle_sim and does some cool stuff. Now I'd like it to communicate (via ros::service) with a new python node. Should I add that in /scripts of the existing package (not working, cmake issues with catkin_make) or make a new package (next to existing package in /src)??



edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-04-30 20:12:58 -0600

Jacco van der Spek gravatar image

Both can be done. You should be able to just put the Python script in /scripts. Make sure that you advertise your service in the Python script and subscribe to it in your C++ main/class.

If you get catkin_make errrors check if your package.xml and CMakelist.txt both contain rospy as depend package.

edit flag offensive delete link more


Thank you! This moved me on to the next level of errors. I did not have rospy properly in my dependencies. I added them in CMakelist.txt right next to where roscpp was, (and corrected a typo in package.xml!). catkin_make error message was totally misdirecting so thanks again!

blakeh gravatar image blakeh  ( 2014-05-01 05:46:59 -0600 )edit

OK - on to next question. How do I set up the service in cpp code template which references a python service? The example for cpp client requires a .h file for the service: 2 #include "beginner_tutorials/AddTwoInts.h" 15 ros::ServiceClient client = n.serviceClient<beginner_tutorials::addtwoints>("add_two_ints"); Thanks again!

blakeh gravatar image blakeh  ( 2014-05-01 05:52:09 -0600 )edit

If you're satisfied with the answer, you can accept it.

Jacco van der Spek gravatar image Jacco van der Spek  ( 2014-05-02 03:29:29 -0600 )edit

Actually it's still unresolved. I guess I forked this to a diffferent question where I commented: The key to this turned out to be finding "AddTwoInts.h". despite triple checking my CMakelists.txt and package.xml files I could not get catkin to "autogenerate" this file. Instead I found it in the hydro examples and used it as is. This then worked. Not a satisfactory solution! (there is an earlier question from 2011 with this same issue which was never answered!)

blakeh gravatar image blakeh  ( 2014-05-02 06:33:03 -0600 )edit

Ok I suppose you added it as a service in your CMakeList.txt? Furthermore you should also do message_generation in in add_dependencies. Then what you also need to do in hydro is add message_generation as a build_depend and as required component.

Jacco van der Spek gravatar image Jacco van der Spek  ( 2014-05-02 07:22:44 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2014-04-30 13:18:34 -0600

Seen: 769 times

Last updated: Apr 30 '14