Open jxltom opened 4 years ago
Change to float32
is fine. It looks like using float16 is overflow or something like that for big numbers such as 280
.
At this exponent, the step is around 0.2:
>>> import numpy
>>> numpy.nextafter(numpy.float16(298), numpy.float16(1000))
298.2
Whereas your value falls closer to 298:
>>> 24.9219 + 273.15
298.07189999999997
The behavior you are observing is correct.
Thanks for the clarification!
So the precision of float16
for numbers such has 298
is around 0.2
or bigger.
Since uavcan is using Kelvin and motor temperature is certainly larger than 273.15
, maybe it makes sense to change the definition of uavcan.equipment.esc.Status.temperature
to float32
, otherwise the digit 0.05
in 273.15
will definitely be lost. float32
doesn't have this issue.
>>> import numpy
>>> numpy.nextafter(numpy.float16(273.15), numpy.float16(numpy.inf))
273.5
>>> numpy.nextafter(numpy.float32(273.15), numpy.float32(numpy.inf))
273.15002
In https://github.com/vedderb/bldc/blob/b460fa0fa3cb507a14aef26082d782f76b30d7db/libcanard/canard_driver.c#L119, the returned temperature is always
298.0000
which looks like precesion is lost.Even I changed code to
status.temperature = 24.9219 + 273.15;
in bldc, the parsed temperature in https://github.com/UAVCAN/gui_tool is still298.0000
Here is the screenshot in gui_tool.
Maybe something wrong with
canardConvertNativeFloatToFloat16
?@pavel-kirienko do you mind also having a look? Thanks.