Skip to content

Commit dc98583

Browse files
committed
add instructions for primitive messages to readme
1 parent 1a80753 commit dc98583

File tree

2 files changed

+61
-37
lines changed

2 files changed

+61
-37
lines changed

README.md

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<img src="https://img.shields.io/github/v/release/ika-rwth-aachen/mqtt_client"/></a>
66
<img src="https://img.shields.io/github/license/ika-rwth-aachen/mqtt_client"/></a>
77
<a href="https://github.com/ika-rwth-aachen/mqtt_client/actions/workflows/build.yml"><img src="https://github.com/ika-rwth-aachen/mqtt_client/actions/workflows/build.yml/badge.svg"/></a>
8-
<img src="https://img.shields.io/github/stars/ika-rwth-aachen/mqtt_client?style=social"/></a>
8+
<a href="https://github.com/ika-rwth-aachen/mqtt_client"><img src="https://img.shields.io/github/stars/ika-rwth-aachen/mqtt_client?style=social"/></a>
99
</p>
1010

1111
The *mqtt_client* package provides a ROS nodelet that enables connected ROS-based devices or robots to exchange ROS messages via an MQTT broker using the [MQTT](http://mqtt.org) protocol. This works generically for arbitrary ROS message types.
@@ -15,6 +15,7 @@ The *mqtt_client* package provides a ROS nodelet that enables connected ROS-base
1515
- [Quick Start](#quick-start)
1616
- [Launch](#launch)
1717
- [Configuration](#configuration)
18+
- [Primitive Messages](#primitive-messages)
1819
- [Latency Computation](#latency-computation)
1920
- [Package Summary](#package-summary)
2021
- [How It Works](#how-it-works)
@@ -57,23 +58,27 @@ docker run --rm --network host --name mosquitto eclipse-mosquitto
5758

5859
The *mqtt_client* is best configured with a ROS parameter *yaml* file. The configuration shown below (also see [`params.yaml`](launch/params.yaml)) allows an exchange of messages as follows:
5960

60-
- ROS messages received locally on ROS topic `/ping` are sent to the broker on MQTT topic `pingpong`;
61-
- MQTT messages received from the broker on MQTT topic `pingpong` are published locally on ROS topic `/pong`;
62-
- MQTT messages received sent by other non-ROS clients and received from the broker on MQTT topic `primitive` are published locally as primitive ROS messages (`bool`, `int`, `float`, `string`) on ROS topic `/primitive`.
61+
- ROS messages received locally on ROS topic `/ping/ros` are sent to the broker on MQTT topic `pingpong/ros`;
62+
- MQTT messages received from the broker on MQTT topic `pingpong/ros` are published locally on ROS topic `/pong/ros`;
63+
- primitive ROS messages received locally on ROS topic `/ping/primitive` are sent as primitive (string) messages to the broker on MQTT topic `pingpong/primitive`;
64+
- MQTT messages received from the broker on MQTT topic `pingpong/primitive` are published locally as primitive ROS messages on ROS topic `/primitive`.
6365

6466
```yaml
6567
broker:
6668
host: localhost
6769
port: 1883
6870
bridge:
6971
ros2mqtt:
70-
- ros_topic: /ping
71-
mqtt_topic: pingpong
72+
- ros_topic: /ping/ros
73+
mqtt_topic: pingpong/ros
74+
- ros_topic: /ping/primitive
75+
mqtt_topic: pingpong/primitive
76+
primitive: true
7277
mqtt2ros:
73-
- mqtt_topic: pingpong
74-
ros_topic: /pong
75-
- mqtt_topic: primitive
76-
ros_topic: /primitive
78+
- mqtt_topic: pingpong/ros
79+
ros_topic: /pong/ros
80+
- mqtt_topic: pingpong/primitive
81+
ros_topic: /pong/primitive
7782
primitive: true
7883
```
7984
@@ -86,44 +91,52 @@ roslaunch mqtt_client standalone.launch
8691
```
8792

8893
```txt
89-
[ WARN] [1665521116.598414724]: Parameter 'broker/tls/enabled' not set, defaulting to '0'
90-
[ WARN] [1665521116.598987895]: Parameter 'client/id' not set, defaulting to ''
91-
[ WARN] [1665521116.599000755]: Client buffer can not be enabled when client ID is empty
92-
[ WARN] [1665521116.599293016]: Parameter 'client/clean_session' not set, defaulting to '1'
93-
[ WARN] [1665521116.599543528]: Parameter 'client/keep_alive_interval' not set, defaulting to '60.000000'
94-
[ WARN] [1665521116.599792350]: Parameter 'client/max_inflight' not set, defaulting to '65535'
95-
[ INFO] [1665521116.600156748]: Bridging ROS topic '/ping' to MQTT topic 'pingpong'
96-
[ INFO] [1665521116.600202047]: Bridging MQTT topic 'pingpong' to ROS topic '/pong'
97-
[ INFO] [1665521116.600219366]: Bridging MQTT topic 'primitive' to primitive ROS topic '/primitive'
98-
[ INFO] [1665521116.600988342]: Connecting to broker at 'tcp://localhost:1883' ...
99-
[ INFO] [1665521116.701596581]: Connected to broker at 'tcp://localhost:1883'
94+
[ WARN] [1665575657.358869079]: Parameter 'broker/tls/enabled' not set, defaulting to '0'
95+
[ WARN] [1665575657.359798329]: Parameter 'client/id' not set, defaulting to ''
96+
[ WARN] [1665575657.359810889]: Client buffer can not be enabled when client ID is empty
97+
[ WARN] [1665575657.360300703]: Parameter 'client/clean_session' not set, defaulting to '1'
98+
[ WARN] [1665575657.360576344]: Parameter 'client/keep_alive_interval' not set, defaulting to '60.000000'
99+
[ WARN] [1665575657.360847295]: Parameter 'client/max_inflight' not set, defaulting to '65535'
100+
[ INFO] [1665575657.361281461]: Bridging ROS topic '/ping/ros' to MQTT topic 'pingpong/ros'
101+
[ INFO] [1665575657.361303380]: Bridging primitive ROS topic '/ping/primitive' to MQTT topic 'pingpong/primitive'
102+
[ INFO] [1665575657.361352809]: Bridging MQTT topic 'pingpong/ros' to ROS topic '/pong/ros'
103+
[ INFO] [1665575657.361370558]: Bridging MQTT topic 'pingpong/primitive' to primitive ROS topic '/pong/primitive'
104+
[ INFO] [1665575657.362153083]: Connecting to broker at 'tcp://localhost:1883' ...
105+
[ INFO] [1665575657.462622065]: Connected to broker at 'tcp://localhost:1883'
100106
```
101107

102108
Note that the *mqtt_client* successfully connected to the broker and also echoed which ROS/MQTT topics are being bridged.
103109

104-
In order to test the communication among `mqtt_client`, publish any message on ROS topic `/ping` and wait for a response on ROS topic `/pong`. In order to test the communication between other MQTT clients and the `mqtt_client`, directly publish any message on MQTT topic `primitive` and wait for a response on ROS topic `/primitive`. To this end, open four new terminals and execute the following commands.
110+
In order to test the communication among *mqtt_clients*, publish any ROS message on ROS topic `/ping/ros` and wait for a response on ROS topic `/pong/ros`.
105111

106112
```bash
107-
# 1st terminal: listen for ROS messages on /pong
108-
rostopic echo /pong
113+
# 1st terminal: listen for ROS messages on /pong/ros
114+
rostopic echo /pong/ros
109115
```
110116

111117
```bash
112-
# 2nd terminal: publish ROS message to /ping
113-
rostopic pub -r 1 /ping std_msgs/String "Hello MQTT!"
118+
# 2nd terminal: publish ROS message to /ping/ros
119+
rostopic pub -r 1 /ping/ros std_msgs/String "Hello MQTT!"
120+
```
121+
122+
In order to test the communication between *mqtt_client* and other MQTT clients, publish a primitive ROS message on ROS topic `/ping/primitive`, directly publish a primitive MQTT message on MQTT topic `pingpong/primitive` and wait for responses on ROS topic `/pong/primitive`.
123+
124+
```bash
125+
# 3rd terminal: listen for primitive ROS messages on /pong/primitive
126+
rostopic echo /pong/primitive
114127
```
115128

116129
```bash
117-
# 3rd terminal: listen for ROS messages on /primitive
118-
rostopic echo /primitive
130+
# 4th terminal: publish primitive ROS message to /ping/primitive
131+
rostopic pub -r 1 /ping/primitive std_msgs/Int32 42
119132
```
120133

121134
```bash
122-
# 4th terminal: publish MQTT message to primitive
123-
docker run --rm --network host eclipse-mosquitto mosquitto_pub -h localhost -t "primitive" --repeat 10 --repeat-delay 1 -m 3.14
135+
# 5th terminal: publish primitive MQTT message to pingpong/primitive
136+
docker run --rm --network host eclipse-mosquitto mosquitto_pub -h localhost -t "pingpong/primitive" --repeat 10 --repeat-delay 1 -m 69
124137
```
125138

126-
If everything works as expected, a new message should be printed in the first and third terminal once a second.
139+
If everything works as expected, the second terminal should print a message at 1Hz, while the fifth third terminal should print two different messages at 1Hz.
127140

128141
### Launch
129142

@@ -213,6 +226,14 @@ bridge:
213226
latched: # [false] whether to latch ROS message
214227
```
215228
229+
## Primitive Messages
230+
231+
As seen in the [Quick Start](#quick-start), the *mqtt_client* can not only exchange arbitrary ROS messages with other *mqtt_clients*, but it can also exchange primitive message data with other non-*mqtt_client* MQTT clients. The `primitive` parameter can be set for both ROS-to-MQTT (`bridge/ros2mqtt`) and MQTT-to-ROS (`bridge/mqtt2ros`) transmissions.
232+
233+
If a ROS-to-MQTT transmission is configured as `primitive`, the ROS message is simply serialized to a string representation, without providing any information of the underlying ROS message type via MQTT. If the ROS message type is one of the supported primitive ROS message types, the encapsualating ROS message components are also removed, s.t. only the raw data is published as a string. The supported primitive ROS message types are [`std_msgs/String`](http://docs.ros.org/en/api/std_msgs/html/msg/String.html), [`std_msgs/Bool`](http://docs.ros.org/en/api/std_msgs/html/msg/Bool.html), [`std_msgs/Char`](http://docs.ros.org/en/api/std_msgs/html/msg/Char.html), [`std_msgs/UInt8`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt8.html), [`std_msgs/UInt16`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt16.html), [`std_msgs/UInt32`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt32.html), [`std_msgs/UInt64`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt16.html), [`std_msgs/Int8`](http://docs.ros.org/en/api/std_msgs/html/msg/Int8.html), [`std_msgs/Int16`](http://docs.ros.org/en/api/std_msgs/html/msg/Int16.html), [`std_msgs/Int32`](http://docs.ros.org/en/api/std_msgs/html/msg/Int32.html), [`std_msgs/Int64`](http://docs.ros.org/en/api/std_msgs/html/msg/Int64.html), [`std_msgs/Float32`](http://docs.ros.org/en/api/std_msgs/html/msg/Float32.html), [`std_msgs/Float32`](http://docs.ros.org/en/api/std_msgs/html/msg/Float64.html).
234+
235+
If an MQTT-to-ROS transmission is configured as `primitive`, the MQTT message is interpreted and published as a primitive data type, if possible. The message is probed in the following order: `bool` ([`std_msgs/Bool`](http://docs.ros.org/en/api/std_msgs/html/msg/Bool.html)), `int` ([`std_msgs/Int32`](http://docs.ros.org/en/api/std_msgs/html/msg/Int32.html)), `float` ([`std_msgs/Float32`](http://docs.ros.org/en/api/std_msgs/html/msg/Float32.html)), `string` ([`std_msgs/String`](http://docs.ros.org/en/api/std_msgs/html/msg/String.html)).
236+
216237
## Latency Computation
217238

218239
The *mqtt_client* provides built-in functionality to measure the latency of transferring a ROS message via an MQTT broker back to ROS. To this end, the sending client injects the current timestamp into the MQTT message. The receiving client can then compute the latency between message reception time and the injected timestamp. **Naturally, this is only accurate to the level of synchronization between clocks on sending and receiving machine.**

launch/params.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ broker:
33
port: 1883
44
bridge:
55
ros2mqtt:
6-
- ros_topic: /ping
7-
mqtt_topic: pingpong
6+
- ros_topic: /ping/ros
7+
mqtt_topic: pingpong/ros
8+
- ros_topic: /ping/primitive
9+
mqtt_topic: pingpong/primitive
10+
primitive: true
811
mqtt2ros:
9-
- mqtt_topic: pingpong
10-
ros_topic: /pong
11-
- mqtt_topic: primitive
12-
ros_topic: /primitive
12+
- mqtt_topic: pingpong/ros
13+
ros_topic: /pong/ros
14+
- mqtt_topic: pingpong/primitive
15+
ros_topic: /pong/primitive
1316
primitive: true

0 commit comments

Comments
 (0)