-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
Lua Script for copter CoM compensation #27402
Conversation
d75c672
to
8a010a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dynamic mixer is great for finding the correct value, but it would be nice to transition people onto the normal mixer. Then you can just have a script that runs at boot with no callbacks. I think the load_factors
call skips the normalization step that we do on a "normal" matrix. So there could be some change in tune.
end | ||
|
||
-- Start running update loop | ||
return protected_wrapper() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return protected_wrapper() | |
return protected_wrapper() | |
Main loop function | ||
--]] | ||
function update() | ||
fsm_step() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might as well call this directly
@IamPete1 A static mixer would definitely bring better performance, agreed. But I really wanted to be able to tune on the fly. |
You could check if you can see the |
this is so common that I wonder if a param in the C++ code is warranted? |
You mean skip the .lua script entirely and implement this in C++? If so, I'd like to have this merged first and then dive into those deep waters 😅. |
How about I add the normalization step to the |
Using throttle factors does add some inaccuracy in the mixer. We do the full mix and then apply throttle factors afterwards, so there not taken into account for the saturation handling. Unless there is a quite significant issue its probably better not to set them and I would not recommend large values at all. As ever, a hardware fix is better if possible.
You would have to do it on every call to |
@IamPete1 is this what you meant? if MotorsMatrix then
is_mixer_matrix_static = true
warn_user("Found static mixer", MAV_SEVERITY.INFO)
end This check follows the truthy path even if |
8a010a3
to
af3c4d3
Compare
@IamPete1 I've pushed another another version. I've managed to implement dual operation, both dynamic and static scriptable matrices. Both use the same factors, normalized to have max 1. I've tested it in RealFlight. Some examples: Operation in Do you require any more specific testing? |
The script uses the scripting matrix to produce non-equal front and back thrust, compensating for the lever arm between the center of thrust and the center of mass.
af3c4d3
to
02ea9d1
Compare
Got another update in, to delete two unused variables. ❯ ./Tools/scripts/run_lua_language_check.py libraries/AP_Scripting/applets/x-quad-cg-allocation.lua
Initializing ...
>>>>>>>>>>========== 1/2
>>>>>>>>>>>>>>>>>>>> 2/2
Diagnosis completed, no problems found
2 Files checked |
I think you can just see if the singleton is nil. Something like:
Yeah, it doesn't get everything. The other one, |
I had tried the following before, but I believe was getting exceptions. -- Decide if the UA is using a static mixer matrix.
function inspect_mixer_matrix_static()
if MotorsMatrix then
is_mixer_matrix_static = true
warn_user("Found static mixer", MAV_SEVERITY.INFO)
end
end
-- Decide if the UA is using a dynamic mixer matrix.
function inspect_mixer_matrix_dynamic()
if Motors_dynamic then
is_mixer_matrix_dynamic = true
warn_user("Found dynamic mixer", MAV_SEVERITY.INFO)
end
end |
This PR is a script that corrects for the CoM discrepancy in a quad-X frame. It is applicable both in Copter and (quad)Plane.
I guess it's what #17461 was envisioned for.
It uses the dynamic mixer matrix to update the front-to-back thrust ratio on the fly.
I've been testing with RealFlight on this model, after "bringing it close to reality" by reverting the "cheat" I had made in the motor positions:
The issue with this model is that due to the CoM misplacement, a throttle-up causes a pitch-down. The script corrects the buildup of the pitch I-term and suppresses the pitch-down motion upon throttling up.
The results have been documented in this blog post.
If you think this script is too dangerous to exist in the
applets
directory, I'm happy with it being in theexamples
too.