Skip to content

Pr port hf4 hf5 fixes to 4.6.3 - #113

Open
vigneshm-debug wants to merge 2 commits into
airbound-develop-4.6.3from
pr-port-hf4-hf5-fixes-to-4.6.3
Open

Pr port hf4 hf5 fixes to 4.6.3#113
vigneshm-debug wants to merge 2 commits into
airbound-develop-4.6.3from
pr-port-hf4-hf5-fixes-to-4.6.3

Conversation

@vigneshm-debug

Copy link
Copy Markdown

This PR has porting of ArduPlane hotfixes 4 and 5 (versions V4.5.7.4-hf4/hf5 and V4.5.7.5-rc1) to the 4.6.3.

https://www.notion.so/airbound/backporting-HF4-HF5-to-4-6-3-38121adf4be980fb8fa9cb9bd17600c1?v=29721adf4be981d59032000c1dc9579e&source=copy_link

akshar-airbound and others added 2 commits June 16, 2026 06:44
* Add thrust vectoring desaturation and halved PID gain parameters (#99)

* Fix weathervane control slope based scale calculation error when control effort is between Q_TAILSIT_CE_LO and Q_TAILSIT_CE_HI (#82)

* Fix weathervane control slope based scale calculation error when control effort is between Q_TAILSIT_CE_LO and Q_TAILSIT_CE_HI

* Pixhawk6C-bdshot/scripts: Add vibration monitoring script and rename autobailout script filename

---------

Co-authored-by: akshar-airbound <[email protected]>

* Rename ab_autobailout.lua back to autobailout.lua for hf3 (#84)

* Update the version to V4.5.7.4 -hf1

* /AP_MotorsTailsitter.cpp:Update the desaturation logic

* Update the version to Airbound ArduPlane V4.5.7.5 -rc1 - Controller desaturation

* Update version to V4.5.7.4 -hf4 - Controller desaturation

* Reset yaw I term when disabling yaw control

* Update the angle p gains of roll and yaw axes

* Update the version to Airbound ArduPlane V4.5.7.4 -hf4 - Controller desat+ Half gain

* Update the fixed wing parameters

---------

Co-authored-by: akshar-airbound <[email protected]>
Co-authored-by: Mayank Joneja <[email protected]>
Co-authored-by: Manuraj P M <[email protected]>

* Add function to check tailsitter backtransition in quadplane class
Add lua bindings exposing above function for lua scripting

* autobailout.lua:Removed debug gcs strings

* Changed version to 4.5.7.4-hf3 + new autobailout
changed default value of parameter AUTOB_BTRN_DLY to 2500

* autobailout.lua: remove unused variables

* quadplane.cpp: add time argument to vtol transition function

* autobailout.lua: increase loop rate from 10 to 20 Hz
defaults.parm: Change param name TECS_SPD_WEIGHT to TECS_SPDWEIGHT

* Changed version name

* autobailoout.lua:Renamed variable

* Fixed TECS_SYNAIRSPEED 0 -> 1

* Change version name

* Reduce weathervane gain during pos1 pos2 repositioning

---------

Co-authored-by: akshar-airbound <[email protected]>
Co-authored-by: Mayank Joneja <[email protected]>
Co-authored-by: Manuraj P M <[email protected]>
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown

Greptile Summary

This PR backports ArduPlane hotfixes HF4 and HF5 to the 4.6.3 branch, covering tailsitter stability, thrust vectoring, auto-bailout logic, and Pixhawk6C-bdshot tuning parameters.

  • AC_AttitudeControl.cpp: Attempts to pass raw gyro yaw through to the rate controller during large thrust errors and reset the yaw I-term, but writes to the member _ang_vel_body.z instead of the local ang_vel_body.z — the assignment is overwritten by _ang_vel_body = ang_vel_body at the end of the function, so the gyro passthrough has no effect.
  • AP_MotorsTailsitter.cpp: Correctly adds yaw headroom limiting so pitch + yaw never exceeds tilt servo range, with a limit.yaw flag when clipped.
  • autobailout.lua: Renames AUTOB_MODE_DLYAUTOB_BTRN_DLY, inverts trigger from landing-detection to VTOL-flight monitoring with a back-transition settle timer, and adds mode exclusions; leaves is_vehicle_landing() as unreachable dead code.

Confidence Score: 3/5

The attitude controller fix in AC_AttitudeControl.cpp is broken as written and should not be merged without correction; the remaining changes are sound.

The yaw gyro-passthrough fix writes to the member variable _ang_vel_body.z but the function ends with _ang_vel_body = ang_vel_body (local), which silently discards the assignment. During large thrust-error recovery the rate controller will receive the error-derived yaw target rather than the raw gyro — exactly the condition the fix was meant to address. All other changes appear correct.

libraries/AC_AttitudeControl/AC_AttitudeControl.cpp — the member-vs-local variable mix-up needs to be corrected before merging.

Important Files Changed

Filename Overview
libraries/AC_AttitudeControl/AC_AttitudeControl.cpp Fixes yaw rate passthrough for large thrust errors — but writes to the wrong variable (_ang_vel_body.z instead of local ang_vel_body.z), so the fix is overwritten at line 969 and has no net effect on yaw control.
ArduPlane/quadplane.cpp Adds weathervane gain reduction (1/3 of max) during tailsitter QRTL position 2 approach; exposes tailsitter_in_vtol_transition() as a public method. Changes look sound.
ArduPlane/quadplane.h Moves Log_Write_AttRate() to private section and adds tailsitter_in_vtol_transition() to public API — matches the implementation changes.
libraries/AP_HAL_ChibiOS/hwdef/Pixhawk6C-bdshot/scripts/autobailout.lua Refactors bailout trigger from landing-detection to VTOL-flight monitoring with a back-transition settle delay; renames AUTOB_MODE_DLY to AUTOB_BTRN_DLY. is_vehicle_landing() is now dead code.
libraries/AP_Motors/AP_MotorsTailsitter.cpp Adds yaw headroom limiting for thrust vectoring: constrains yaw so pitch + yaw <= 1.0 and sets limit.yaw when clipped. Logic is correct.
libraries/AP_HAL_ChibiOS/hwdef/Pixhawk6C-bdshot/defaults.parm Vehicle-specific tuning: halved roll/yaw angle P gains, tightened pitch limits, added TECS_SPDWEIGHT, lowered TRIM_THROTTLE.
libraries/AP_Scripting/docs/docs.lua Adds Lua binding documentation for quadplane:tailsitter_in_vtol_transition() — matches the new C++ binding.
libraries/AP_Scripting/generator/description/bindings.desc Registers tailsitter_in_vtol_transition as a Lua-accessible singleton method on QuadPlane — correct and consistent with the implementation.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Lua as autobailout.lua
    participant QP as QuadPlane (C++)
    participant AC as AC_AttitudeControl
    participant Motors as AP_MotorsTailsitter

    Note over Lua: update() every 50ms
    Lua->>QP: tailsitter_in_vtol_transition()
    QP-->>Lua: bool (new binding)
    Lua->>QP: in_vtol_mode()
    QP-->>Lua: bool
    Note over Lua: in_vtol_flight() guards monitoring
    alt in_vtol_flight() and armed and delay elapsed
        Lua->>Lua: check pitch vs AUTOB_PIT_LIM
        alt "pitch bad for > AUTOB_PIT_TOUT ms"
            Lua->>QP: vehicle:set_mode(QLOITER)
        end
    end
    Note over QP: vtol_position_controller() QRTL path
    QP->>QP: weathervane set_gain(wvane_max_gain/3)
    Note over AC: attitude_controller_run_quat()
    AC->>AC: compute local ang_vel_body
    alt "thrust_error > 2x threshold"
        AC->>AC: "_ang_vel_body.z = get_gyro().z [BUG: overwritten]"
        AC->>AC: reset_I() on yaw PID
    end
    AC->>AC: "_ang_vel_body = ang_vel_body [overwrites .z]"
    Note over Motors: output_armed_stabilizing()
    Motors->>Motors: constrain pitch_thrust
    Motors->>Motors: "yaw_headroom = 1 - abs(pitch_thrust)"
    Motors->>Motors: limit yaw to headroom, set limit.yaw
    Motors->>Motors: "tilt_left/right = pitch +/- yaw_limited"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Lua as autobailout.lua
    participant QP as QuadPlane (C++)
    participant AC as AC_AttitudeControl
    participant Motors as AP_MotorsTailsitter

    Note over Lua: update() every 50ms
    Lua->>QP: tailsitter_in_vtol_transition()
    QP-->>Lua: bool (new binding)
    Lua->>QP: in_vtol_mode()
    QP-->>Lua: bool
    Note over Lua: in_vtol_flight() guards monitoring
    alt in_vtol_flight() and armed and delay elapsed
        Lua->>Lua: check pitch vs AUTOB_PIT_LIM
        alt "pitch bad for > AUTOB_PIT_TOUT ms"
            Lua->>QP: vehicle:set_mode(QLOITER)
        end
    end
    Note over QP: vtol_position_controller() QRTL path
    QP->>QP: weathervane set_gain(wvane_max_gain/3)
    Note over AC: attitude_controller_run_quat()
    AC->>AC: compute local ang_vel_body
    alt "thrust_error > 2x threshold"
        AC->>AC: "_ang_vel_body.z = get_gyro().z [BUG: overwritten]"
        AC->>AC: reset_I() on yaw PID
    end
    AC->>AC: "_ang_vel_body = ang_vel_body [overwrites .z]"
    Note over Motors: output_armed_stabilizing()
    Motors->>Motors: constrain pitch_thrust
    Motors->>Motors: "yaw_headroom = 1 - abs(pitch_thrust)"
    Motors->>Motors: limit yaw to headroom, set limit.yaw
    Motors->>Motors: "tilt_left/right = pitch +/- yaw_limited"
Loading

Reviews (1): Last reviewed commit: "ported hf4 anf hf5" | Re-trigger Greptile

Comment on lines +953 to +954
_ang_vel_body.z = _ahrs.get_gyro().z;
get_rate_yaw_pid().reset_I();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Assignment to member variable is immediately overwritten

The change writes _ang_vel_body.z = _ahrs.get_gyro().z to the member, but line 969 unconditionally does _ang_vel_body = ang_vel_body, which replaces the entire struct — including .z — with the local ang_vel_body that was never updated in this branch. The intended gyro-passthrough for yaw during large thrust errors is silently discarded, so the rate controller receives the error-derived yaw target instead of the raw gyro value. The original code correctly wrote to ang_vel_body.z (the local variable), which was then picked up by the final assignment. The fix should use ang_vel_body.z = _ahrs.get_gyro().z; so the gyro value survives to line 969.

Suggested change
_ang_vel_body.z = _ahrs.get_gyro().z;
get_rate_yaw_pid().reset_I();
ang_vel_body.z = _ahrs.get_gyro().z;
get_rate_yaw_pid().reset_I();

Comment on lines 63 to 69
function is_vehicle_landing()
local current_mode = vehicle:get_mode()
if current_mode == MODE_QLAND then
return true
elseif quadplane:in_vtol_land_descent() then
if quadplane:in_vtol_land_descent() then
return true
else
return false
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Dead code: is_vehicle_landing() is no longer called

The refactor replaced the is_vehicle_landing() guard in update() with in_vtol_flight(), but is_vehicle_landing() itself was left defined. It is now dead code and can be removed to avoid confusion.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@vigneshm-debug vigneshm-debug self-assigned this Jun 18, 2026
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.

2 participants