--[[ SCRIPT: DBLIM AUTHOR: L Shems URL: http://repository.justfly.solutions DATE: 28 Apr 2019 VERSION: 1.0 LICENSE: https://www.gnu.org/licenses/gpl-3.0.en.html DESCRIPTION: DeadBand and Rate Limiter: Implementation of a linear mapping of an input x to an output y with the input x between xmin and xmax and output y between 0 and 100% on both sides of the center position of the input xmin and xmax adjustable in-flight by any control source so: y = sign(x)* minimum(xmax, maximum(xmin, ( (abs(x)-xmin) * 100%/(xmax-xmin) ) ) To be used to create a dead band (zero output y) for any input abs(x) smaller than xmin and limit the output y to 100% for any input abs(x) greater then xmax and have a linear interpolation between these two endpoints (xmin,0) and (xmax,100) y ^ 100% ---- | / | / ^ | / | -----------0----------> x / | ^ | / | | | / | | | ---- -100% | | | | xmin xmax Source x to be provided in the script setup: i.e. snapflap -> choose stick ele (raw) or input ele Source to be provided to supply xmin: to allow in flight adaptation through i.e. slider S1. Source to be provided to supply xmax: to allow in flight adaptation through i.e. slider S2. Value xminv will override the xmin source value: set to -1 to disable value override. Value xmaxv will override the xmax source value: set to -1 to disable value override. Output y is provided as output To check the correct function and settings: Source x is provided as output xmin is provided as output xmax is provided as output --]] local P={} P.input = { { "x", SOURCE,}, -- x input value { "xmin", SOURCE}, -- xmin value via specified control, sign is ignored { "xmax", SOURCE}, -- xmax value via specified control, sign is ignored { "xminv", VALUE,-1,100,5}, -- xmin value forced setting, -1 is use xmin source { "xmaxv", VALUE,-1,100,95}, -- xmax value forced setting, -1 is use xmax source } P.output = {"y", "x", "xmin", "xmax", } -- periodically called function P.run=function(x, xmin, xmax, xminv, xmaxv) --set xmin, xmax if no input sources are given xmin = (xminv<0) and math.abs(xmin) or xminv*10.24 xmax = (xmaxv<0) and math.abs(xmax) or xmaxv*10.24 --limit xmin and xmax xmin = math.max(0,xmin) xmax = math.min(xmax,1024) --make sure xmax is greater than xmin xmax = math.max(xmin+1,xmax) return x/math.abs(x) * math.min(1024, math.max(0, (math.abs(x)-xmin) * 1024/(xmax-xmin) )), x, xmin, xmax end return P