Ask Your Question
0

ROS2 Services in Python

asked 2019-05-08 19:19:45 -0500

stbuebel gravatar image

Hello,

I have been looking everywhere for documentation on how to add .srv files to a workspace when using the Python build system for ROS2. I assume something needs to go in the setup.py (as well as the package.xml) but don't know what to add.

To be clear, I just want to define a simple service.srv for use in my custom package, and can't figure out how to import my service into my python script (seems like documentation on this is sparse...).

Thanks in advance!

edit retag flag offensive close merge delete

Comments

1

It would perhaps be good to use a separate package to store your service definition. It's a best practice in any version of ROS as it makes it possible to use your service definition (and by that being able to invoke your service) wthout having to build (or even have access to) your Python package.

gvdhoorn gravatar imagegvdhoorn ( 2019-05-09 05:22:56 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2019-05-08 19:31:01 -0500

Dirk Thomas gravatar image

You can't define messages and services in a pure Python package. The reason is that for every interface file the types for various languages needs to be generated (even if you only want to use Python). All that logic is only available in CMake packages since it requires to compile c and C++ libraries etc.

edit flag offensive delete link more
1

answered 2019-05-08 19:30:40 -0500

William gravatar image

I don't believe we support message generation from a pure Python package. You have to use CMake if you want to define new message or service types.

The reason for this is likely that we need to generate (and sometimes compile) code for each support language when you define a new message or service, and we only have infrastructure to do that in CMake.

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

Stats

Asked: 2019-05-08 19:19:45 -0500

Seen: 37 times

Last updated: May 08