Robobot MQTT topics: Difference between revisions

From Rsewiki
Line 102: Line 102:


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.
== Subscription test ==
Install mosquitto; see: https://mosquitto.org/download/
Tu see the messages from the teensy_interface; assuming the robot has the IP 10.197.218.72, you could try:
mosquitto_sub -v -t -h 10.197.218.72 -t robobot/drive/#
It should then reply with something like:
robobot/drive/T0/acc2 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/gyro2 1739638296.2126 -0.113159 -0.068024 0.168213 31618.031
robobot/drive/T0/acc2 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/gyro2 1739638296.2150 -0.052124 -0.006989 0.351318 31618.033
robobot/drive/T0/acc2 1739638296.2151 -0.028809 0.029053 1.022461 31618.033
robobot/drive/T0/current 1739638296.2162 -0.000 0.000

Revision as of 17:54, 15 February 2025

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

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

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.

Subscription test

Install mosquitto; see: https://mosquitto.org/download/

Tu see the messages from the teensy_interface; assuming the robot has the IP 10.197.218.72, you could try:

mosquitto_sub -v -t -h 10.197.218.72 -t robobot/drive/#

It should then reply with something like:

robobot/drive/T0/acc2 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/gyro2 1739638296.2126 -0.113159 -0.068024 0.168213 31618.031
robobot/drive/T0/acc2 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/gyro2 1739638296.2150 -0.052124 -0.006989 0.351318 31618.033
robobot/drive/T0/acc2 1739638296.2151 -0.028809 0.029053 1.022461 31618.033
robobot/drive/T0/current 1739638296.2162 -0.000 0.000