Fix PID derivative kickoff and reset #1403
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes some unwanted consequences of #1337
Since the D term now uses the difference of current and previous measurements (instead of errors) this introduced two issues:
for yaw, flying near 180deg yaw results in D spikes (measurements jumping between +180 and -180)
the pid internal measurement state is being reset to zero, which is not true for x, y, z, and attitude angles. This resulted in a D spike at the beginning of every flight
Both of these issues get especially noticable when LP filters are being used in the PID, as the spikes will propagate in time.
For 1), I removed the
pidSetError
functionality, as it was only used to deal with yaw discontinuity around +180/-180.Instead, an additional parameter in
pidUpdate
is now used to enable extra code inside the pid that deals with the discontinuity.For 2), the reset now takes into account current state values (x, y, z, roll, pitch, yaw).
TODO: The reset in src/modules/src/crtp_commander_rpyt.c is not yet fixed, as I did not find an elegant way to read out the x,y,z states.
Still, even without the last TODO item, this should fix the majority of use cases...