Advertisement
kerbo_

Archean simple plane

Sep 18th, 2024 (edited)
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. ; this was converted to code from nodes so is a bit of a mess
  2.  
  3. const $mynumber1 = 0.200000
  4.  
  5. var $_plane_counter1 = 0
  6. var $dash = screen("dash1", 0)
  7. var $battCharge = 0
  8. var $stabRoll = 0.0
  9. var $stabPitch = 0.0
  10.  
  11. function @pid1($_setpoint:number, $_processvalue:number, $_kp:number, $_ki:number, $_kd:number, $_integral:number, $_prev_error:number) : number
  12. var $_error = $_setpoint - $_processvalue
  13. var $_dt = delta_time
  14. var $_derivative = ($_error - $_prev_error) / $_dt
  15. $_integral += $_error * $_dt
  16. $_prev_error = $_error
  17. return $_kp * $_error + $_ki * $_integral + $_kd * $_derivative
  18.  
  19. init
  20. $dash.blank()
  21.  
  22. update
  23. var $_input_number_9_1 = input_number(9, 1) ; Back/Fwd
  24.  
  25. var $_input_number_9_5 = input_number(9, 5) ; Roll
  26. output_number(2, 0, ($_input_number_9_5 * 0.75))
  27. output_number(1, 1, ($_input_number_9_5 * -0.75))
  28. var $_input_number_9_2 = input_number(9, 2) ; Left/Right
  29. ; moved to stab
  30. var $_input_number_9_8 = input_number(9, 8) ; Aux 1
  31. output_number(7, 3, $_input_number_9_8)
  32.  
  33. ;var $wheelie = input_number(9,9)
  34. ;output_number(7, 0, $wheelie)
  35.  
  36. var $tilt = input_number("tilt_roll", 0)
  37. var $pitch = input_number("tilt_pitch", 0)
  38. var $speed = input_number("speed", 0)
  39. var $altitude_abs = input_number("altitude", 0)
  40. var $altitude = input_number("altitude", 1)
  41.  
  42. var $stabsw = input_number("dash1", 2)
  43. if $stabsw == 1
  44. $stabRoll = $tilt * -2
  45. output_number(6, 0, -($stabRoll))
  46. output_number(11, 0, $stabRoll)
  47. else
  48. output_number(6, 0, (-($_input_number_9_2 * 0.75)))
  49. output_number(11, 0, ($_input_number_9_2 * 0.75))
  50.  
  51. var $pitchsw = input_number("dash1", 1)
  52. if $pitchsw == 1
  53. $stabPitch = @pid1(0.12, $pitch, 0.3,0.2,0.1,0,0)
  54. output_number(3, 0, $stabPitch)
  55. else
  56. output_number(3, 0, ($_input_number_9_1 * -0.75))
  57.  
  58. var $_input_number_9_3 = input_number(9, 3) ; Down/Up
  59. var $_input_number_9_17 = input_number(9, 17) ; Aux 0
  60. $_plane_counter1 += $_input_number_9_3
  61. if $_plane_counter1 < 0
  62. $_plane_counter1 = 0
  63. if $_plane_counter1 > 100
  64. $_plane_counter1 = 100
  65. if $_input_number_9_17
  66. $_plane_counter1 = 0
  67. output_number(8, 0, ($_plane_counter1 / 100))
  68. output_number(8, 1, $mynumber1)
  69.  
  70. ; dashboard
  71. $battCharge = input_number("battery1", 2)*100
  72. $dash.blank()
  73. $dash.text_size(0.7)
  74. $dash.write(2, 2, green, text(" Battery: {0}%", $battCharge))
  75. $dash.write(2, 12, green, text(" Throttle: {0}", $_plane_counter1))
  76. $dash.write(2, 22, green, text(" Speed: {0}", $speed))
  77. $dash.write(2, 32, green, text("Radar Alt: {0}", $altitude))
  78. $dash.write(2, 42, green, text(" Altitude: {0}k", $altitude_abs/1000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement