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

Better handling of motor power distribution #1147

Merged
merged 7 commits into from
Nov 15, 2022

Conversation

krichardsson
Copy link
Contributor

This PR updates the power distribution.

Previously the motor power has been capped per motor if the desired thrust exceeds the maximum possible thrust. In this PR the capping has been updated to maintain the relative power of the motors and the trust of all motors are reduced equally much. The intention is to prioritize attitude over altitude to reduce the risk of flipping.

The power distribution code has also been refactored to make it easier to understand and test.

Moved all thrust manipulation to the stabilizer loop for better overview.
Added a platform specific cap function to allow a platform to cap thrust in more meaningful way.
@krichardsson
Copy link
Contributor Author

@matejkarasek I have updated the power distribution a bit and thus modified the flapper power distribution file. It all looks good (in my opinion) but I have note tested on a real Flapper. The intention is that the functionality should be identical to before, would it be possible for you to take a look?

  • Kristoffer

@matejkarasek
Copy link
Contributor

Thanks for the heads up, will try to test it and report back soon.

The new capping method, which prioritizes the attitude, could also be interesting for the Flapper :)

@krichardsson
Copy link
Contributor Author

Agree, I think it can be interesting for the Flapper as well. I did not want to change anything without checking with you first :-)

motorPwm->motors.m2 = limitThrust(motorThrustBatCompUncapped->motors.m2, 0, UINT16_MAX); // pitch servo
motorPwm->motors.m3 = limitThrust(motorThrustBatCompUncapped->motors.m3, 0, UINT16_MAX); // yaw servo
motorPwm->motors.m1 = limitThrust(motorThrustBatCompUncapped->motors.m1, idleThrust, UINT16_MAX); // left motor
motorPwm->motors.m4 = limitThrust(motorThrustBatCompUncapped->motors.m4, idleThrust, UINT16_MAX); // left motor
Copy link
Contributor

Choose a reason for hiding this comment

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

copy&paste error in the comment, should be :
// right motor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks!

@matejkarasek
Copy link
Contributor

matejkarasek commented Nov 10, 2022

So I tested this on the flapper platform and all seems fine, thanks!

@krichardsson
Copy link
Contributor Author

Great!
Thanks @matejkarasek !

Copy link
Member

@tobbeanton tobbeanton left a comment

Choose a reason for hiding this comment

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

Looks good and something we should have done a long time ago.

@tobbeanton tobbeanton merged commit fce6f32 into master Nov 15, 2022
@krichardsson krichardsson deleted the krichardsson/power-limitation branch November 18, 2022 09:15
@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