ROS2_pubsub/src/pubsub/pubsub/Readme.md

42 lines
2.7 KiB
Markdown
Raw Normal View History

2021-04-21 11:14:15 +02:00
# Readme /pubsub
This directory represents a ROS package due to its internal structure and files. The files inside `pubsub/pubsub/` are the Python scripts written by the package developer and can be called using the command line `ros2 run pubsub <entry_point_name>`. The `<entry_point_name>` has to be defined in _setup.py_.
## Files
This section describes the content and purpose of the files inside this directory.
`ros2 run` callable files:
* *topic\_talker.py* : Example for creating a `MinimumPublisher` and sending topics
* *topic\_listener.py* : Example for creating a `MinimumSubscriber` and receiving topics
* *service\_host.py* : Example for creataing a `MinimumServiceProvider` and hosting a service
* *service\_client.py* : Example for creating a `MinimumServiceClient` and calling a service
* *statemachine\_host\_example.py* : Example application of State Machine (SM) hosting a service to call for a change of state
* *statemachine\_client\_example.py* : Example application of a service client calling for the change of SM state
Library files:
* \[*pubsub\_library* ; *pubsub\_library\_v2*\] : old versions
* *pubsub\_library\_v3* : Library containing
* `MinimalPublisher` class
* `MinimalSubscriber` class
* `MinimalServiceProvider` class
* `MinimalServiceClient` class
## How to use
2021-04-23 15:39:40 +02:00
In the following the various classes named above are referred to as `Minimal<X>` with `<X>` standing for topic publisher/subscriber or service host/client.
2021-04-21 11:14:15 +02:00
You can use the `Minimal<X>` classes in three ways:
2021-04-23 15:39:40 +02:00
* Create `Minimal<X>` in your script (eg. [topic_listener.py](None)): Here data is echanged between the script environment and the class environment.
__Upsides__: You can implement as many instances of `Minimal<X>` as you like
__Downsides__: Code get's complicated and confusing
* Implement `Minimal<X>` inside your device class the same way as implementing in your main script (__<-- ToDo !!!__)
__Upsides__: You can implement as man instances of `Minimal<X>` as you like; You can wrap these instances inside you device class
__Downsides__: __ToDo__
* Build device class upon `Minimal<X>` by using this structure
2021-04-21 11:14:15 +02:00
```python
class Child_Class(Parent_Class):
```
For example:
```python
class StateMachineCMDServiceProvider(MinimalServiceProvider):
```
2021-04-23 15:39:40 +02:00
(Example: [statemachine_host_example.py](None): device class is built upon `MinimalServiceProvider` class.)
__Upsides__: `Minimal<X>` is automatically instantiated when creating an instance of your device class though `__init()__`
__Downsides__: You can only implement one instance of `Minimal<X>`, eg. one device class can only implement one publisher, in this case you want to implement `Minimal<X>` inside device class (see above)