Skip to content

Instantly share code, notes, and snippets.

@theely
Created March 1, 2021 07:25
Show Gist options
  • Save theely/071844902c9868cd5478194311e24df6 to your computer and use it in GitHub Desktop.
Save theely/071844902c9868cd5478194311e24df6 to your computer and use it in GitHub Desktop.
Behavioural Consistency - Testing Script
-- Testing Script to meause Behavioural Consistency
-- Credits to: Mactac for creating the original script
-- Instruction to install and run the script: https://youtu.be/tocH6IgbK7k
tricks = {{}, {}, {}}
-- Flip
tricks[1][1] = {200,800,0,0,0} -- Throttle bust {time,throttle,yaw,roll,pitch}
tricks[1][2] = {35,-1024,0,256,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][3] = {35,-1024,0,512,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][4] = {35,-1024,0,768,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][5] = {35,-1024,0,1024,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][6] = {400,-1024,0,1024,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][7] = {35,-1024,0,1024,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][8] = {35,-1024,0,768,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][9] = {35,-1024,0,512,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][10] = {35,-1024,0,256,0} -- flip {time,throttle,yaw,roll,pitch}
tricks[1][11] = {0,0,0,0,0} -- finalizing move
-- Switch assignments
-- You can change these around based on how your Taranis is set up.
-- Just make sure you use the correct switch types (ie 3 position or momentary)
local go_switch = "se" -- switch to execute trick (should be a momentary switch)
local trim_axe = "trim-rud" -- trim axe used to adjust timing
-- Other variables
local elapsed_time
local move = 0
local started = 0
local start_time = 0
local move_time =0
local trick =0
-- Outputs
local thr = 0
local yaw = 0
local roll = 0
local pitch = 0
local trim=0
local inputs = {
{"orig_thr", SOURCE},
{"orig_yaw", SOURCE},
{"orig_roll", SOURCE},
{"orig_pitch", SOURCE}
}
local outputs = { "thr", "yaw", "roll", "pitch", "trim"}
-- Maximum 4 characters
local function run(orig_thr,orig_yaw,orig_roll,orig_pitch)
trim = getValue(trim_axe)
-- which trick are we doing?
trick_num = 1
trick = tricks[trick_num]
if getValue(go_switch) > 1 and started == 0 then -- if trick not alrady started, then launch
started = 1
move = 1
end
if started == 1 then -- make sure we are not at end of trick
if start_time == 0 then -- start of a new move, reset timer
start_time = getTime()
end
elapsed = getTime() - start_time
move_time = (trick[move][1]+trim) / 10 -- converto to 10ms unit
if elapsed > move_time then -- go to next move
move = move + 1
start_time = getTime()
end
if trick[move][1] > 0 then -- has a next move (function table.leng not available)
thr = trick[move][2]
yaw = trick[move][3]
roll = trick[move][4]
pitch= trick[move][5]
return thr, yaw, roll, pitch, trim -- return new move
end
end
-- no trick in progress, default to mirroring sticks
thr = orig_thr
yaw = orig_yaw
roll = orig_roll
pitch = orig_pitch
start_time = 0
started = 0
move = 1
-- Return the values. Note that in addition to the 4 axes, we are also returning the value
-- of trim.
return thr, yaw, roll, pitch, trim
end
return { input=inputs, output=outputs, run=run }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment