You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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:
59
60
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`.
[ INFO] [1665575657.362153083]: Connecting to broker at 'tcp://localhost:1883' ...
105
+
[ INFO] [1665575657.462622065]: Connected to broker at 'tcp://localhost:1883'
100
106
```
101
107
102
108
Note that the *mqtt_client* successfully connected to the broker and also echoed which ROS/MQTT topics are being bridged.
103
109
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`.
105
111
106
112
```bash
107
-
# 1st terminal: listen for ROS messages on /pong
108
-
rostopic echo /pong
113
+
# 1st terminal: listen for ROS messages on /pong/ros
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
114
127
```
115
128
116
129
```bash
117
-
#3rd terminal: listen for ROS messages on /primitive
118
-
rostopic echo /primitive
130
+
#4th terminal: publish primitive ROS message to /ping/primitive
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.
127
140
128
141
### Launch
129
142
@@ -213,6 +226,14 @@ bridge:
213
226
latched: # [false] whether to latch ROS message
214
227
```
215
228
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
+
216
237
## Latency Computation
217
238
218
239
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.**
0 commit comments