Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PID derivative kickoff and reset #1403

Merged
merged 2 commits into from
Sep 9, 2024

Conversation

matejkarasek
Copy link
Contributor

@matejkarasek matejkarasek commented Aug 23, 2024

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:

  1. for yaw, flying near 180deg yaw results in D spikes (measurements jumping between +180 and -180)

  2. 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...

Copy link
Member

@gemenerik gemenerik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't observed the spikes in practice, though they seem logically possible. Thanks for your patience and for the PR.

src/utils/src/pid.c Show resolved Hide resolved
src/modules/src/controller/controller_pid.c Outdated Show resolved Hide resolved
@gemenerik gemenerik merged commit 557cee7 into bitcraze:master Sep 9, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants