-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds the python bindings tutorial #450
Conversation
Signed-off-by: Voldivh <[email protected]>
python/examples/publisher.py
Outdated
@@ -39,10 +38,11 @@ def main(): | |||
while True: | |||
count += 1 | |||
vector3d_msg.x = count | |||
if not (pub_stringmsg.publish(stringmsg_msg) or pub_vector3d.publish(vector3d_msg)): | |||
if not (pub_stringmsg.publish(stringmsg_msg)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can drop the parens now that there is a single condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
python/examples/publisher.py
Outdated
print("Publishing 'Hello' on topic [{}]".format(stringmsg_topic)) | ||
if not (pub_vector3d.publish(vector3d_msg)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/01_intro.md
Outdated
@@ -20,5 +20,5 @@ combination of custom code and [ZeroMQ] (http://zeromq.org/). | |||
|
|||
## What programming language can I use with Gazebo Transport? | |||
|
|||
C++ is the native implementation and so far the only way to use the library. | |||
We hope to offer different wrappers for the most popular languages in the future. | |||
C++ is the native implementation and the only language that have available all library features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++ is the native implementation and the only language that have available all library features. | |
C++ is the native implementation and the only language that has all available library features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/01_intro.md
Outdated
C++ is the native implementation and so far the only way to use the library. | ||
We hope to offer different wrappers for the most popular languages in the future. | ||
C++ is the native implementation and the only language that have available all library features. | ||
Python implementation is a wrapper around C++ methods using pybind11. It does not support all features like C++, but, contains the main features such as publication, subscription and service request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python implementation is a wrapper around C++ methods using pybind11. It does not support all features like C++, but, contains the main features such as publication, subscription and service request. | |
Python implementation is a wrapper around C++ methods using `pybind11`. It does not support all features like C++, but contains the main features such as publication, subscription and service request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/06_python_support.md
Outdated
|
||
In this tutorial, we are going to show the functionalities implemented in python. This features are brought up to python by creating bindings from the C++ implementation using pybind11. It is important to note that not all of C++ features are available yet in python, on this tutorial we will go over the most relevant features we currently have on python. For more information refer to the [__init__.py](https://github.com/gazebosim/gz-transport/blob/gz-transport13/python/src/__init__.py) file which is a wrapper for all the bindings. | ||
|
||
For this tutorial, we will create two nodes that are going to communicate via messages. One node will be a publisher that generates the information, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this tutorial, we will create two nodes that are going to communicate via messages. One node will be a publisher that generates the information, | |
For this tutorial, we will create two nodes that communicate via messages. One node will be a publisher that generates the information, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks and done.
tutorials/06_python_support.md
Outdated
|
||
## Overview | ||
|
||
In this tutorial, we are going to show the functionalities implemented in python. This features are brought up to python by creating bindings from the C++ implementation using pybind11. It is important to note that not all of C++ features are available yet in python, on this tutorial we will go over the most relevant features we currently have on python. For more information refer to the [__init__.py](https://github.com/gazebosim/gz-transport/blob/gz-transport13/python/src/__init__.py) file which is a wrapper for all the bindings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shorten lines
In this tutorial, we are going to show the functionalities implemented in python. This features are brought up to python by creating bindings from the C++ implementation using pybind11. It is important to note that not all of C++ features are available yet in python, on this tutorial we will go over the most relevant features we currently have on python. For more information refer to the [__init__.py](https://github.com/gazebosim/gz-transport/blob/gz-transport13/python/src/__init__.py) file which is a wrapper for all the bindings. | |
In this tutorial, we are going to show the functionalities implemented in python. This features are brought up to python by creating bindings from the C++ implementation using pybind11. It is important to note that not all of C++ features are available yet in Python, on this tutorial we will go over the most relevant features we currently have on Python. For more information refer to the [__init__.py](https://github.com/gazebosim/gz-transport/blob/gz-transport13/python/src/__init__.py) file which is a wrapper for all the bindings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/06_python_support.md
Outdated
from gz.transport13 import Node | ||
``` | ||
|
||
The library `gz.transport13` contains all the Gazebo Transport elements that can be used in python. The final API we will use is contained inside the class `Node`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The library `gz.transport13` contains all the Gazebo Transport elements that can be used in python. The final API we will use is contained inside the class `Node`. | |
The library `gz.transport13` contains all the Gazebo Transport elements that can be used in Python. The final API we will use is contained inside the class `Node`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/06_python_support.md
Outdated
|
||
First of all we declare a *Node* that will offer some of the transport | ||
functionality. In our case, we are interested in publishing topic updates, so | ||
the first step is to announce our topics names and their types. Once a topic name is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first step is to announce our topics names and their types. Once a topic name is | |
the first step is to announce our topics names and their types. Once a topic name is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
We need to register a function callback that will execute every time we receive | ||
a new topic update. The signature of the callback is always similar to the ones |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to register a function callback that will execute every time we receive | |
a new topic update. The signature of the callback is always similar to the ones | |
We need to register a function callback that will execute every time we receive | |
a new topic update. The signature of the callback is always similar to the ones |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/06_python_support.md
Outdated
|
||
## Updating PYTHONPATH | ||
|
||
If you made the binary installation of Gazebo Transport, you can skip this step and go directly to the next section. Otherwise, if you built the package from source it is needed to update the PYTHONPATH in order for python to recognize the library by doing the following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you made the binary installation of Gazebo Transport, you can skip this step and go directly to the next section. Otherwise, if you built the package from source it is needed to update the PYTHONPATH in order for python to recognize the library by doing the following: | |
If you made the binary installation of Gazebo Transport, you can skip this step and go directly to the next section. Otherwise, if you built the package from source it is needed to update the PYTHONPATH in order for Python to recognize the library by doing the following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
```{.sh} | ||
python3 ./data_race_without_mutex.py | ||
``` | ||
or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or | |
or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/06_python_support.md
Outdated
as an argument to the *advertise()* method. | ||
|
||
|
||
## Subscribe Options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as an argument to the *advertise()* method. | |
## Subscribe Options | |
as an argument to the *advertise()* method. | |
## Subscribe Options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Signed-off-by: Voldivh <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have some errors in CI https://github.com/gazebosim/gz-transport/actions/runs/6408005204/job/17396035440?pr=450
Signed-off-by: Voldivh <[email protected]>
friendly ping @Voldivh |
@Voldivh there are still some unresolved comments |
Signed-off-by: Voldivh <[email protected]>
Oh I completely missed that comment, sorry. Take a look now. |
Codecov Report
@@ Coverage Diff @@
## gz-transport13 #450 +/- ##
==================================================
+ Coverage 87.78% 87.79% +0.01%
==================================================
Files 59 59
Lines 5696 5696
==================================================
+ Hits 5000 5001 +1
+ Misses 696 695 -1
|
tutorials/06_python_support.md
Outdated
|
||
## Overview | ||
|
||
In this tutorial, we are going to show the functionalities implemented in python. This features are brought up to python by creating bindings from the C++ implementation using pybind11. It is important to note that not all of C++ features are available yet in Python, on this tutorial we will go over the most relevant features we currently have on Python. For more information refer to the [__init__.py](https://github.com/gazebosim/gz-transport/blob/gz-transport13/python/src/__init__.py) file which is a wrapper for all the bindings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this tutorial, we are going to show the functionalities implemented in python. This features are brought up to python by creating bindings from the C++ implementation using pybind11. It is important to note that not all of C++ features are available yet in Python, on this tutorial we will go over the most relevant features we currently have on Python. For more information refer to the [__init__.py](https://github.com/gazebosim/gz-transport/blob/gz-transport13/python/src/__init__.py) file which is a wrapper for all the bindings. | |
In this tutorial, we are going to show the functionalities implemented in Python. This features are brought up to Python by creating bindings from the C++ implementation using pybind11. It is important to note that not all of C++ features are available yet in Python, on this tutorial we will go over the most relevant features we currently have on Python. For more information refer to the [__init__.py](https://github.com/gazebosim/gz-transport/blob/gz-transport13/python/src/__init__.py) file which is a wrapper for all the bindings. |
tutorials/06_python_support.md
Outdated
|
||
## Running the examples | ||
|
||
Open two new terminals and directly run the python scripts downloaded previously. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open two new terminals and directly run the python scripts downloaded previously. | |
Open two new terminals and directly run the Python scripts downloaded previously. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/06_python_support.md
Outdated
|
||
## Service Responser | ||
|
||
Unfortunately, this feature is not available on python at the moment. However, we can use a service responser created in C++ and make a request to it from a code in python. Taking that into account, we will use the [response.cc](https://github.com/gazebosim/gz-transport/blob/gz-transport13/example/responser.cc) file as the service responser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this feature is not available on python at the moment. However, we can use a service responser created in C++ and make a request to it from a code in python. Taking that into account, we will use the [response.cc](https://github.com/gazebosim/gz-transport/blob/gz-transport13/example/responser.cc) file as the service responser. | |
Unfortunately, this feature is not available on Python at the moment. However, we can use a service responser created in C++ and make a request to it from a code in Python. Taking that into account, we will use the [response.cc](https://github.com/gazebosim/gz-transport/blob/gz-transport13/example/responser.cc) file as the service responser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/06_python_support.md
Outdated
|
||
## Running the examples | ||
|
||
Open a new terminal and directly run the python script downloaded previously. It is expected that the service responser is running in another terminal for this, you can refer to the previous tutorial \ref services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open a new terminal and directly run the python script downloaded previously. It is expected that the service responser is running in another terminal for this, you can refer to the previous tutorial \ref services. | |
Open a new terminal and directly run the Python script downloaded previously. It is expected that the service responser is running in another terminal for this, you can refer to the previous tutorial \ref services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tutorials/06_python_support.md
Outdated
Received Vector3: [x: 4.0, y: 15.0, z: 20.0] | ||
``` | ||
## Threading in Gazebo Transport | ||
The way Gazebo Transport is implemented, it creates several threads each time a node, publisher, subscriber, etc is created. While this allows us to have a better paralization in processes, a downside is possible race conditions that might occur if the ownership/access of variables is shared across multiple processes. Even though python have it's [GIL](https://wiki.python.org/moin/GlobalInterpreterLock), all the available features are bindings created for it's C++ implementation, in other words, downsides commented before are still an issue to be careful. We recommend to always use threading locks when working with object that are used in several places (publisher and subscribers). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way Gazebo Transport is implemented, it creates several threads each time a node, publisher, subscriber, etc is created. While this allows us to have a better paralization in processes, a downside is possible race conditions that might occur if the ownership/access of variables is shared across multiple processes. Even though python have it's [GIL](https://wiki.python.org/moin/GlobalInterpreterLock), all the available features are bindings created for it's C++ implementation, in other words, downsides commented before are still an issue to be careful. We recommend to always use threading locks when working with object that are used in several places (publisher and subscribers). | |
The way Gazebo Transport is implemented, it creates several threads each time a node, publisher, subscriber, etc is created. While this allows us to have a better paralization in processes, a downside is possible race conditions that might occur if the ownership/access of variables is shared across multiple processes. Even though Python have it's [GIL](https://wiki.python.org/moin/GlobalInterpreterLock), all the available features are bindings created for it's C++ implementation, in other words, downsides commented before are still an issue to be careful. We recommend to always use threading locks when working with object that are used in several places (publisher and subscribers). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Signed-off-by: Voldivh <[email protected]>
Thank you @Voldivh |
the first step is to announce our topics names and their types. Once a topic name is | ||
advertised, we can start publishing periodic messages using the publishers objects. | ||
|
||
```{.py} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw you had the directives #! [complete]
in the example code. Would it be possible to do the same for these, so we don't have to duplicate the example code here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean for each or the small parts during the Walkthrough? I did it this way just to keep consistency with it is done on the other tutorials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll approve as is, but I think it's better to use the doxygen trick instead of duplicating the code. The other tutorials should also be doing the same.
Signed-off-by: Voldivh <[email protected]>
friendly ping @azeey |
🎉 New feature
Summary
This PR creates a new tutorial page with all the relevant information regarding the python API created for gz-transport in #411.
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.