M0r13n / pyais

AIS message decoding and encoding in Python (AIVDM/AIVDO)
MIT License
176 stars 61 forks source link

Fix ROT decode rounding #130

Closed davidalo closed 6 months ago

davidalo commented 6 months ago

Hello,

When encoding and decoding some messages I found an inconsistency in ROT (turn). For some values it's inconsistent because to_turn function is truncating instead of rounding.

You can see the effect in the following screenshots:

image

image

I added a new test test_rot_encode_decode to cover this.

Related PR: https://github.com/M0r13n/pyais/pull/74 . I see that to_turn was rounding in the past, but it was changed for some reason. Could you shed some light on this?

M0r13n commented 6 months ago

Hey @davidalo,

The GPSD project - the de facto reference documentation for this project - does not round: https://gitlab.com/gpsd/gpsd/-/blob/master/devtools/ais.py#L117. Therefore, I dropped the round statement, because it caused some trouble for other users.

However, I am not 100% sure, since the values for ROT vary slightly from decoder to decoder. Depending on the decoder, there seems to be a certain confidence interval of +/- 5 degrees, in which all available decoders scatter. 🤷

For example the very same messages are decoded differently:

I am inclined to accept your PR with the addition to round to two decimals places.