ArduPilot:master
← mbuzdalov:edt-v2-support
opened 03:16PM - 25 Feb 24 UTC
### Description
This PR adds support for Extended DShot Telemetry v2, the spe…cification for which is available [here](https://github.com/bird-sanctuary/extended-dshot-telemetry). Currently, recent versions of Bluejay and AM32 support this specification, and I believe BlHeli32 also has some limited support.
Notably, EDTv2 introduces two new types of messages, which are useful to investigate the performance of ESCs:
- the "stress level" message that contains a number in the range [0..255], which is the greater the more effort an ESC had to make during commutation;
- the "status" message contains three bits for different warning levels: "alert", "warning" and "error", as well as the maximum stress level encountered, which is in the range [0..15].
The existing EDT parser handles these messages, but ignores them. This PR propagates them all the way through the `AP_ESC_Telem` machinery and logs the obtained information using two new log messages:
- `EDT2` logs the status messages, so it has fields `Alert`, `Warning`, `Error` and `MaxStress`;
- `EDTS` logs the stress messages, with the only field `Stress`.
### Implementation details
Note that two different messages needed to be introduced, because the stress messages come more frequently than the status messages, and the stress level itself is scaled differently. For instance, there is a non-obvious but linear correspondence in Bluejay code, e.g. 120 maps to 0 and 255 maps to 15, and other firmware providers can implement a different relationship.
As these messages come at a relatively low rate, and my use cases in particular use logging rate limiting, we do not want the information in these messages to be lost, there are two important implementation details:
- when the next message comes, the telemetry values are aggregated rather than replaced, that is, status bits are OR-ed, and stress values are max-ed;
- if the backend refuses to log the message, we don't drop the existing values, so that we do not lose any information, and the next attempt to log them may succeed.
### Tests performed
This PR was tested on two copters, one quadcopter using the FlywooF405S-AIO controller, and one coax copter using the MatekH743-WLITE controller, both running Bluejay 0.19+ on their ESCs. The logs I obtained during testing appear to be rather sane and consistent. I attached [one of them](https://github.com/ArduPilot/ardupilot/files/14396764/24-02-25_14-01-52_edt.bin.zip) as an example.
### Thoughts on firmware and log sizes
Initially I thought that the amount of new code seems to be not very large and should not lead to firmware exceeding the available size. However, it apparently exceeded the size on Pixhawk1-1M, so I surrounded the code with `#ifdef HAL_WITH_BIDIR_DSHOT`, which, retrospectively, makes sense.
Other than that, I think this contribution can be important to FPV flyers, so there is a merit to include it in low-flash builds that support bidirectional DShot. The rate of these messages in current ESC firmware implementations seems to be quite low, so it should also be rather safe from this perspective.