Setting Q_TRIM_PITCH via LUA script

I have written a small LUA script for VTOL aeroplanes to set Q_TRIM_PITCH correctly by transmitter using a 3-way switch. This may be necessary if the pitch angle trim difference (Q_TRIM_PITCH) deviates too much from the preset zero degrees and the VTOL wants to fly forwards or backwards when hovering in QHOVER or QSTABILIZE.

Q_TRIM_PITCH is the pitch angle trim difference between the calibrated AHRS level and the pitch angle. It can be reasonably estimated or set with little or no wind (and under no circumstances in QLOITER mode). The setting in QHover works the easiest.

For this purpose, a 3-way switch is assigned to the Lua script via RC_OPTION 300. The change between centre and the upper or lower switch position increases or decreases Q_TRIM_PITCH by one degree each case. The current Q_TRIM_PITCH value is displayed on a groundstation, an FPV display or the Yapouu widget.

The setting is made by hovering briefly in calm conditions. When hovering on the spot with neutral pitch stick, the VTOL should not accelerate forwards or backwards.

With an optional second switch (RCx_Option 301, 2-way switch or push-button is ok), Q_TRIM_PITCH value can be permanently written to non-volatile memory. Without second switch assigned, new Q_TRIM_PITCH value must be saved permanently by groundcontrolstation.

QTRIM.lua (2.0 KB)

Rolf