multiwii/baseflight — pull request #96 by kilrah (2014-04-28 18:24:48+00:00)
Title: Remote gain adjustment support

It's the thing I was missing the most in the otherwise great baseflight FW, all my other FCs have an inflight gain adjustment feature... so there it is.

Obviously setting everything in the CLI is not the most convenient way, but it works for now if you know what you're doing. Ideally it should be in the GUI, I've had a little try at it but my lack of web-oriented programming skills is badly showing. I can probably get the backend done but I keep breaking the display layout, I don't understand much about CSS...

![config](https://cloud.githubusercontent.com/assets/6065069/2820857/0e30fe78-ceff-11e3-8ed2-63704c0b14f0.jpg)

I noticed since then that we could reuse the pidnames[] array and just append P, I, D to populate the dropdowns, that way we're sure the destinations will match.

______________________________
For the Wiki or other user doc:

The remote gain adjustment feature is turned on with:
feature REMOTEGAINS

It presents 4 "remote gain adjusters" that can be configured through the CLI and each have the following settings (x is 1-4):
rg_x_mode
rg_x_min
rg_x_max
rg_x_source
rg_x_dest

rg_x_mode: How this adjuster works. 0=disabled, 1=enabled by an AUX position, 2=enabled when unarmed, 3=always enabled. If set to 1, you will need to choose in which AUX channel position(s) the adjustment is enabled in the GUI "Auxiliary Configuration", and it is recommended to use the failsafe feature (feature FAILSAFE) especially if you have enabled adjustment in a MED AUX position to avoid unwillingly triggering gain adjustment when no valid RC signal is present.
rg_x_min: Min value of the adjusted parameter when the selected AUX channel is at minimum pulse width.
rg_x_max: Max value of the adjusted parameter when the selected AUX channel is at maximum pulse width.
rg_x_source: Which AUX channel is used to adjust the parameter. Range 1-4 for AUX1-AUX4.
rg_x_dest: Which parameter should be adjusted. Linked to the PID table, see enum in mw.h. Currently, 0-9 are P terms of ROLL, PITCH, YAW, ALT, POS, POSR, NAVR, LEVEL, MAG, VEL. 10-19 are the I terms of the same, 20-29 are the D terms of the same, and 30 is TPA Rate.

So for example with:
set rg_2_mode = 1
set rg_2_min = 20
set rg_2_max = 150
set rg_2_source = 2
set rg_2_dest = 1

![clipboard01](https://cloud.githubusercontent.com/assets/6065069/2820923/acfccf3c-ceff-11e3-849d-e207deb89749.jpg)

RG2 will adjust PITCH_P between 20 and 150 based on AUX2's position when enabled by AUX1 HIGH.

Important notes:
The remote gain adjustments are done in RAM, and are not saved into EEPROM automatically. Connecting to the GUI, going to the PID Tuning page, refreshing and saving is required. It's a good idea to do it to review the result anyway. Be aware that entering and exiting CLI WILL also save everything. Until saved cycling power to the board will reload the previous values.