DeltaDev

simple gear script

Aug 1st, 2019
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.46 KB | None | 0 0
  1. -- Coded by Sirius
  2.  
  3. -- Check with other files
  4. dofile(LockOn_Options.script_path.."command_defs.lua")
  5. dofile(LockOn_Options.script_path.."devices.lua")
  6. dofile(LockOn_Options.script_path.."mainpanel_init.lua")
  7.  
  8. -- Declare self variables
  9. local gear_system = GetSelf()
  10. local dev = GetSelf()
  11.  
  12. -- 0.01 rep. 1000th of second, by 10 ms.
  13. local update_time_step = 0.01
  14.  
  15. make_default_activity(update_time_step)
  16.  
  17. local sensor_data = get_base_data()
  18.  
  19. -- Landing Gear
  20. local Gear = 68 -- Keys.iCommandPlaneGear
  21. -- local GearParam = get_param_handle("GEAR_LEVER")
  22.  
  23. -- Movement dependencies
  24. local GEAR_STATE = 1
  25. local GEAR_STATE_PARAM = 1
  26. local GEAR_COMMAND = 0
  27. local GEAR_TIME_IN = update_time_step / 5 -- 5 reps sec.
  28. local GEAR_TIME_OUT = update_time_step / 3 -- 3 reps sec.
  29. local GEAR_TIME_PARAM = update_time_step / 2 -- 2 reps sec.
  30. local GEAR_WEIGHT = sensor_data:getWOW_LeftMainLandingGear() -- checks if gear suspension is in place, needed for ground check
  31.  
  32. -- Wheelbrakes
  33. local BrakesOn = 74 -- Keys.iCommandWheelBrakeOn
  34. local BrakesOff = 75 -- Keys.iCommandWheelBrakeOff
  35. -- local LeftBrakeParam = get_param_handle("LEFT_TOEBRAKE")
  36. -- local RightBrakeParam = get_param_handle("RIGHT_TOEBRAKE")
  37.  
  38. -- Movement dependencies
  39. local BRAKE_COMMAND = 0
  40. local BRAKE_STATE_PARAM = 0
  41. local BRAKE_TIME_PARAM = update_time_step / 1 -- 1 reps sec.
  42.  
  43. -- Begin listening to the iCommands
  44. gear_system:listen_command(Gear)
  45. gear_system:listen_command(BrakesOn)
  46. gear_system:listen_command(BrakesOff)
  47.  
  48. -- Sets up list of command events (prior to iCommands listened)
  49. function SetCommand(command,value)
  50.     -- If the landing gear was called
  51.     if command == Gear then
  52.         if GEAR_COMMAND == 1 then
  53.             GEAR_COMMAND = 0
  54.         elseif GEAR_COMMAND == 0 then
  55.             GEAR_COMMAND = 1
  56.         end
  57.     end
  58.  
  59.     -- If the wheelbrakes are being applied
  60.     if command == BrakesOn then
  61.         BRAKE_COMMAND = 1
  62.     end
  63.  
  64.     -- If the wheelbrakes are not being applied
  65.     if command == BrakesOff then
  66.         BRAKE_COMMAND = 0
  67.     end
  68. end
  69.  
  70. -- Defines how gear animations should work
  71. function animate_gear()
  72.     -- Comfortably assuming we are off the ground...
  73.     if GEAR_WEIGHT == 0 then
  74.         -- If the gear is supposed to be up and is down
  75.         if GEAR_COMMAND == 0 and GEAR_STATE > 0 then
  76.             GEAR_STATE = GEAR_STATE - GEAR_TIME_IN
  77.         end
  78.  
  79.         -- If the gear is supposed to be down and is up
  80.         if GEAR_COMMAND == 1 and GEAR_STATE < 1 then
  81.             GEAR_STATE = GEAR_STATE + GEAR_TIME_OUT
  82.         end
  83.  
  84.         -- Limit the gear movement when fully out
  85.         if GEAR_STATE > 1 then
  86.             GEAR_STATE = 1
  87.         end
  88.  
  89.         -- Limit the gear movement when fully in
  90.         if GEAR_STATE < 0 then
  91.             GEAR_STATE = 0
  92.         end
  93.     end
  94. end
  95.  
  96. -- Defines how cockpit animations should work
  97. function animate_cockpit()
  98.     -- Comfortably assuming we are off the ground...
  99.     if GEAR_WEIGHT == 0 then
  100.         -- If the gear is supposed to be up and is down
  101.         if GEAR_COMMAND == 0 and GEAR_STATE_PARAM > 0 then
  102.             GEAR_STATE_PARAM = GEAR_STATE_PARAM - GEAR_TIME_PARAM
  103.         end
  104.  
  105.         -- If the gear is supposed to be down and is up
  106.         if GEAR_COMMAND == 1 and GEAR_STATE_PARAM < 1 then
  107.             GEAR_STATE_PARAM = GEAR_STATE_PARAM + GEAR_TIME_PARAM
  108.         end
  109.     end
  110.  
  111.     -- Limit the gear movement when fully out
  112.     if GEAR_STATE_PARAM > 1 then
  113.         GEAR_STATE_PARAM = 1
  114.     end
  115.  
  116.     -- Limit the gear movement when fully in
  117.     if GEAR_STATE_PARAM < 0 then
  118.         GEAR_STATE_PARAM = 0
  119.     end
  120.  
  121.     -- If the wheelbrakes are being applied
  122.     if BRAKE_COMMAND == 1 and BRAKE_STATE_PARAM < 1 then
  123.         BRAKE_STATE_PARAM = BRAKE_STATE_PARAM + BRAKE_TIME_PARAM
  124.     end
  125.  
  126.     -- If the wheelbrakes are not being applied
  127.     if BRAKE_COMMAND == 0 and BRAKE_STATE_PARAM > 0 then
  128.         BRAKE_STATE_PARAM = BRAKE_STATE_PARAM - BRAKE_TIME_PARAM
  129.     end
  130.  
  131.     -- Limit the wheelbrake movements when fully pushed down
  132.     if BRAKE_STATE_PARAM > 1 then
  133.         BRAKE_STATE_PARAM = 1
  134.     end
  135.  
  136.     -- Limit the wheelbrake movements when fully released
  137.     if BRAKE_STATE_PARAM < 0 then
  138.         BRAKE_STATE_PARAM = 0
  139.     end
  140. end
  141.  
  142. -- Begins a loop function
  143. update = function()
  144.     -- Runs gear animation function
  145.     animate_gear()
  146.  
  147.     -- Runs cockpit animations function
  148.     -- animate_cockpit()
  149.  
  150.     -- Animates the positions of the landing gears
  151.     set_aircraft_draw_argument_value(0, GEAR_STATE)
  152.     set_aircraft_draw_argument_value(3, GEAR_STATE)
  153.     set_aircraft_draw_argument_value(5, GEAR_STATE)
  154.  
  155.     -- Animates the positions of the landing gear lever and Wheelbrakes
  156.     --[[
  157.         GearParam:set(GEAR_STATE_PARAM)
  158.         LeftBrakeParam:set(BRAKE_STATE_PARAM)
  159.         RightBrakeParam:set(BRAKE_STATE_PARAM)
  160.     ]]--
  161. end
  162.  
  163. need_to_be_closed = false
Add Comment
Please, Sign In to add comment