Fix inverted TPA pitch-compensation sign in fixed-wing throttle - #11952
sensei-hacker wants to merge 1 commit into
Conversation
calculateTPAThtrottle() computed groundCos as the NED down-component of the aircraft's forward vector (positive diving, negative climbing), then multiplied it directly by tpa_pitch_compensation, which is documented and range-limited (0-20) to *increase* throttle when climbing. The unsigned multiply produced the opposite: throttle was reduced when pitching up and increased when diving. The earth-frame Z sign convention here (raw frame is up-positive, not NED) was independently settled by iNavFlight#11869 while auditing the wind estimator, which flagged this exact TPA inversion as a follow-up. The underlying vForward/groundCos construction is correct and shared with wind_estimator.c's fuselageDirection, so the fix negates only at the point where groundCos is applied to throttleAdjustment, rather than touching the vector construction itself. tpa_pitch_compensation has always been >= 0 (settings.yaml min: 0), so no existing tune could have used a negative value to work around the inversion. Any fixed-wing craft currently relying on the old (inverted) behavior will see TPA pitch compensation reverse direction after this fix - flight testing is needed to confirm.
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoCorrect fixed-wing TPA pitch-compensation direction
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper |
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #11952 245 targets built. Find your board's
|
|
This is an interesting one. Because the mention of increasing the throttle or decreasing it seems very misleading. It was even written this way in the explanation of the setting.
This is what it does currently. And would be totally wrong if it is altering the actual throttle output. That would be a backwards move. However, from what I remember when I was reviewing I think the complexity comes by the way the wording appears to be a double inversion of the throttle. But when you add Plane is flying level.
Plane is commanded to climb (e.g. 20degs)
Plane is commanded to dive (e.g. 20degs)
Notice how 1 and 3 both command the throttle to increase. But the Then noticed how 2 and 4 both command the throttle to reduce. But the Granted I could be wrong. But I haven't seen the control surfaces oscillate on any of my planes when using Does that make any sense ? |
|
I think I take it the idea is to "virtually" adjust the throttle passed to As an aside I don't really understand the need for And perhaps better to use constants to convert rads to degrees rather than using raw numbers. |
|
Yes, sorry guys. This shouldn't be here. It was a process error that you guys even ended up seeing this.
Yeah the machine got confused there, I think. (But I will double-check just in case). That's similar to I remember for APA initially it estimated a "virtual throttle" based on the airspeed, then fed that to the essentially TPA. But throttle is itself a proxy for airspeed, so it was using the actual airspeed as a proxy for a virtual throttle, as a proxy for the airspeed. If I had unlimited time and energy, I'd apply the same treatment to TPA pitch, eliminating "virtual throttle". |
|
There is a different PR attempting to fix the ACTUAL problem. A comment in the code said: And settings.yaml said: The machine saw that the actual behavior didn't match the "documented intent". It wanted to fix the code to match the documentation and comment. Settings.yaml hopefully fixed in: |
Summary
calculateTPAThtrottle()insrc/main/flight/pid.cappliestpa_pitch_compensationwith the wrong sign, so fixed-wing TPA pitch compensation currently reduces throttle when climbing and increases it when diving — the opposite of the documented behavior ("Positive values will increase throttle when pitching up, and decrease throttle when pitching down").Root cause
groundCosis the NED down-component of the aircraft's forward vector (vForward = {x, -y, -z}ofHeadVecEFFiltered), so it is positive while diving and negative while climbing.tpa_pitch_compensationis range-limited to[0, 20](always non-negative), so multiplying it directly bygroundCosdecreases throttle on climb.This earth-frame Z sign convention (
HeadVecEFFiltered.zis up-positive in the raw frame, not NED) was independently settled in #11869 while auditing the wind estimator's equation 12. That PR's "Follow-ups" section flagged this exact TPA inversion:Two corrections to that follow-up / to this task's original assignment, found during investigation:
calculateTPAThtrottle()— no second function (calculateAutoTransitionTargetTPAThrottle()) exists anywhere in the codebase; that name appears to be stale.tpa_pitch_compensation'smin: 0in settings.yaml means no user could have "compensated" for the inversion with a negative value — the setting has never accepted one.The
vForward/groundCosconstruction itself is correct and shared withwind_estimator.c'sfuselageDirection, so the fix negates only at the point of use (throttleAdjustment), not the vector construction.Testing
tpa_pitch_compensation> 0 will see the compensation direction reverse after this fix (previously reduced throttle on climb; will now increase it, as documented). Flight testing is needed to confirm the corrected direction feels right and to re-tune if needed.Related
Follow-up to #11855 / #11869.
https://claude.ai/code/session_017mXYKN2RCu49ZtumhXfutw