-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add airspeed TPA support #11042
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
base: master
Are you sure you want to change the base?
Add airspeed TPA support #11042
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
|
This does look kinda over-complicated for historical reasons. But I'm not volunteering to refactor it, so I'm not really complaining. We originally saw we need to reduce the PID when airspeed increases. Because the force/lift from the control surface is proportional to ( 0.5 * airspeed) ². What we really wanted originally when TPA was introduced was the airspeed. But we often don't have the airspeed. So we used the throttle value to make a rough estimate of what the airspeed might be, in order to reduce the PID appropriately. Now when we DO have the airspeed (the value we wanted in the first place), we're using the airspeed to simulate a throttle value, in order to estimate how much the throttle value might affect the airspeed and therefore the PID. Kinda like: Given we already know the airspeed, there's no need to mess around with estimating a "virtual throttle", then estimating how much that will affect the velocity and therefore the force. |
I think this only explain the first half of the theory and it is not proportial but inverse propotional, The following are my thoughts, in short the angular velocity of the plane is propotional to the control surface multiplied by airspeed. If the old TPA assumes throttle is propotional to airspeed. then it is on same page with the following. And airspeed gain reduction(TPA) will need some internal variable to calculate, then why dont we use the virtual throttle value as the internal variable to maintain the compability, reducing the workload of users to shift from throttle based to airspeed based. Relationship Between Airspeed, Control Surface Deflection, and Angular Velocity in Model Aircraft1. Fundamental Dynamic EquationFor a single rotational axis (roll, pitch, or yaw):
Interpretation: 2. Steady-State ConditionIn our small plane, the plane enters Steady-State quily, that is why the plane is mainly driven by FF gain
Therefore:
3. Key Proportional Relationships
4. Quick Reference
Summary
High-speed flight requires smaller control deflections to achieve the same rotation rate due to aerodynamic damping and increased control effectiveness. |
Agreed. Therefore the deflection needed to generate the force is ~ inversely proportional. (Given assumptions). So no need to bring a simulated throttle into it. THAT said, you actually wrote the dang code. And it works, presumably. I didn't write it and probably wouldn't, so whichever way you want to write it is fine by me. I'm somewhat regretting having said anything because you do great work and my comment wasn't pointing out a real problem that needed to be fixed. It just felt awkward to do a "virtual throttle". Ps I had mentioned inversely proportional to (0.5 * V)², I see why you said inversely proportional to V itself. I see V is probably more correct for correcting for external disturbances, whereas V² would be for initiating maneuver, for starting a a turn. (If I understand correctly). On an unrelated topic - I wanted to let you know I'm hoping to cut an INAV 9.0RC1 in the next couple of weeks. Hopefully with airspeed PID attenuation included. I sent a build with this plus some other PRs over to James Downing for testing. |
I think V is more important for continuous control stick input , and V² is more important for everything else including disturbances and starting a turn. I am changing my mind. considering only V, then the TPA formula can be much simplier but have some promlems.
While the virtual throttle method has some extra parameters to toggle, or add a new parameter/modify δ = δref * Vref / V curiousto know how others think |
|
I love that I have someone to discuss this with who understands it better than I do. :)
It occurs to me that V^1.3 or V^1.4 will always be in between. I think V^1.3 would probably be a good compromise between the two. Of course, if you didn't want to do a decimal exponent, something like (0.5 * V) ^ 2 would also give a compromise value in between V and V² 😜
The baseline is not having any airspeed-based attenuation at all, so IMHO capping the attenuation at 4 * vref or so would be pretty good. It's not like it explodes at the cap. It just doesn't attenuate any further. I don't think the exact cap is critical. Of course one could smooth out the saturation by multiplying by (10 - Vfactor) / (Vfactor + 8) or whatever. (Where Vfactor = current airspeed / Vref). |
Yeah I expect the deflection will be approximately linear to the force (0.5V)^2 given the material is reasonably sized for the application. In the end, I suspect that's about the difference between V^1.3 and V^1.35. |
|
I'm looking to get INAV 9RC1 cut very soon so that 9.0 can be released in time to flash Christmas gifts with it. Based on the above discussion about using an exponent of around ^1.3 or ^1.5, and the testing by @trailx , do you expect to make further refinements on this soon? |
|
My tests showed the current And due to this. I also think it might be good to have the Just to add a bit more. I think it would also aid attenuation/boost response time if Down Pitch was accounted for in the calculations. I noticed there was occasionally a little bit of lag in the virtual airspeed. Likely GPS velocity related. Another thing that would be helpful for tuning. Is if the TPA gain changes could be shown on the OSD |
10ae664 to
4c44d5f
Compare
|
@sensei-hacker |
|
Update the pitot LPF Hz default value to 1hz, default 0.35hz is lagging |
|
@shota3527 Thanks for the extra commits.. You've ticked a lot more boxes with its handling. However, I don't mean to come across ungrateful for your work here. But integrating pitch angle based on + or - from gravity vector, would help in a GNSS failure or if a reduction in airspeed accuracy occurs in aerobatic maneuvers, which Turnrate can't detect either... Or the pitot tube gets partially blocked. It's in the case of a dive condition that the current fixedwing TPA doesn't work correctly. Because throttle can be low and airspeed will still rise in a dive. |
|
I got two flights in today on this PR. I'll try to keep my notes short. Wind was between 10-15 mph according to both feel and windspeed estimator in INAV. Once again I took off into my airspeed-driven 3-profile setup. I had a switch that would lock the middle profile, which is the one that had airspeed-pid-attenuation power at 1.20. Reference airspeed was set to 55 mph, where profile 2 maxed out previously. First flight, overall everything performed as expected. Low speeds worked flawlessly, showing excellent control at low speeds even in the wind. I did run into some oscillations in the 75+ mph range, but I noted that my pitot was under-reporting airspeed. I have both GPS 3D speed and airspeed on the OSD, and airspeed was consistently low. I've had a consistent struggle with this and am working on tuning the scale properly. Assuming this was the issue, I landed and adjusted the scale. Second flight, the airspeed was more inline with expectations at normal flight speed, while over-estimated at low speeds. I think the FC restart in windy conditions disturbed the zero offset. That said, the oscillations were gone. I did a few steep power off and power on dives without issue. Overall, this flew extremely well, and I'm looking forward to getting my pitot sensor dialed in a little better, and further adjusting things as needed. I'd like to try flying with the virtual pitot too. TLDR:
Thanks for all your work on this! |
|
In case of climb/dive situation, how about based on current throttle based tpa, offset the throttle value by "pitch to throttle value"(i forget the variable name but it is in navigation settings). Then hopefully no additional parameters needed. I am also thinking about raise the default tpa value from 0, if it is also 0 in the default presets. |
@shota3527 Yes, good thinking. It didn't occur to me to use |
Agreed. The force of gravity accelerating the aircraft (replacing motor thrust) is proportional to the sine of the angle. |
|
I've flown the current implementation on my Penguin a few additional times since my last update, and it flies great. No more need for my stepped PID attenuation program. Today's flight had very little wind, and I was able to confirm the calibration on my airspeed pitot. With that correct, I didn't run into any oscillatory issues, but those oscillations could also have been adjusted by applying a higher attenuation power. Again, it would be nice to be able to adjust this in flight, but I don't feel its imperative for inclusion on 9.0 RC. I am curious if the 1.20 power on Airspeed TPA will be a constant for all planes, but I do believe its a solid starting point, and luckily - its adjustable. TPA meaning Throttle PID Attenuation does seem like a bit of a misnomer now. I'm going to propose we keep "TPA" though, since its now embedded in the lexicon of INAV/BF, but I propose we change its interpretation to mean "Tuned PID Attenuation". So Airspeed TPA meaning "Airspeed-Tuned PID Attenuation" still makes sense. Certainly more sense than "Airspeed Throttle PID Attenuation". Standard Throttle TPA can then be referred to as Throttle-Tuned PID Attenuation. I think it would be best to differentiate it as "Throttle TPA" in any documentation updates. |
|
My friends and I have also been testing this feature over the last week. From what we can tell it works good.
@shota3527 I agree with this. Tuning is noticeably more time consuming. It would be awesome if |
|
AFAKI, this isn't to replace TPA. But to be a better option if you can use it. So my recommendation would be to leave Also, adding adjustments and the appropriate OSD elements should be pretty simple. It would also be nice to see the setup to this in Configurator above or below the |
I was wondering why this new feature was still being called TPA if T means throttle... but yes I think APA makes better sense, or since Air Speed can be abbreviated as AS, ASPA would be another option. |
|
updated cli variable name to apa |
|
@shota3527 Thanks for your work on this. https://github.com/iNavFlight/inav/wiki/PID-Attenuation-and-scaling Edit: Have a look at the part I wrote as a caution. What is you view on this with the use of high power airplanes ? Or have I missed something in TPA/Pitch angle operation. |
|
Lots of info in there @Jetrell. I don't know what the right mechanism would be for providing feedback on different parts. There are a few small items I see. Overall I appreciate the detail, though it may be bordering on too much information for the average user and may result in overload. Since you asked specifically about the caution about planes with high thrust to weight, where did the referenced 1.3:1 power/weight ratio come from? The resolution implies that the TPA_rate would need to be adjusted, but I'd think the pitch2throttle would be the item you'd ideally adjust, right? I think if P2T is adjusted to maintain a constant speed during climb and dive, then it should be relatively well tuned. Until there's more time on it, I think the warning may be clearer if it states: while the system adjusts the PIDs proportionally through vertical pitch and dive angles, it may not be well tuned beyond climb and dive angles seen in typical autopilot flight profiles (+/- 30 deg). Also, here are some reference images that should help visualize how the system adjusts the attenuation/gain curve depending on a few factors. I found the reference images provided previously to be really helpful to help me understand what was going on behind the scenes.
|
|
@trailx You'll notice the Wiki is broken into 4 categories at the top. The middle two are related to these changes.
The 2 new Fixedwing categories do not over lap in their operation. This is why their operation is explained separately. The one with the Caution is Fixedwing TPA and Pitch angle category. Not APA - I wanted to hear whats @shota3527 view on this is.
It takes a thrust to weight greater than approximately 1.3 : 1 to be able to hold a continuous vertical climb rate. Even to hold a good hover or prop hang, you require greater than 1 : 1 . Or you will have no thrust overhead to maintain it.
Maybe. But what isn't included is bound to be asked by someone when they experience a certain condition related to how one of those methods operate. |
I saw that, I think the layout makes sense and the separation is pretty clear. I think we're aligned on how it all works. Personally, I just absorb diagrams better than long descriptions. But I agree that nearly all of the content is necessary and helpful if someone reads it. But to a new user, it may feel abstract. Visually representing how pitch2throttle influences the TPA curve is tricky, but maybe we can come up with a diagram to help visualize that too.
Ok, so the 1.3:1 is a general rule of thumb for planes capable of vertical flight. I agree that high pitch angles can produce oscillations. Adding pitch2throttle certainly helps the pitch-based TPA behave better, but I still think vertical flight profiles are outside the regime this method was really intended for. While P2T will influence the effective “synthetic throttle,” it won’t fully correct behavior once you’re far beyond typical climb angles. For the caution, maybe wording like below would address the concern more directly: While the TPA-with-Pitch system adjusts PID gains proportionally through the full pitch range, it may produce unexpected results or oscillations at extreme nose-up attitudes (beyond 30–40 deg). In your description of nav_fw_pitch2thr, you mention that:
I’m curious why you believe 10-11 is ideal, because I think the optimal number will vary between different airframes. It may help to describe how users can tune this variable when integrating into pitch-based TPA:
|
|
I agree with @trailx with
Some recent PNP models' power combinations have a very wide speed range. from 50km/h to 130km/h, even 200+km/h in the dive. I don't think the current 2x-0.5x range is sufficient in theory. but one thing needs also keep in mind is the deflection in the linkage/sarvo will reduce the throw in high speed. more Attenuation might lead to insuffcient actual throw in control surface And I believe the default values of these may also require some adjustment. |
|
For this document, i suggest to change the order of APA and TPA on the FW side. I think the virtual pitot-based APA is better than TPA, and it should always be used if available. I think the airspeed estimate is accurate, even GPS 3D speed along is better than TPA. Additionally, TPA has more parameters to tune. Who knows the relationship between the throttle/pitch angle/weight/inertia of the plane? |
No problem.
I agree. However, due to TPA and Pitch angle being a fall back if the airspeed source fails while using APA. It should also be tuned.. The one with the Caution is Fixedwing TPA and Pitch angle category. Not APA - apa_pow / fw_reference_airspeed |
|
Yes, throttleAdjusted will decrease when the pitch is up. A 2000us throttle will decrease to 1100us for calculation with the current default value, and then the PID might be too high. |
Due to this being a shared variable. We have to be cautions of how much this setting is altered, without it effecting the navigation climb/dive throttle. Meaning that the user would also have to retune all other setting related to pitch2thr for navigation. |
|
My penguin is overpowered, and the default pitch2thr would result in it exiting automated flight climbs at a very high rate of speed. Right now its at 8 and climbs well, if maybe still a little too strong. (In RTH I like it to pop up pretty fast) The difficulty is the non-linearity of throttle % vs airspeed, and the users just need to be aware that the addition of the pitch calculation is probably limited somewhat in its effectivity to the automated flight pitch limits (its not, but it effectively may be). Tuning pitch2thr so that when in automated flight the plane does high angle climbs and dives roughly at a constant speed may be a good prerequisite to tuning TPA. |
|
@shota3527 After reading yesterdays conversation. I took one of my planes with a 2:1 thrust to weight out to test it with commit 00c9db0. As it would appear in the logic and raised by Jet. The PIDs are boosted at high climb speeds, when the throttle is significantly above the I proceeded to alter the I'm aware setting variables are a limited hardware resource. However cutting corners on such an important feature as this is not the way to go. @shota3527 I would like to encourage your efforts towards implementing such an overdue feature. ❤️ What about adding a tpa pitch scaler variable that could be adjusted by the user if their plane has a high thrust to weight. It could reduce the effect PID boost would have on such aircraft at a high climb speed/angle, without altering the dive angle attenuation function. I have not forgotten that APA is still the best approach. But this method is also required to work well if the air speed source fails. How about this extrapolation? Adding |
|
@rts18 , I don't know how tightly you have your PIDs adjusted, but did TPA+pitch work for a certain range of pitch angles? At what angles, speeds, and throttles did you run into oscillations? How far did try you adjusting pitch2thr? I have to assume that at 0, it would not create this oscillation. I also assume that at 1, it will likely not create the oscillation. Academically, at some point, you should be able adjust the pitch-up-TPA-gain oscillation out of the system by adjusting the P2T. But at that point - where it no longer creates oscillations on a climb - does it create other issues from pitch2thr being too low? Rather than going on a hunt for new solutions to fixing TPA, at what point do we try to adopt something more akin to the "basic TPA" solution that was developed by betaflight? I don't think we need to consider betaflight's advanced method, because APA fills that gap, arguably better. I'm also a bit concerned that we won't find a solution to TPA that works in all situations - and APA gets held up. I don't want perfecting TPA to hold up the implementation of APA, and at least getting that improvement out to people in 9.0. |
Climbing vertical at 80 km/h @ 85% throttle. It has a 25.2v 700w power system.
No, why would it. Have you not read how the logic works. Down pitch works as it should. pitch angle overrides raw throttle and attenuates the gains if the plane is in a low throttle dive. Instead of boosting them as the old fixedwing tpa used to.
No it won't. This was the whole point of my last post.
Dude you worry too much. What's the good of merging something that has a known and real life tested bug. When things don't get cleaned up before a merge, you end up with bugs everywhere that never get addressed. |
|
My 2 cents. APA can be effected by the results of |
You're right, I wasn't thinking. And yes I fully understand how the logic works. I was really trying to understand the details of what you experienced. Down-pitch may over-attenuate, but you're right over-attenuation isn't the concern, it just becomes less stabilized. The concern is over-boost where it can generate oscillation. I think there's another potential issue when switching to TPA and simply flying level at high throttle because it may not attenuate enough because TPA's curve is flatter than APA.
It wasn't completely clear in your last post, so I wanted to understand. I've got my P2T down to 7 now and it still maintains speed in climb. I think I could probably go lower without issue. I may have my cruise throttle set proportionally higher than you to stay further away from stall.
Maybe you're right, its my engineering brain mitigating schedule risk. To me, APA is the single most important fundamental fixed-wing feature that I've been wanting and advocating for over the last couple years. That said, TPA has never controlled gains appropriately on a fixed wing, and I don't think it will ever function as well as APA. If it did, we wouldn't even need an APA solution. So that’s why I’m concerned about a fundamental mismatch here that may not have a solution: But, I realized last night that there may be a simple workaround for anyone using APA. I think you can avoid almost all TPA-fallback oscillation issues by setting tpa_breakpoint to a throttle value significantly below the throttle required to maintain the reference airspeed used by APA. For example, on my penguin, looking at the graphs, I’m thinking I'll actually set it to 1000, while it flies at the ref airspeed at about 1450. Doing this accomplishes several things at once:
This basically “chops” the PID gains if APA drops out. No code changes needed, just documentation of best practices, and this only becomes an issue if people start tuning higher PIDs, I doubt theres any issue when flying defaults. |
That won't have any effect on the reported condition because the throttle is still above the breakpoint no matter how far. @trailx Please stop distracting from the problem with workarounds. Open a chat in the Discussions section. shota3527 is a capable developer. He will fix the issue when he has time. There are two issues.
|
|
Let's not discourage active participation... I agree with you that the workaround I mentioned isn't the final solution, but openly talking through the issues is part of the process of solving it. I think if we put it simply, if TPA is the fallback, the solution needs to ensure TPA's gains are never above APA's. After more thought, I think I can boil my thoughts down to two code recommendations, and one general setup recommendation:
I'd like to test the fallback functionality directly... is there a clever way to force APA to dropout via a switch? Best I can think is setting up two identical control profiles, and setting APA_pow = 0 on one of them? |











User description
add a cli command to let fixed wing use airspeed based tpa.
It calculates the corresponding throttle value based on the airspeed. Ensure a seamless integration with the current throttle-based TPA. Turn it on with cli command and no more tunning is needed, fallback to old throttle based tpa if airspeed is not avaliable
tpa_breakpoint + (airspeed - fw_reference_airspeed)/fw_reference_airspeed * (tpa_breakpoint - ThrottleIdleValue(default:1150))
sim test ok
recommend to raise pitot_lpf_milli_hz on vitual pitot
PR Type
Enhancement
Description
This description is generated by an AI tool. It may have inaccuracies
Add airspeed-based TPA calculation for fixed-wing aircraft
New
airspeed_tpasetting to enable airspeed TPA modeRefactor TPA calculation to support both throttle and airspeed
Add airspeed validity check function for sensor health
Diagram Walkthrough
File Walkthrough
controlrate_profile.c
Initialize airspeed TPA settingsrc/main/fc/controlrate_profile.c
airspeed_tpafield initialization to control rate profile resetfunction
controlrate_profile_config_struct.h
Add airspeed TPA configuration fieldsrc/main/fc/controlrate_profile_config_struct.h
airspeed_tpaboolean field to throttle configuration structuresettings.yaml
Configure airspeed TPA settingsrc/main/fc/settings.yaml
airspeed_tpasetting configuration with descriptionpid.c
Implement airspeed-based TPA calculationsrc/main/flight/pid.c
calculateMultirotorTPAFactorto accept throttle parameterpitotmeter.c
Add airspeed sensor validity checksrc/main/sensors/pitotmeter.c
pitotValidForAirspeedfunction to check sensor validitypitotmeter.h
Expose airspeed validity functionsrc/main/sensors/pitotmeter.h
pitotValidForAirspeedSettings.md
Document airspeed TPA settingdocs/Settings.md
airspeed_tpasetting