paparazzi / pprzlink

Message and communication library for the Paparazzi UAV system
Other
24 stars 55 forks source link

BUG: Python's PprzMessage doesn't cast values to the specified types #124

Open MJafarMashhadi opened 4 years ago

MJafarMashhadi commented 4 years ago

msg[value_name] is always of type str and the fieldtypes property is ignored there (at least for numbers). It's only used when converting to/from binary.

gautierhattenberger commented 4 years ago

Yes, it is true that data in message fields have the same type than the element stored inside. So when they are filled from IVY strings, I guess they all end up as str as well. It's not really a bug, nor a feature... Mostly laziness I guess :( If you have a clean solution for that, it could be integrated, as there is no reason to store data with the wrong type. And that would avoid explicit cast when extracting them on user side (like here: https://github.com/paparazzi/paparazzi/blob/master/sw/ground_segment/python/multi/fc_rotor/fc_rotor.py#L116)

MJafarMashhadi commented 4 years ago

Explicit casting was exactly what I had to do as well!

I think doing the type casting right in ivy_string_to_payload and binary_to_payload would do the job. Also it'd be nicer to have a dictionary mapping names to a 3-tuple of value, dtype, and coef instead of keeping 4 separate lists in-sync for them.