Robobot MQTT topics: Difference between revisions
(→MQTT) |
No edit summary |
||
| Line 3: | Line 3: | ||
== MQTT == | == MQTT == | ||
MQTT (Message Queuing Telemetry Transport) is a lightweight protocol | MQTT (Message Queuing Telemetry Transport) is a lightweight protocol for transporting messages between processes and across networks. | ||
The used MQTT server is Mosquitto from https://mosquitto.org/ | The used MQTT server is Mosquitto from https://mosquitto.org/ | ||
| Line 11: | Line 11: | ||
Mosquitto comes with commands for ''publish'' and subscribe directly from the command line, e.g.: | Mosquitto comes with commands for ''publish'' and subscribe directly from the command line, e.g.: | ||
mosquitto_pub -h 10.197.218.81 -t | mosquitto_pub -h 10.197.218.81 -t dtubot/cmd/T0 -m "sub ir 300" | ||
mosquitto_sub -h 10.197.218.81 -v -t | mosquitto_sub -h 10.197.218.81 -v -t dtubot/drive/T0/# | ||
The used options are: ''-h'' for host, ''-t'' for topic and ''-m'' for message. | The used options are: ''-h'' for host, ''-t'' for topic and ''-m'' for message. | ||
| Line 22: | Line 22: | ||
[[file: mqtt-server-with-app.png | 770px]] | [[file: mqtt-server-with-app.png | 770px]] | ||
MQTT message flow and power off. | MQTT message flow and power off. MQTT Explorer can explore messages. The ''ip_display'' does not display the IP address; it is handled by the ''teensy_interface'' (legacy names). The ''Start'' button starts the Python mission app. All receive the shutdown (>5 sec on 'Start'). The Teensy is told to cut power in 20 seconds to allow the Raspberry to shut down. | ||
== Robobot == | == Robobot == | ||
| Line 34: | Line 34: | ||
=== Data topics (from firmware) === | === Data topics (from firmware) === | ||
Data messages mainly originate from the Teensy firmware, where | Data messages mainly originate from the Teensy firmware, where they can be subscribed to. | ||
* topic: | * topic: dtubot/# | ||
All used topics start with the keyword <code> | All used topics start with the keyword <code>dtubot/</code>. The <code>#</code> is a wildcard that matches all sub-topics. | ||
* topic: | * topic: dtubot/drive/T0/# | ||
The sub-topic <code> | The sub-topic <code>dtubot/drive/</code> is used for all data messages sourced by the teensy_interface (data from the drive function and generated by the first (and only) Teensy <code>T0</code>). | ||
==== Data messages ==== | ==== Data messages ==== | ||
Data types described in [[Help page Teensy_8]] generate messages starting with a keyword and some parameters. | Data types described in [[Help page Teensy_8]] generate messages starting with a keyword and some parameters. | ||
The keyword is used as subtopic, e.g.: | The keyword is used as a subtopic, e.g.: | ||
* | * dtubot/drive/T0/pose is a pose message | ||
The parameters are then the MQTT message "payload", | The parameters are then the MQTT message "payload", | ||
examples of a pose | examples of a pose message are: | ||
* | * dtubot/drive/T0/pose 1738930269.8039 2232.5911 0.583 0.702 2.5420 3.1241 | ||
After the topic '' | After the topic ''dtubot/drive/T0/pose'' is the payload. | ||
The payload is always pure text (7-bit ASCII), and the first data is always a timestamp in seconds (since 1 Jan 1970). | The payload is always pure text (7-bit ASCII), and the first data is always a timestamp in seconds (since 1 Jan 1970). | ||
In this case, the remaining data are Teensy time (sec), x and y | In this case, the remaining data are Teensy time (sec), x- and y-positions, heading (radians), and tilt (radians). | ||
Examples: | Examples: | ||
dtubot/drive/T0/gyro2 1738930269.7980 -0.448853 0.816986 -4.012695 2232.585 | |||
dtubot/drive/T0/vel 1738930269.7992 2232.5859 -0.003 -0.008 -0.0200 -0.003 3 | |||
dtubot/drive/T0/pose 1738930269.7992 2232.5859 0.583 0.702 2.5420 3.1239 | |||
dtubot/drive/T0/mvel 1738930269.7999 -0.003 -0.008 | |||
dtubot/drive/T0/acc2 1738930269.8004 0.018066 -0.026367 0.984863 2232.587 | |||
dtubot/drive/T0/current 1738930269.8004 0.000 0.000 | |||
dtubot/drive/T0/dist 1738930269.8027 0.623 0.469 | |||
dtubot/drive/T0/livn 1738930269.8061 203 195 193 202 197 200 209 217 195 | |||
dtubot/drive/T0/vel 1738930269.8062 2232.5930 -0.003 -0.008 -0.0200 -0.003 4 | |||
dtubot/drive/T0/mvel 1738930269.8073 -0.003 -0.008 | |||
dtubot/drive/T0/pose 1738930269.8096 2232.5959 0.583 0.702 2.5420 3.1241 | |||
dtubot/drive/T0/conf 1738499287.6484 0.0750 0.0750 19.000 68 0.2300 0.0020 0 | |||
dtubot/drive/T0/gyro2 1738930269.8107 -0.815063 -1.807526 -4.348389 2232.597 | |||
dtubot/drive/T0/info 1738918215.7251 # got confw: r1=0.075, r2=0.075, G=19, PPR=68, WB=0.23 | |||
Most parameters are numeric but | Most parameters are numeric but may contain text, as in the last message. | ||
At times, the Teensy sends a comment or a debug message. Such messages are sent with the ''info'' topic. | At times, the Teensy sends a comment or a debug message. Such messages are sent with the ''info'' topic. A ''#'' always precedes the data in the payload. | ||
== Command topics to Teensy_interface == | == Command topics to Teensy_interface == | ||
| Line 87: | Line 87: | ||
These topics start as: | These topics start as: | ||
* | * dtubot/cmd/ti/ | ||
Examples are: | Examples are: | ||
1738498850.8640 0 drive | 1738498850.8640 0 drive dtubot/cmd/ti log 1 | ||
1738498851.3836 0 drive | 1738498851.3836 0 drive dtubot/cmd/ti rc 0.0 0.0 | ||
1738498851.3969 0 drive | 1738498851.3969 0 drive dtubot/cmd/ti rc 0.250 -1.000 1738498851.3969011 | ||
1738498851.8492 0 drive | 1738498851.8492 0 drive dtubot/cmd/ti alive 2025-02-02 13:20:50.861066 | ||
1738498851.8627 0 drive | 1738498851.8627 0 drive dtubot/cmd/ti rc 0.250 0.119 1738498851.8626823 | ||
1738498852.2016 0 drive | 1738498852.2016 0 drive dtubot/cmd/ti alive 2025-02-02 13:20:50.861066 | ||
1738498857.8342 0 drive | 1738498857.8342 0 drive dtubot/cmd/ti log 0 | ||
The ''teensy_interface'' logger adds the first 3 columns; the rest are topic and message. | |||
The | |||
=== Master topic === | === Master topic === | ||
| Line 105: | Line 104: | ||
A master regularly publishes a live message that includes a timestamp as payload, e.g. every 400ms: | A master regularly publishes a live message that includes a timestamp as payload, e.g. every 400ms: | ||
at 1739609901.9768: | at 1739609901.9768: dtubot/cmd/ti alive 2025-02-15 09:57:53.433439 | ||
at 1739609902.3793: | at 1739609902.3793: dtubot/cmd/ti alive 2025-02-15 09:57:53.433439 | ||
at 1739609902.7721: | at 1739609902.7721: dtubot/cmd/ti alive 2025-02-15 09:57:53.433439 | ||
If this is the first (or the only) MQTT client that wants to control the robot, then the ''teensy_interface'' publishes a master message with this timestamp, like: | If this is the first (or the only) MQTT client that wants to control the robot, then the ''teensy_interface'' publishes a master message with this timestamp, like: | ||
dtubot/drive/master 1739609909.5709 2025-02-15 09:57:53.433439 | |||
The first parameter is a timestamp, as usual. The last part, ''2025-02-15 09:57:53.433439'', is a copy of the alive message from a master. | The first parameter is a timestamp, as usual. The last part, ''2025-02-15 09:57:53.433439'', is a copy of the alive message from a master. | ||
| Line 117: | Line 116: | ||
The master should then test whether the master message matches its timestamp. If not, the MQTT client should terminate. | The master should then test whether the master message matches its timestamp. If not, the MQTT client should terminate. | ||
If there is a match, the MQTT client prints | If there is a match, the MQTT client prints the message % I am now accepted as master of robot XXX." It can happen that it hasn't received the robot's name yet, then it would say "unknown". | ||
When the teensy_interface has not received an alive message from the accepted master for some time (2 seconds), it will stop the robot and allow a new master. | When the teensy_interface has not received an alive message from the accepted master for some time (2 seconds), it will stop the robot and allow a new master. | ||
| Line 124: | Line 123: | ||
Messages to the Teensy use the topic: | Messages to the Teensy use the topic: | ||
dtubot/cmd/T0 | |||
The message will start with a command keyword. | The message will start with a command keyword. | ||
As an example, a command to subscribe to gyro data could be: | As an example, a command to subscribe to gyro data could be: | ||
topic: | topic: dtubot/cmd/T0 | ||
message: sub gyro 15 | message: sub gyro 15 | ||
| Line 140: | Line 139: | ||
These messages are translated to MQTT as | These messages are translated to MQTT as | ||
topic: | topic: dtubot/drive/T0/gyro | ||
message: time x.xxxxx y.yyyyyy z.zzzzz, e.g.: | message: time x.xxxxx y.yyyyyy z.zzzzz, e.g.: | ||
message: 1740818119.4175 -0.021606 0.115082 0.381836 | message: 1740818119.4175 -0.021606 0.115082 0.381836 | ||
The message | The message now prepends the Raspberry Pi timestamp, in seconds since the start of the epoch. | ||
The available commands are listed on the [[Help page Teensy 8]]. | The available commands are listed on the [[Help page Teensy 8]]. | ||
| Line 157: | Line 156: | ||
=== Subscribe === | === Subscribe === | ||
To see the messages from the teensy_interface | To see the messages from the teensy_interface, assuming the robot has the IP 10.197.218.72, you could try: | ||
mosquitto_sub -v -h 10.197.218.72 -t | mosquitto_sub -v -h 10.197.218.72 -t dtubot/drive/T0/# | ||
Or just the gyro messages | Or just the gyro messages | ||
mosquitto_sub -v -h 10.197.218.72 -t | mosquitto_sub -v -h 10.197.218.72 -t dtubot/drive/T0/gyro | ||
It should then reply with something like (for all messages): | It should then reply with something like (for all messages): | ||
dtubot/drive/T0/acc 1739638296.2093 -0.028076 0.027344 1.025879 31618.027 | |||
dtubot/drive/T0/pose 1739638296.2094 31618.0273 0.000 0.000 0.0000 3.1169 | |||
dtubot/drive/T0/gyro 1739638296.2126 -0.113159 -0.068024 0.168213 31618.031 | |||
dtubot/drive/T0/acc 1739638296.2127 -0.026611 0.023926 1.023193 31618.031 | |||
dtubot/drive/T0/vel 1739638296.2128 31618.0312 0.000 0.000 0.0000 0.000 4 | |||
dtubot/drive/T0/mvel 1739638296.2131 0.000 0.000 | |||
dtubot/drive/T0/pose 1739638296.2139 31618.0332 0.000 0.000 0.0000 3.1169 | |||
dtubot/drive/T0/gyro 1739638296.2150 -0.052124 -0.006989 0.351318 31618.033 | |||
dtubot/drive/T0/acc 1739638296.2151 -0.028809 0.029053 1.022461 31618.033 | |||
dtubot/drive/T0/current 1739638296.2162 -0.000 0.000 | |||
=== Send command === | === Send command === | ||
To get gyro data faster, as an example: | To get gyro data faster, as an example: | ||
mosquitto_pub -h 10.197.218.72 -t | mosquitto_pub -h 10.197.218.72 -t dtubot/cmd/T0/sub -m "gyro 1" | ||
Or stopping gyro streaming | Or stopping gyro streaming | ||
mosquitto_pub -h 10.197.218.72 -t | mosquitto_pub -h 10.197.218.72 -t dtubot/cmd/T0/sub -m "gyro 0" | ||
Revision as of 12:41, 15 May 2026
Back to Robobot
MQTT
MQTT (Message Queuing Telemetry Transport) is a lightweight protocol for transporting messages between processes and across networks.
The used MQTT server is Mosquitto from https://mosquitto.org/
The interface library used in both the Teensy_interface and the MQTT_client is paho-mqtt: https://eclipse.dev/paho/files/paho.mqtt.python/html/index.html
Mosquitto comes with commands for publish and subscribe directly from the command line, e.g.:
mosquitto_pub -h 10.197.218.81 -t dtubot/cmd/T0 -m "sub ir 300" mosquitto_sub -h 10.197.218.81 -v -t dtubot/drive/T0/#
The used options are: -h for host, -t for topic and -m for message.
Many other MQTT apps can be used too.
The MQTT-explorer is recommended and available on all platforms. see: http://mqtt-explorer.com/
MQTT message flow and power off. MQTT Explorer can explore messages. The ip_display does not display the IP address; it is handled by the teensy_interface (legacy names). The Start button starts the Python mission app. All receive the shutdown (>5 sec on 'Start'). The Teensy is told to cut power in 20 seconds to allow the Raspberry to shut down.
Robobot
Robobot uses MQTT
The MQTT server connects the Teensy_interface with the behaviour part of the robot.
Data topics (from firmware)
Data messages mainly originate from the Teensy firmware, where they can be subscribed to.
- topic: dtubot/#
All used topics start with the keyword dtubot/. The # is a wildcard that matches all sub-topics.
- topic: dtubot/drive/T0/#
The sub-topic dtubot/drive/ is used for all data messages sourced by the teensy_interface (data from the drive function and generated by the first (and only) Teensy T0).
Data messages
Data types described in Help page Teensy_8 generate messages starting with a keyword and some parameters. The keyword is used as a subtopic, e.g.:
- dtubot/drive/T0/pose is a pose message
The parameters are then the MQTT message "payload", examples of a pose message are:
- dtubot/drive/T0/pose 1738930269.8039 2232.5911 0.583 0.702 2.5420 3.1241
After the topic dtubot/drive/T0/pose is the payload.
The payload is always pure text (7-bit ASCII), and the first data is always a timestamp in seconds (since 1 Jan 1970).
In this case, the remaining data are Teensy time (sec), x- and y-positions, heading (radians), and tilt (radians).
Examples:
dtubot/drive/T0/gyro2 1738930269.7980 -0.448853 0.816986 -4.012695 2232.585 dtubot/drive/T0/vel 1738930269.7992 2232.5859 -0.003 -0.008 -0.0200 -0.003 3 dtubot/drive/T0/pose 1738930269.7992 2232.5859 0.583 0.702 2.5420 3.1239 dtubot/drive/T0/mvel 1738930269.7999 -0.003 -0.008 dtubot/drive/T0/acc2 1738930269.8004 0.018066 -0.026367 0.984863 2232.587 dtubot/drive/T0/current 1738930269.8004 0.000 0.000 dtubot/drive/T0/dist 1738930269.8027 0.623 0.469 dtubot/drive/T0/livn 1738930269.8061 203 195 193 202 197 200 209 217 195 dtubot/drive/T0/vel 1738930269.8062 2232.5930 -0.003 -0.008 -0.0200 -0.003 4 dtubot/drive/T0/mvel 1738930269.8073 -0.003 -0.008 dtubot/drive/T0/pose 1738930269.8096 2232.5959 0.583 0.702 2.5420 3.1241 dtubot/drive/T0/conf 1738499287.6484 0.0750 0.0750 19.000 68 0.2300 0.0020 0 dtubot/drive/T0/gyro2 1738930269.8107 -0.815063 -1.807526 -4.348389 2232.597 dtubot/drive/T0/info 1738918215.7251 # got confw: r1=0.075, r2=0.075, G=19, PPR=68, WB=0.23
Most parameters are numeric but may contain text, as in the last message.
At times, the Teensy sends a comment or a debug message. Such messages are sent with the info topic. A # always precedes the data in the payload.
Command topics to Teensy_interface
These topics start as:
- dtubot/cmd/ti/
Examples are:
1738498850.8640 0 drive dtubot/cmd/ti log 1 1738498851.3836 0 drive dtubot/cmd/ti rc 0.0 0.0 1738498851.3969 0 drive dtubot/cmd/ti rc 0.250 -1.000 1738498851.3969011 1738498851.8492 0 drive dtubot/cmd/ti alive 2025-02-02 13:20:50.861066 1738498851.8627 0 drive dtubot/cmd/ti rc 0.250 0.119 1738498851.8626823 1738498852.2016 0 drive dtubot/cmd/ti alive 2025-02-02 13:20:50.861066 1738498857.8342 0 drive dtubot/cmd/ti log 0
The teensy_interface logger adds the first 3 columns; the rest are topic and message.
Master topic
A master regularly publishes a live message that includes a timestamp as payload, e.g. every 400ms:
at 1739609901.9768: dtubot/cmd/ti alive 2025-02-15 09:57:53.433439 at 1739609902.3793: dtubot/cmd/ti alive 2025-02-15 09:57:53.433439 at 1739609902.7721: dtubot/cmd/ti alive 2025-02-15 09:57:53.433439
If this is the first (or the only) MQTT client that wants to control the robot, then the teensy_interface publishes a master message with this timestamp, like:
dtubot/drive/master 1739609909.5709 2025-02-15 09:57:53.433439
The first parameter is a timestamp, as usual. The last part, 2025-02-15 09:57:53.433439, is a copy of the alive message from a master.
The master should then test whether the master message matches its timestamp. If not, the MQTT client should terminate.
If there is a match, the MQTT client prints the message % I am now accepted as master of robot XXX." It can happen that it hasn't received the robot's name yet, then it would say "unknown".
When the teensy_interface has not received an alive message from the accepted master for some time (2 seconds), it will stop the robot and allow a new master.
Commands topics to the Teensy
Messages to the Teensy use the topic:
dtubot/cmd/T0
The message will start with a command keyword. As an example, a command to subscribe to gyro data could be:
topic: dtubot/cmd/T0 message: sub gyro 15
The Teensy interface sends the message part to the Teensy, in this case:
sub gyro 15
The Teensy reply is a gyro message every 15 ms:
gyro x.xxxxx y.yyyyyy z.zzzzz, e.g.: gyro -0.021606 0.115082 0.381836
where the three values are the rotation speed in degrees per second. The values are averaged over the subscription interval to reduce noise.
These messages are translated to MQTT as
topic: dtubot/drive/T0/gyro message: time x.xxxxx y.yyyyyy z.zzzzz, e.g.: message: 1740818119.4175 -0.021606 0.115082 0.381836
The message now prepends the Raspberry Pi timestamp, in seconds since the start of the epoch.
The available commands are listed on the Help page Teensy 8.
Subscription test (gyro)
Install mosquitto; see: https://mosquitto.org/download/
This has command line functions mosquitto_pub and mosquitto_sub.
Any other MQTT app would probably do as well.
Subscribe
To see the messages from the teensy_interface, assuming the robot has the IP 10.197.218.72, you could try:
mosquitto_sub -v -h 10.197.218.72 -t dtubot/drive/T0/#
Or just the gyro messages
mosquitto_sub -v -h 10.197.218.72 -t dtubot/drive/T0/gyro
It should then reply with something like (for all messages):
dtubot/drive/T0/acc 1739638296.2093 -0.028076 0.027344 1.025879 31618.027 dtubot/drive/T0/pose 1739638296.2094 31618.0273 0.000 0.000 0.0000 3.1169 dtubot/drive/T0/gyro 1739638296.2126 -0.113159 -0.068024 0.168213 31618.031 dtubot/drive/T0/acc 1739638296.2127 -0.026611 0.023926 1.023193 31618.031 dtubot/drive/T0/vel 1739638296.2128 31618.0312 0.000 0.000 0.0000 0.000 4 dtubot/drive/T0/mvel 1739638296.2131 0.000 0.000 dtubot/drive/T0/pose 1739638296.2139 31618.0332 0.000 0.000 0.0000 3.1169 dtubot/drive/T0/gyro 1739638296.2150 -0.052124 -0.006989 0.351318 31618.033 dtubot/drive/T0/acc 1739638296.2151 -0.028809 0.029053 1.022461 31618.033 dtubot/drive/T0/current 1739638296.2162 -0.000 0.000
Send command
To get gyro data faster, as an example:
mosquitto_pub -h 10.197.218.72 -t dtubot/cmd/T0/sub -m "gyro 1"
Or stopping gyro streaming
mosquitto_pub -h 10.197.218.72 -t dtubot/cmd/T0/sub -m "gyro 0"