Plane: add input shaping to roll and pitch controllers#32743
Conversation
|
@lthall One thing I have noticed with having a jerk parameter is that if the acceleration limit is much larger than the jerk limit the I don't think its really a fundamental problem, but it does make me think moving to a time constant like copter will stop users from causing themselves issues, although I think the separate jerk limit is conceptually easier to understand. |
|
|
||
| // Calculate angle error and apply gain | ||
| angle_err_deg = angle_target_deg - get_measured_angle(); | ||
| const float desired_rate = (angle_err_deg / gains.tau) + rate_target_deg; |
There was a problem hiding this comment.
Adding the rate feed forward here results in significantly more overshoot. Just angle_err_deg / gains.tau is much better.
There was a problem hiding this comment.
I think if you can get a good tune this is not such a issue. I'm not sure of a way we can mitigate this without also loosing some of the benefits.
Yes, this algorithm was not designed with the intention of providing a Jerk limit primarily. It works on the assumption that the primary limit is Acceleration and that Jerk will be set high enough that it is primarily limiting the acceleration, not the velocity. I don't think this is a problem provided we provide clear guidance. |
e93147d to
b96a132
Compare
bb04225 to
56426f3
Compare
|
@IamPete1 main thing I'd like to see is an analysis of the impact on upset recovery, we want to ensure this doesn't re-introduce the problem with slow upset recovery. For example, maybe disable when inverted? |
56426f3 to
fcb5e90
Compare
The pitch controller will not apply rate limits if inverted and the roll controller will not apply rate limits if the
One way to fix this would be to constrain the attitude resets to be within the normal attitude envelope in those cases.
I have added a checker the plane and a reset function in the controllers. I have not yet tested it thoroughly. |
|
This now uses the existing time constant as the axis time constant and adds a new angle gain for each axis. |
cf4dd4e to
ff2313f
Compare
Georacer
left a comment
There was a problem hiding this comment.
Really nice to have this feature! Perhaps now we'll be able to assess whether the roll/pitch angle tracking is well-tuned based on actual angle reference tracking and not angle rise times.
For now this is a review based on visual inspection. I'll test it in a 2nd pass.
Some additional comments:
IIUC tau (aka *2SRV_TCONST) is getting shadowed by the new *ANGLE_P parameter when input shaping is enabled. Is this correct?
Instead it's used as a gain for the jerk limit, which is a different usage, not covered by its parameter description.
It's not a problem for a first-pass implementation, but shouldn't we keep only one of the two? And/or deduplicate the usage of tau?
| float get_rate_out(float desired_rate, float scaler); | ||
| virtual float get_servo_out(int32_t angle_err, float scaler, bool disable_integrator, bool ground_mode) = 0; |
There was a problem hiding this comment.
Nice! I never liked those method names anyway!
| "RFNS", "QBBBBfffffIf", "TimeUS,InUse,InRng,IRCnt,Ms0OK,Ms0,Dst,Cor,Cor0,CorL,TimeCL,HE", "s----mmmmmsm", "F----00000C0", true }, | ||
| #endif // AP_RANGEFINDER_ENABLED | ||
|
|
||
| // @LoggerMessage: ATIS |
There was a problem hiding this comment.
How about logging Demanded, Target, Actual like we do in Copter? These now exist and have the same meaning, no?
There was a problem hiding this comment.
Yeah, we certainly could. This was really a first pass at logging which logs everything.
There was a problem hiding this comment.
I had a think about this, I decided I like it better like this. This only logs the shaped angle and the angle error. If we did add demanded and actual that would be four extra fields which are already in the ATT message. The angle stuff is also redundant for VTOL modes, the velocity and acceleration logged is useful in all modes.
Although I could certainty see the case that we might want to log the shaped target in ATT since that is what people are used to logging. Now to get the full picture you need target and actual from ATT and the shaped target from ATIS.
Open to ideas.
There was a problem hiding this comment.
I have improved the field descriptions.
Sort of, the way the maths works results in the same rate demand from the error path using the old method as the feed forward path and the new method. So by re-using the same param we matain the same "feel". The angle gain can then be used to tune the disturbance rejection. So we do need both, but your totally right that I should update the TCONST param description. |
|
I have done a plane version of the kinematic tool that I hope will help explain how the new code will behave in comparison to the current code. https://firmware.ardupilot.org/Tools/WebTools/KinematicTool/plane/ |
…attitude controlers
…ide of input shaping
…altitude to settle
35776ad to
3edd9d6
Compare
3edd9d6 to
7718b99
Compare
| } | ||
|
|
||
| // Apply gain using sqrt controller | ||
| float desired_rate = sqrt_controller(angle_err_deg, angle_gain, accel_max * 0.5, dt); |
There was a problem hiding this comment.
@lthall I have copied this from copter, why use half the accel limit? With the input shaping that means we could attempt 1.5 times the accel limit.
There was a problem hiding this comment.
Maybe I should add that I don't think there is really any right or wrong answer here, you could make arguments for using 1, or you could make a argument to limit the input shaped path to 0.5 too. 0.5 here seems like a nice middle ground. Just want to make sure I'm not missing something.
|
I'm now quite happy with this, I think we just need to build testing hours. Looking for feedback on user facing stuff like param names and usage and logging. I did wonder if we should take the opportunity to get rid of the "2SRV" stuff. |
|
Failed to fly this due to rebase issue |


Summary
This adds input shaping to the roll and pitch controllers with new accel and jerk limit params for each. This should result in much smoother flight.
Classification & Testing (check all that apply and add your own)
Description
This uses copters "real time s-curves" to shape the angle demands using the existing rate limits and new acceleration and jerk limits. This adds a new
ATISlog message that shows the result of the input shaping. Currently this logs all the time (under the attitude bit), but once were happy with it we may want to turn it off by defualt.Through testing we need to find good default values for the accel and jerk limits. The user can disable the new input shaping by setting either accel or jerk limit to zero.
Example of "raw" roll angle and shaped roll angle:
Some existing features are still missing: