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

Migrating default PID gains and filter settings to platform defaults and Kconfig #1122

Merged

Conversation

matejkarasek
Copy link
Contributor

Until now, PID values have been hardcoded, and could only be changed via permanent_parameters, or in a custom fork.
This PR enables using platform-specific PID gain values and filter settings.

  • PID gains are now defined for each platform individually in the [specific_patform]_defaults.h
  • defaults for low pass filter settings are in platform_defaults.h, and can be overridden inside [specific_patform]_defaults.h for each platform if needed
  • defines PID_FILTER_ALL and IMPROVED_BARO_Z_HOLD moved to Kconfig

@matejkarasek
Copy link
Contributor Author

Not sure what is going wrong with the build checks, all platforms build fine locally... Any ideas?

@krichardsson
Copy link
Contributor

After a very quick look (that is it might be completely wrong) I think the problem is that the unit tests can not include the platform_defaults.h file. You probably have to add it to the unit test config

You can run the unit tests with tb test

I will have mote time to look at the PRs next week

@knmcguire
Copy link
Member

Same here:) Please check what is causing the CI to fail

@matejkarasek
Copy link
Contributor Author

After a very quick look (that is it might be completely wrong) I think the problem is that the unit tests can not include the platform_defaults.h file. You probably have to add it to the unit test config

You can run the unit tests with tb test

I will have mote time to look at the PRs next week

Thanks for the pointer @krichardsson, will check it out!

@matejkarasek
Copy link
Contributor Author

matejkarasek commented Sep 30, 2022

So running tb test in docker passes all the tests.
But tb build fails at the same place as the CI.

The unit test config seems to already include the folder where platform_defaults.h is included, so it must be something else 🤔

- 'src/platform/interface/'

@krichardsson
Copy link
Contributor

The problem is not the unit tests, but building the python bindings. You can run them with tb test_python.

I think you need to add "src/platform/interface", to the include section of bindings/setup.py

@krichardsson
Copy link
Contributor

The call to commanderGetSetpoint() in attitude_pid_controller.c is also causing problems, in general it feels a bit "backwards". Maybe you can pass in the value of setpoint.attitudeRate.yaw as a parameter to the function instead?

@matejkarasek
Copy link
Contributor Author

matejkarasek commented Oct 3, 2022

The build errors are fixed, thanks for suggesting the correct solution :)

The call to commanderGetSetpoint() in attitude_pid_controller.c is also causing problems, in general it feels a bit "backwards". Maybe you can pass in the value of setpoint.attitudeRate.yaw as a parameter to the function instead?

I have removed the feedforward gain (where this is needed) from the current pull request as it can be treated separately.

How would you feel about updating the entire PID structure, such that it includes an extra feedforward gain, and everything is handled by the pidUpdate(...) function?
Next to yaw control, we use feed forward gains also in the velocity controller:

attitude->pitch = -runPid(state_body_vx, &this.pidVX, setpoint->velocity.x, DT) - kFFx*setpoint->velocity.x;
attitude->roll = -runPid(state_body_vy, &this.pidVY, setpoint->velocity.y, DT) - kFFy*setpoint->velocity.y;

@matejkarasek
Copy link
Contributor Author

The last 2 commits include the feedforward gain in the PID structure, how do you feel about this solution?

@krichardsson krichardsson self-requested a review October 4, 2022 06:43
@krichardsson krichardsson marked this pull request as draft October 4, 2022 06:44
Copy link
Contributor

@krichardsson krichardsson left a comment

Choose a reason for hiding this comment

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

I think it looks good!
The feed forward addition to the the PIDs is a nice feature

src/modules/src/attitude_pid_controller.c Outdated Show resolved Hide resolved
@matejkarasek
Copy link
Contributor Author

Ok, great to hear!

@matejkarasek matejkarasek marked this pull request as ready for review October 4, 2022 10:26
Copy link
Contributor

@krichardsson krichardsson left a comment

Choose a reason for hiding this comment

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

Nice!

@krichardsson krichardsson merged commit 2748522 into bitcraze:master Oct 5, 2022
@krichardsson
Copy link
Contributor

Merged. Thanks!

@krichardsson krichardsson added this to the 2022.12 milestone Dec 13, 2022
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.

3 participants