MB3hel / AUVControlBoard

Vectored 6-DOF motion controller for AUVs.
https://mb3hel.github.io/AUVControlBoard/
1 stars 2 forks source link

[BUG] Crash on NaN Motor Speeds #28

Closed Bennett-Petzold closed 10 months ago

Bennett-Petzold commented 10 months ago

Describe the bug Sending NaN as a motor speed causes a reset with code -6.

Tested Versions v1 and v2

Impacted Versions v1 and v2

To Reproduce Send a stability_assist_2 command with a NaN as the x value.

Expected behavior Some non-crash behavior, likely a rejection of the message.

Additional context The code crashes because it gets stuck in a loop.

MB3hel commented 10 months ago

Now fixed on main. Will be in next 1.1.0 release.

When sending nan, inf, or other out of range values, the command is not rejected. The control board forces values into the valid range for arguments. In the case of nan or inf, they will be treated as zeros. This is consistent with the behavior described in the docs.

While it may be useful in this specific case to have out of range values be rejected with an "INVALID_ARG" error, this error is primarily intended to mean "incorrect number of arguments". Furthermore, rejecting out of range value with INVALID_ARG could cause other problems. For example, if the code sending speeds to the control board calculates 1.05 instead of 1.00 due to floating point errors, it would be undesirable for control board to reject the command. As such, out of range values are (by design) forced into range by the control board.

It is recommended to have value checks (for nan, inf, values with magnitudes much larger than 1, etc) in code using the control board (the code issuing commands). This can allow warnings to be logged if invalid values are generated before sending to the control board.

Once sent to the control board, it will force values into range to make it possible to execute the command.