In this article we will turn Zubax Babel into a simple UAVCAN publisher. All the code here includes the code from the previous tutorials and extends it.
THE MATERIALS PRESENTED HERE ARE BASED ON UAVCAN v0 – AN EXPERIMENTAL VERSION OF THE PROTOCOL THAT IS NOW OBSOLETE. TO LEARN ABOUT THE LONG-TERM STABLE REVISION OF THE PROTOCOL, PROCEED TO UAVCAN.ORG.
Our goal is to publish a couple of different values via UAVCAN and to check if everything works properly by plotting graphs in the UAVCAN GUI Tool's plotter utility.
We are going to use the UAVCAN message
uavcan.protocol.debug.KeyValue. The UAVCAN specification says that
float32 values can be broadcasted this way. We can use it to broadcast some custom sensor data, ADC data, or just any named value. For the sake of simplicity, in this tutorial we will broadcast sine values. But, assuming that the MCU resources are quite constrained, we will take the values from a lookup table. We will also broadcast the second value – the current table index.
Important note. Integer and float values have very different bit-structure. As libcanard expects a float data type for
uavcan.protocol.debug.KeyValue, it is important to give it exactly what it wants - a float value. So, despite the fact that we have an unsigned integer (even
uint8_t) typed sine table, it is important to provide the
canardEncodeScalar function with a
float type parameter.
Now, let's add our publisher to
main(), so now it looks like this:
Now it's time to flash the firmware to Babel and check if everything is working as expected. You should find a bunch of new messages in the Bus monitor panel:
Now let's open
UAVCAN Plotter, which can be found in the
Tools -> Plotter menu.
Firstly, let's just plot every message of type
uavcan.protocol.debug.KeyValue. For that, open the Plotter and hit that
+ button in bottom left corner of the window. Fill in the plot details as shown below and hit
Now you should see something like this:
You may adjust the scale of time and value axes by moving the mouse while holding the right button pressed.
The plot looks pretty weird because the plotter tries to display all values of type
debug.KeyValue, and Babel transmits two diifferent values simultaneously: the sine value and the step. Let's delete this plot and add two more, one for each separate value:
Now the graphs look properly: