Robobot MQTT topics

From Rsewiki

Back to Robobot

MQTT

MQTT (Message Queuing Telemetry Transport) is a lightweight protocol that transports messages between processes and 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 robobot/cmd/T0/sub -m "ir 300"
mosquitto_sub -h 10.197.218.81 -v -t robobot/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 can be recommended, and is available on all platforms. see: http://mqtt-explorer.com/

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 data can be subscribed.

  • topic: robobot/#

All used topics start with the keyword robobot/. The # is a wildcard that matches all sub-topics.

  • topic: robobot/drive/T0/#

The sub-topic robobot/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 subtopic, e.g.:

  • robobot/drive/T0/pose is a pose message

The parameters are then the MQTT message "payload", examples of a pose messages are:

  • robobot/drive/T0/pose 1738930269.8039 2232.5911 0.583 0.702 2.5420 3.1241

After the topic robobot/drive/T0/pose are 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 position, heading (radians), and tilt (radians).

Examples:

robobot/drive/T0/gyro2   1738930269.7980 -0.448853 0.816986 -4.012695 2232.585
robobot/drive/T0/vel     1738930269.7992 2232.5859 -0.003 -0.008 -0.0200 -0.003 3
robobot/drive/T0/pose    1738930269.7992 2232.5859 0.583 0.702 2.5420 3.1239
robobot/drive/T0/mvel    1738930269.7999 -0.003 -0.008
robobot/drive/T0/acc2    1738930269.8004 0.018066 -0.026367 0.984863 2232.587
robobot/drive/T0/current 1738930269.8004 0.000 0.000
robobot/drive/T0/dist    1738930269.8027 0.623 0.469
robobot/drive/T0/livn    1738930269.8061 203 195 193 202 197 200 209 217 195
robobot/drive/T0/vel     1738930269.8062 2232.5930 -0.003 -0.008 -0.0200 -0.003 4
robobot/drive/T0/mvel    1738930269.8073 -0.003 -0.008
robobot/drive/T0/pose    1738930269.8096 2232.5959 0.583 0.702 2.5420 3.1241
robobot/drive/T0/conf    1738499287.6484 0.0750 0.0750 19.000 68 0.2300 0.0020 0
robobot/drive/T0/gyro2   1738930269.8107 -0.815063 -1.807526 -4.348389 2232.597
robobot/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 could contain text like the last message.

At times, the Teensy sends a comment or a debug message. Such messages are sent with the info topic. The data is always preceded with a #.

Command topics to Teensy_interface

These topics start as:

  • robobot/cmd/ti/

Examples are:

1738498850.8640 0 drive robobot/cmd/ti/log 1
1738498851.3836 0 drive robobot/cmd/ti/rc 0.0 0.0
1738498851.3969 0 drive robobot/cmd/ti/rc 0.250 -1.000 1738498851.3969011
1738498851.8492 0 drive robobot/cmd/ti/alive 2025-02-02 13:20:50.861066
1738498851.8627 0 drive robobot/cmd/ti/rc 0.250 0.119 1738498851.8626823
1738498852.2016 0 drive robobot/cmd/ti/alive 2025-02-02 13:20:50.861066
1738498857.8342 0 drive robobot/cmd/ti/log 0

The first 3 columns are added by the teensy_interface logger, the rest is topic and message.

Master topic

A master regularly publishes an alive message that includes a timestamp as payload, e.g. every 400ms:

at 1739609901.9768: robobot/cmd/ti/alive 2025-02-15 09:57:53.433439
at 1739609902.3793: robobot/cmd/ti/alive 2025-02-15 09:57:53.433439
at 1739609902.7721: robobot/cmd/ti/alive 2025-02-15 09:57:53.433439

If this is the first (or the only) MQTT client, that want to control the robot, then the teensy_interface publishes a master message with this timestamp, like:

robobot/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 a 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 are all topics starting with the direction topic:

robobot/cmd/T0

Then, it will be followed by the keyword that Teensy can recognize. As an example, a command to subscribe to gyro data could be:

topic:   robobot/cmd/T0/sub
message: gyro 15

The Teensy interface strips then strips the direction topic (robobot/cmd/T0) and sends the remaining part and the message 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 af

topic: robobot/drive/T0/gyro
message: time x.xxxxx y.yyyyyy z.zzzzz, e.g.:
message: 1740818119.4175 -0.021606 0.115082 0.381836

time is the Raspberry Pi timestamp in seconds since the start of the epoch.

The available commands are here 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 robobot/drive/T0/#

Or just the gyro messages

mosquitto_sub -v -h 10.197.218.72 -t robobot/drive/T0/gyro

It should then reply with something like (for all messages):

robobot/drive/T0/acc 1739638296.2093 -0.028076 0.027344 1.025879 31618.027
robobot/drive/T0/pose 1739638296.2094 31618.0273 0.000 0.000 0.0000 3.1169
robobot/drive/T0/gyro 1739638296.2126 -0.113159 -0.068024 0.168213 31618.031
robobot/drive/T0/acc 1739638296.2127 -0.026611 0.023926 1.023193 31618.031
robobot/drive/T0/vel 1739638296.2128 31618.0312 0.000 0.000 0.0000 0.000 4
robobot/drive/T0/mvel 1739638296.2131 0.000 0.000
robobot/drive/T0/pose 1739638296.2139 31618.0332 0.000 0.000 0.0000 3.1169
robobot/drive/T0/gyro 1739638296.2150 -0.052124 -0.006989 0.351318 31618.033
robobot/drive/T0/acc 1739638296.2151 -0.028809 0.029053 1.022461 31618.033
robobot/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 robobot/cmd/T0/sub -m "gyro 1"

Or stopping gyro streaming

mosquitto_pub -h 10.197.218.72 -t robobot/cmd/T0/sub -m "gyro 0"