gazebosim / gz-transport

Transport library for component communication based on publication/subscription and service calls.
https://gazebosim.org
Apache License 2.0
29 stars 36 forks source link

Python Bindings for Publisher, Subscriber and Service Request features. #411

Closed Voldivh closed 12 months ago

Voldivh commented 1 year ago

🎉 New feature

Closes #387

Summary

This PR creates the python bindings for the publisher, subscriber and request features from the repository. In order to avoid creating a new dependency to be able to create python bindings from protobuf messages, it was decided to use the methods that publishes, subscribes and make services request with serialized messages, i.e, use the methods PublishRaw, SubscribeRaw and RequestRaw. The bindings for these methods are wrapped by python methods in order to give the user an API similar to the one we have in C++.

We would like to acknowledge and give credit to @srmainwaring for his code which served as a reference and inspiration for this implementation. The main difference with this implementation is that we are using the methods that uses serialized messages instead of creating bindings with the pybind11_protobuf library to the non-serialized methods.

Test it

There are some examples that were created as smoke test in order to test out the functionality. In order to use them you would have to:

  1. Compile from source this branch
  2. Update the PYTHONPATH variable:
    export PYTHONPATH=$PYTHONPATH:<path_to_ws>/install/lib/python
  3. Run the python script for the example you would like to try out:
    python3 <path_to_ws>/src/gz-transport/python/examples/<example_to_run>

    Note: The service requester example will only work if there is a server running that listens to /echo topic and expects a gz.messages.StringMsg as the request. One way to do so is to follow the instructions on the examples folder and run the responser executable.

codecov[bot] commented 1 year ago

Codecov Report

Merging #411 (2c1f3dd) into main (917bf04) will decrease coverage by 0.33%. The diff coverage is 74.26%.

:exclamation: Current head 2c1f3dd differs from pull request most recent head 5371b41. Consider uploading reports for the commit 5371b41 to get more accurate results

@@            Coverage Diff             @@
##             main     #411      +/-   ##
==========================================
- Coverage   87.43%   87.11%   -0.33%     
==========================================
  Files          60       61       +1     
  Lines        5291     5462     +171     
==========================================
+ Hits         4626     4758     +132     
- Misses        665      704      +39     
Impacted Files Coverage Δ
python/src/transport/_gz_transport_pybind11.cc 74.26% <74.26%> (ø)

... and 4 files with indirect coverage changes

azeey commented 1 year ago

This requires https://github.com/gazebosim/gz-msgs/pull/355.

Voldivh commented 1 year ago

Added the python version example of https://github.com/gazebosim/gz-sim/tree/main/examples/standalone/multi_lrauv_race in https://github.com/gazebosim/gz-transport/pull/411/commits/2f23947262eb71c4b43c6e16705fc5565ee5f2ad using the bindings created on this PR. In order to run it follow the next steps, this takes into account that you have Gazebo installed and gz-transport package compiled:

  1. Launch the world (This would require to have the source code of gz-sim on the main branch):
    gz sim <path_to_ws>/src/gz-sim/examples/worlds/multi_lrauv_race.sdf
  2. Update the PYTHONPATH variable:
    export PYTHONPATH=$PYTHONPATH:<path_to_ws>/install/lib/python
  3. Run the python script for the example:
    python3 <path_to_ws>/src/gz-transport/python/examples/multi_lrauv_race.py
Voldivh commented 1 year ago

I have one test failure. Not sure if it's failing for you. Also, I know I asked you to rebase this to work with new message generation framework in gz-msgs. But since that's been reverted, could you also revert the change here? I plan to open a gz-msgs PR that uses the old message generation framework and adds python bindings.

No problem, just one question then, should I change this PR to target the main branch as before then?

azeey commented 1 year ago

I have one test failure. Not sure if it's failing for you. Also, I know I asked you to rebase this to work with new message generation framework in gz-msgs. But since that's been reverted, could you also revert the change here? I plan to open a gz-msgs PR that uses the old message generation framework and adds python bindings.

No problem, just one question then, should I change this PR to target the main branch as before then?

Yes, target the main branch.

azeey commented 1 year ago

@osrf-jenkins run tests please

azeey commented 1 year ago

Needs https://github.com/gazebo-release/gz-msgs10-release/pull/6 for CI.

azeey commented 1 year ago

I've built gz-msgs10 debians just for Jammy for testing and added a new dependency in https://github.com/gazebosim/gz-transport/pull/411/commits/e1bca5ec9b41c9569618fc83317c9a6f188e9102. It looks like tests are passing on Jenkins 🎉

azeey commented 1 year ago

https://github.com/gazebo-release/gz-msgs10-release/pull/6 is merged and I've built the debs for Focal and Jammy, so I'll run tests again.

@osrf-jenkins run tests please

azeey commented 1 year ago

@osrf-jenkins run tests please