--[[ SCRIPT: stick2rate.lua AUTHOR: Mike Shellim URL: http://rc-soar.com/opentx DATE: 14 Sept 2014 VERSION: 1.0 DESCRIPTION: Script to convert stick position into rate command. Typical usage: for controlling a gimbal for smoother control and 'nudging'. Pull SH to recentre TESTED OpenTx v. 2.08 INPUTS ctrl: control stick 'ail' (default), 'ele', 'thr', 'rud' Sens: sensitivity (1 - 100, default = 50) INSTALLATION 1. Save script with .LUA extension, store in /SCRIPTS/MIXES folder on SD Card 2. Open Custom Scripts menu in the transmitter 3. Assign this script to empty slot 4. Open script, and test by moving aileron stick and observing 'gimb' output 5. Close Scripts menu 6. Check that [i]gimb appears in the mixer Src list MIXER SETUP - In the gimbal channel, create single mixer line, call it 'gimbal' - Specify Src = [i]gimb --]] local gimbal = 0 -- local control_id = {} -- array of control ids local SENS_ADJUST = 2048 ------------------- -- inputs / outputs ------------------- local inp = { { "ctrl", VALUE, 1, 4, 1}, -- index into array of control. Default = 1, i.e ail { "sens", VALUE, 1, 100, 50 } -- sensitivity } local out = {"gimbal"} -- output position ---------------------------- -- initialisation function ---------------------------- local function init_func() -- Store ids of permissable gimbal controls -- (saves expensive lookups in run_func) control_id [1] = getFieldInfo ("ail").id control_id [2] = getFieldInfo ("ele").id control_id [3] = getFieldInfo ("rud").id control_id [4] = getFieldInfo ("thr").id -- switch SH control_id [5] = getFieldInfo ("sh").id end ------------------------------- -- periodically called function ------------------------------- local function run_func(ctrl, sens) -- Is user re-centring? if getValue (control_id[5]) == 1024 then -- Recentring gimbal = 0 else -- (not recentring) -- Get stick position local pos = getValue (control_id[ctrl]) -- integrate gimbal position gimbal = gimbal + pos * (sens / SENS_ADJUST) -- handle end stop condition if gimbal > 1024 then gimbal = 1024 elseif gimbal < -1024 then gimbal = -1024 end end -- done return gimbal end return {init=init_func, run=run_func, input=inp, output=out}