kfc-200(1).nas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #### Bendix-King KFC-200 Flight Director ####
  2. #Buttons
  3. # HDG ...heading hold
  4. # FD ..... flightdirector on/off
  5. # ALT ....altitude arm
  6. # NAV ...VOR / LOC arm
  7. # BC ....LOC back course
  8. # APPR ... LOC / GS arm
  9. #### lnav ####
  10. # 0 = wingleveler
  11. # 1 = heading hold
  12. # 2 = NAV arm
  13. # 3 = NAV cap
  14. # 4 = APPR arm
  15. # 5 = APPR cap
  16. #### vnav ####
  17. # 0 = pitch hold
  18. # 1 = ALT arm
  19. # 2 = ALT cap
  20. # 3 = GS arm
  21. # 4 = GS cap
  22. var L_list=["wing-leveler","dg-heading-hold","dg-heading-hold","nav1-hold","dg-heading-hold","nav1-hold","dg-heading-hold","nav1-hold"];
  23. var V_list=["pitch-hold","pitch-hold","altitude-hold","pitch-hold","gs1-hold"];
  24. var fdprop = props.globals.getNode("/instrumentation/kfc200",1);
  25. var lnav = 0;
  26. var vnav = 0;
  27. var current_alt=0.0;
  28. var alt_select = 0.0;
  29. var DH = 0;
  30. var HASGS = "/instrumentation/nav/has-gs";
  31. var NAVLOC = "/instrumentation/nav/nav-loc";
  32. var NAVDST = "/instrumentation/nav/nav-dist";
  33. var NAVRNG = "/instrumentation/nav/in-range";
  34. var HDEFL = "/instrumentation/nav/heading-needle-deflection";
  35. var GSDEFL = "/instrumentation/nav/gs-needle-deflection-norm";
  36. var BC = "/instrumentation/nav/back-course-btn";
  37. var HDG = props.globals.getNode("/autopilot/locks/heading",1);
  38. var ALT = props.globals.getNode("/autopilot/locks/altitude",1);
  39. var SPD = props.globals.getNode("/autopilot/locks/speed",1);
  40. var SRVC = 0;
  41. setlistener("/sim/signals/fdm-initialized", func {
  42. fdprop.getNode("serviceable",1).setBoolValue(1);
  43. fdprop.getNode("armed",1).setBoolValue(0);
  44. fdprop.getNode("cpld",1).setBoolValue(0);
  45. fdprop.getNode("pitch-trim",1).setIntValue(0);
  46. fdprop.getNode("alt-trim",1).setIntValue(0);
  47. fdprop.getNode("fd-on",1).setBoolValue(0);
  48. fdprop.getNode("gs-arm",1).setBoolValue(0);
  49. fdprop.getNode("lnav",1).setValue(0);
  50. fdprop.getNode("vnav",1).setValue(0);
  51. fdprop.getNode("alt-preset",1).setDoubleValue(0.0);
  52. fdprop.getNode("alt-alert",1).setBoolValue(0);
  53. fdprop.getNode("dh-alert",1).setBoolValue(0);
  54. DH = getprop("/autopilot/route-manager/min-lock-altitude-agl-ft");
  55. alt_select = 0;
  56. ALT.setValue(V_list[vnav]);
  57. HDG.setValue(L_list[lnav]);
  58. settimer(update,5);
  59. print("KFC-200 ... Check");
  60. });
  61. setlistener("/instrumentation/kfc200/fd-on", func(fd){
  62. var fdON = fd.getBoolValue();
  63. clear_ap();
  64. },0,0);
  65. setlistener("/autopilot/locks/passive-mode", func(ap){
  66. if(!ap.getBoolValue()){
  67. setprop("autopilot/settings/target-pitch-deg",getprop("/orientation/pitch-deg"));
  68. }
  69. },0,0);
  70. setlistener("/instrumentation/kfc200/serviceable", func(srv){
  71. if(srv.getBoolValue()){SRVC=1;
  72. }else{
  73. SRVC=0;
  74. }
  75. },0,0);
  76. setlistener("/autopilot/settings/target-altitude-ft",func(at){
  77. alt_select = at.getValue();
  78. },0,0);
  79. setlistener("/autopilot/route-manager/min-lock-altitude-agl-ft",func(dh){
  80. DH = dh.getValue();
  81. },0,0);
  82. setlistener("/instrumentation/kfc200/lnav",func(ln){
  83. if(SRVC == 0)return;
  84. lnav = ln.getValue();
  85. if(lnav == 4){
  86. if(!getprop(NAVLOC)){
  87. lnav=2;
  88. setprop("/instrumentation/kfc200/lnav",lnav);
  89. }else{
  90. if(getprop(HASGS)){
  91. if(!getprop(BC)){
  92. setprop("/instrumentation/kfc200/gs-arm",1);
  93. }
  94. }
  95. }
  96. }
  97. HDG.setValue(L_list[lnav]);
  98. },0,0);
  99. setlistener("/instrumentation/kfc200/vnav", func(vn){
  100. if(SRVC == 0)return;
  101. vnav = vn.getValue();
  102. ALT.setValue(V_list[vnav]);
  103. },0,0);
  104. var clear_ap = func {
  105. setprop("/autopilot/settings/target-pitch-deg",getprop("/orientation/pitch-deg"));
  106. vnav = 0;
  107. lnav=0;
  108. setprop("/instrumentation/kfc200/lnav",lnav);
  109. setprop("/instrumentation/kfc200/vnav",vnav);
  110. HDG.setValue(L_list[lnav]);
  111. ALT.setValue(V_list[vnav]);
  112. }
  113. #### PITCH TRIM = 1 degree per second ####
  114. var pitch_trim = func {
  115. var temp_pitch = getprop("autopilot/settings/target-pitch-deg");
  116. var FR =getprop("sim/frame-rate");
  117. if(FR > 0){
  118. var trim = (1/FR) * arg[0];
  119. setprop("autopilot/settings/target-pitch-deg",temp_pitch + trim);
  120. }
  121. }
  122. #### ALTITUDE TRIM = 600 fpm ####
  123. var alt_trim = func {
  124. var temp_alt = getprop("autopilot/settings/target-altitude-ft");
  125. var FR =getprop("sim/frame-rate");
  126. if(FR > 0){
  127. var trim = (10/FR) * arg[0];
  128. setprop("autopilot/settings/target-altitude-ft",temp_alt + trim);
  129. }
  130. }
  131. var update_nav = func {
  132. if(SRVC == 1){
  133. var inrange= getprop(NAVRNG);
  134. if(inrange){
  135. if(lnav == 2 or lnav == 4){
  136. setprop("instrumentation/kfc200/armed",1);
  137. setprop("instrumentation/kfc200/cpld",0);
  138. var DF = getprop(HDEFL);
  139. if(DF > -9 and DF < 9){
  140. setprop("/instrumentation/kfc200/lnav",lnav + 1);
  141. setprop("instrumentation/kfc200/armed",0);
  142. setprop("instrumentation/kfc200/cpld",1);
  143. }
  144. }
  145. if(lnav ==5){
  146. if(getprop("instrumentation/kfc200/gs-arm")){
  147. if(getprop("instrumentation/nav/gs-distance") < 25000){
  148. var GS1 = getprop(GSDEFL);
  149. if( GS1< 0.5 and GS1 > -0.5){vnav = 4;
  150. setprop("/instrumentation/kfc200/vnav",vnav);
  151. }
  152. }
  153. }
  154. }
  155. }
  156. if(vnav == 1){
  157. var offset = get_altoffset();
  158. if(offset > -990 and offset < 990){
  159. setprop("/instrumentation/kfc200/vnav",vnav + 1);
  160. }
  161. }
  162. }
  163. }
  164. var get_altoffset = func(){
  165. current_alt = getprop("/instrumentation/altimeter/pressure-alt-ft");
  166. var offset = (current_alt - alt_select);
  167. var alert =0;
  168. if(offset > -1000 and offset < -1000){
  169. if(offset < -300 and offset > 300)alert = 1;
  170. }
  171. fdprop.getNode("alt-alert").setBoolValue(alert);
  172. return(offset);
  173. }
  174. var update = func {
  175. var PT = getprop("instrumentation/kfc200/pitch-trim");
  176. var AT = getprop("instrumentation/kfc200/alt-trim");
  177. if(PT !=0)pitch_trim(PT);
  178. if(AT!=0)alt_trim(AT);
  179. if(getprop("/position/altitude-agl-ft") < DH){
  180. props.globals.getNode("/autopilot/locks/passive-mode").setBoolValue(1);
  181. setprop("instrumentation/kfc200/dh-alert",1);
  182. }else{
  183. setprop("instrumentation/kfc200/dh-alert",0);
  184. }
  185. update_nav();
  186. settimer(update, 0);
  187. }