Gnat_afcs.nas 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # ========================================================================================
  2. # Slimmed down AFCS System for the Gnat_T1 by Warty, 2023
  3. # ========================================================================================
  4. var afcs_loop = func {
  5. var altRate = getprop("/velocities/vertical-speed-fps");
  6. var currentFlightMode = getprop("/afcs/flight-mode");
  7. var currentAGL = getprop("/position/altitude-agl-ft");
  8. var currentIAS = getprop("/velocities/airspeed-kt");
  9. # Put the gear and flaps up once take off is established
  10. if(currentFlightMode == 'Take off' and currentAGL>=50 and altRate >= 10){
  11. setprop("/controls/gear/gear-down", 0);
  12. if(currentAGL >= 200 and currentIAS >= 120){
  13. setprop("/afcs/flight-mode", '-----');
  14. setprop("/controls/flight/flaps", 0.0 );
  15. setprop("/autopilot/locks/speed", "speed-with-throttle" );
  16. setprop("/autopilot/settings/target-speed-kt", 200);
  17. s#etprop("/autopilot/locks/altitude", "altitude-hold" );
  18. #setprop("/autopilot/settings/target-altitude-ft", 500 + getprop("/position/altitude-ft"));
  19. #setprop("/autopilot/locks/heading", "dg-heading-hold" );
  20. #setprop("/autopilot/settings/heading-bug-deg", getprop("/orientation/heading-magnetic-deg"));
  21. }
  22. }
  23. # Adjust flap dependent on airspeed for landing
  24. if(currentFlightMode == 'Landing' and 200 >= currentIAS ){
  25. setprop("/controls/flight/flaps", 1.00 - (currentIAS - 150)*0.01 );
  26. if(150 >= currentIAS ){
  27. setprop("/controls/flight/flaps", 1.00 ) ;
  28. }
  29. }
  30. # Cut power and AutoPilot once landing is established
  31. if(currentFlightMode == 'Landing' and 25 >= currentAGL){
  32. setprop("/autopilot/settings/target-speed-kt", 0);
  33. setprop("/autopilot/locks/altitude", "");
  34. setprop("/autopilot/locks/heading", "");
  35. setprop("/autopilot/locks/speed", "");
  36. setprop("/controls/engines/engine/throttle", 0.0);
  37. setprop("/controls/gear/brake-parking", 1);
  38. setprop("/sim/current-view/field-of-view", 90.0); # was probably on zoom for landing
  39. setprop("/controls/flight/speedbrake", 0); # just in case (should not operate
  40. # on the ground because the gear doors are the air brakeso n a Gnat)
  41. if( 10 >= currentIAS){
  42. setprop("/afcs/flight-mode", "Taxi");
  43. setprop("/controls/engines/engine[0]/throttle", 0.10);;
  44. setprop("/controls/gear/brake-parking", 0);
  45. }
  46. }
  47. setprop("/afcs/counter", getprop("/afcs/counter")+1); # testing only
  48. var forDebug = getprop("/afcs/counter") ;
  49. ##### Blinkers should maybe be in the HUD Nasal as it is where they are used ??
  50. setprop("/afcs/Blink2HzCount", getprop("/afcs/Blink2HzCount")+1);
  51. if(getprop("/afcs/Blink2HzCount") == 5){
  52. setprop("/afcs/Blink2HzCount", 0);
  53. if(getprop("/afcs/Blinker2Hz") == 0){setprop("/afcs/Blinker2Hz", 1.0);}
  54. else {setprop("/afcs/Blinker2Hz", 0.0);}
  55. }
  56. setprop("/afcs/Blink5HzCount", getprop("/afcs/Blink5HzCount")+1);
  57. if(getprop("/afcs/Blink5HzCount") == 2){
  58. setprop("/afcs/Blink5HzCount", 0);
  59. if(getprop("/afcs/Blinker5Hz") == 0){setprop("/afcs/Blinker5Hz", 1.0);}
  60. else {setprop("/afcs/Blinker5Hz", 0.0);}
  61. }
  62. settimer(afcs_loop, 0.05);
  63. }
  64. setlistener("/sim/signals/fdm-initialized", func { # ====================== initialization
  65. ##################setprop("ai/models/aircraft[0]/position/altitude-ft", -200); #targetMarker
  66. #setprop("/sim/keytest", "WartAFCS"); # testing only
  67. setprop("/afcs/counter", 0);
  68. setprop("/afcs/targetYawRate", 0);
  69. setprop("/afcs/yaw", 0);
  70. setprop("/afcs/hasGear", 1);
  71. setprop("/afcs/screenXPhysical", 4.63); # PFD-Screen position
  72. setprop("/afcs/flight-mode", '-----');
  73. setprop("/afcs/Blink2HzCount", 0); setprop("/afcs/Blinker2Hz", 0);
  74. setprop("/afcs/Blink5HzCount", 0); setprop("/afcs/Blinker5Hz", 0);
  75. setprop("/surface-positions/elevator-pos-norm", 0);
  76. setprop("/canopy/position-norm", 0);
  77. # force radar debug-mode on (forced radar calculations even if
  78. # no radar instrument and AI aircraft are out of range
  79. setprop("/instrumentation/radar/debug-mode", 1);
  80. engines.engine1.autostart();
  81. afcs_loop();
  82. })