FP16 to float conversion
Posted: Fri Jun 18, 2021 10:43 am
Hi, I'd like to know how to convert FP16 to its float value.
I'm logging values as in https://github.com/bitcraze/crazyflie-l ... py#L75-L84, but I'd like to print (and store) the floating value of 'pm.vbat' (or pm.batteryLevel), in order to use them inside an IF to make the CF land under a certain threshold.
By the way, what threshold would you advise to set?
I have already tried as in viewtopic.php?t=1835 with
and also with
as in https://github.com/bitcraze/crazyflie-l ... issues/227, but nothing is working.
I would really appreciate your help, Thanks!
I'm logging values as in https://github.com/bitcraze/crazyflie-l ... py#L75-L84, but I'd like to print (and store) the floating value of 'pm.vbat' (or pm.batteryLevel), in order to use them inside an IF to make the CF land under a certain threshold.
By the way, what threshold would you advise to set?
I have already tried as in viewtopic.php?t=1835 with
Code: Select all
import struct
import numpy as np
hexVal = hex(fp16Value)
y = struct.pack("H", int(hexVal, 16))
floatVal = np.frombuffer(y, dtype=np.float16)[0]
Code: Select all
struct.Struct('e').unpack_from(data)
I would really appreciate your help, Thanks!