Skip to content

Commit

Permalink
Almost done with Alex's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
hman523 committed Jul 28, 2020
1 parent bf6f629 commit 523f0e3
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 12 deletions.
24 changes: 24 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. py:currentmodule:: rti.connextdds
Examples
~~~~~~~~

Getting Started Guide
=====================

The RTI Getting Started Guide can be found
`here <https://github.com/rticommunity/rticonnextdds-getting-started>`_.
It is recommended that you clone the repository.
After cloning, you should enter the folder 1_hello_world/python and
there will be a readme. The readme will include instructions for
how to go through the example.
For a full walkthrough, you can go
`here <https://community.rti.com/static/documentation/connext-dds/6.0.1/doc/manuals/connext_dds/getting_started/index.html>`_.
This is the Getting Started Guide for Modern C++. The Python Guide is a translation
of the Modern C++ version so the Modern C++ Getting Started Guide is a great resource.

Python Examples
===============

Some Python Examples can be found in the connextdds-py repository
`here <https://github.com/rticommunity/connextdds-py/tree/master/examples>`_.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ or the full :ref:`API reference <rti:rti package>`.
building.rst
overview.rst
API Reference <rti.rst>
examples.rst

Indices and tables
==================
Expand Down
26 changes: 24 additions & 2 deletions docs/source/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,37 @@ Introduction

Welcome to connextdds-py! This is the Python API for RTI Connext DDS.
It is based on the Modern C++ API and is similar but has a few key
differences. Due to the dynamic nature of Python, Dynamic Data is
differences. Due to the dynamic nature of Python, :class:`DynamicData` is
the way to define data types. This can be done in IDL files that
can be converted to XML files, or in code. Additionally, there are
a few built in types that can be created in code such as :class:`Int32Type`
or :class:`StringType`. There are some other differences too.
For example, instead of getters and setters, we utilize properties.
If there's a property that is write only, it is assigned typically
with a call to set_name_of_property.
with a call to set_name_of_property.

.. code-block:: python
import rti.connextdds as dds
DOMAIN_ID = 0 # Could be anything, I just chose 0
participant = dds.DomainParticipant(DOMAIN_ID)
print(participant.domain_id) # Will print zero
There is also support for built in python constructs to make the
library more ergonomic. For example, instead of a :code:`to_string`
function anywhere, the python :code:`str()` is used. This allows you
to do things like print a value without it being of type string.
Another built in construct that is used is the :code:`iter()` function.
This function alls the user to iterate through a data type. You can
also use :code:`for a in b` loop constructs. An example would look like
this:

.. code-block:: python
# Assume that the reader has been properly created
samples = reader.take()
for sample in samples:
print(sample)
**Note**: As an experimental product, this API documentation is less
comprehensive than the documentation for the other language APIs.
Expand Down
9 changes: 5 additions & 4 deletions docs/source/participant.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DomainParticipant
~~~~~~~~~~~~~~~~~

When using connextdds-py, one of the first things you'll need is to
make a participant object. To create a participant, all you need to
make a :class:`DomainParticipant` object. To create a participant, all you need to
do is import the module and then create the object. This can be seen
in the code below.

Expand All @@ -14,8 +14,8 @@ in the code below.
DOMAIN_ID = 0 # Could be anything, I just chose 0
participant = dds.DomainParticipant(DOMAIN_ID)
Optionally, you can also create a participant using a with statement
so it gets deleted when the block ends.
Optionally, you can also create a participant using a :code:`with`
statement so it gets deleted when the block ends.

.. code-block:: python
Expand All @@ -24,7 +24,8 @@ so it gets deleted when the block ends.
with dds.DomainParticipant(DOMAIN_ID) as participant:
pass
Additionally, you can supply an additional parameter to specify the QoS.
Additionally, you can supply an additional parameter to specify the
:class:`DomainParticipantQos`.
For example, if you would like to have a participant with a quicker
shutdown cleanup period, you can follow the code below.

Expand Down
22 changes: 22 additions & 0 deletions docs/source/reader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,25 @@ looks like this:
if sample.info.valid:
print(sample)
If you would like to use a :class:`WaitSet` and a :class:`StatusCondition`,
you can follow the example below:

.. code-block:: python
samples_read = 0
def handler(_):
nonlocal samples_read
nonlocal reader
samples_read += len(reader.take())
status_condition = dds.StatusCondition(reader)
status_condition.enable_statuses = dds.StatusMask.data_available()
status_condition.handler(handler)
waitset = dds.WaitSet()
waitset += status_condition
while samples_read < 10:
print("Still looping")
waitset.dispatch(dds.Duration(1)) # Wait 1 second each loop
The code block above will essentially print "Still looping" until 10 samples
are processed.
4 changes: 2 additions & 2 deletions docs/source/topic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Topics

DDS Topics allow for publishers and subscriber to communicate
without knowing about each other. They dynamically discover
each other through topics. The data that the DataReader and
DataWriter share is described by a topic.
each other through topics. The data that the :class:`DataReader` and
:class:`DataWriter` share is described by a topic.

To create a topic, all you need to do is create a topic object.
Due to the dynamic nature of Python, dynamic data types are used.
Expand Down
20 changes: 16 additions & 4 deletions docs/source/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Types
~~~~~

Types in connextdds-py are similar to the types in other RTI APIs
but with a few differences. Due to Python's dynamic nature, Dynamic
Data is used. You cannot directly use IDL files for your types,
but with a few differences. Due to Python's dynamic nature, :class:`DynamicData`
is used. You cannot directly use IDL files for your types,
however, you can generate XML files from your IDL files. To do so,
at the command line run:

Expand All @@ -23,7 +23,7 @@ you can get the type from the file like this:
provider = dds.QosProvider(FILE)
provider_type = provider.type("NameOfType")
Now in the provider_type variable you have the type defined in the IDL file.
Now in the :code:`provider_type` variable you have the type defined in the IDL file.
To make an instance of it, all you have to do is this:

.. code-block:: python
Expand All @@ -34,4 +34,16 @@ To make an instance of it, all you have to do is this:
sample['x'] = 42
Now you would be able to publish the sample which is discussed in
:ref:`writer:Publications`
:ref:`writer:Publications`.

Sequences
=========

Data from Dictionaries
======================

Nested Sample Data
==================

Loaned Data
===========

0 comments on commit 523f0e3

Please sign in to comment.