enginecontrol-h145.nas 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #
  2. # Engine Control Panel Switches code:
  3. # by litzi
  4. #
  5. # called from ec145-main-panel.xml model file
  6. var engswitch = {
  7. swpos: [0, 0],
  8. startdelay: [0.1, 0.1],
  9. init: func {
  10. me.get(0);
  11. me.get(1);
  12. },
  13. vent: func(eng) {
  14. curr = me.get(eng);
  15. if (curr == 0 ) {
  16. # ventilate engine for 20s
  17. setprop("/controls/switches/ecp/vent["~eng~"]",1);
  18. setprop("controls/engines/engine["~eng~"]/starter", 1);
  19. interpolate("controls/engines/engine["~eng~"]/starter", 0, 20);
  20. }
  21. },
  22. up: func(eng) {
  23. #i.e. a left mouse button press
  24. curr = me.get(eng);
  25. if (curr == 0 or curr == 2) {
  26. var delay=0.1;
  27. # if other engine is starting delay all steps by 11 sec
  28. if (curr==0 and getprop("controls/engines/engine["~!eng~"]/starter")>0)
  29. me.startdelay[eng] = 11;
  30. me.set(eng, 1.0);
  31. if (curr==0) {
  32. settimer(func {
  33. # from off to idle: init startup sequence
  34. setprop("controls/engines/engine["~eng~"]/starter", 1);
  35. #reset starter-signal to 0 after 10 sec
  36. interpolate("controls/engines/engine["~eng~"]/starter", 0, 10);
  37. setprop("controls/engines/engine["~eng~"]/ignition", 1);
  38. #reset ignition signal to 0 after 10 sec
  39. interpolate("controls/engines/engine["~eng~"]/ignition", 0, 12);
  40. setprop("controls/engines/engine["~eng~"]/flight", 0);
  41. setprop("controls/engines/engine["~eng~"]/cutoff", 0);
  42. }, me.startdelay[eng] );
  43. } else {
  44. #from flight to idle
  45. setprop("controls/engines/engine["~eng~"]/flight", 0);
  46. }
  47. } else {
  48. me.set(eng,2.0);
  49. setprop("controls/engines/engine["~eng~"]/flight", 1);
  50. }
  51. },
  52. down: func(eng) {
  53. #i.e. mid mouse button press
  54. curr = me.get(eng);
  55. if (curr == 2) {
  56. me.set(eng,1.0);
  57. #from flight to idle
  58. setprop("controls/engines/engine["~eng~"]/flight", 0);
  59. } elsif (curr == 1) {
  60. me.set(eng,0.0);
  61. #from idle to off
  62. setprop("controls/engines/engine["~eng~"]/ignition", 0);
  63. setprop("controls/engines/engine["~eng~"]/flight", 0);
  64. setprop("controls/engines/engine["~eng~"]/cutoff", 1);
  65. }
  66. },
  67. train: func () {
  68. pos = getprop("/controls/switches/ecp/trainswitch") or 0;
  69. if (pos == 0) {
  70. if (me.swpos[0]==2 and me.swpos[1]==2) {
  71. setprop("controls/engines/engine[0]/training", 1);
  72. setprop("/controls/switches/ecp/trainswitch",1);
  73. settimer( func { me.testtrain(); } ,1 );
  74. }
  75. } else {
  76. me.aborttrain(0);
  77. }
  78. },
  79. train2idle: func () {
  80. # both engines main switches idle
  81. if (engswitch.get(0) == 2) engswitch.down(0);
  82. if (engswitch.get(1) == 2) engswitch.down(1);
  83. },
  84. get: func(eng) {
  85. me.swpos[eng]=getprop("controls/switches/ecp/pos["~eng~"]") or 0;
  86. return me.swpos[eng];
  87. },
  88. set: func(eng, p) {
  89. interpolate("controls/switches/ecp/pos["~eng~"]", p, 0.2);
  90. me.swpos[eng] = p;
  91. },
  92. aborttrain: func(m) {
  93. #setprop("controls/engines/engine[0]/flight", 1);
  94. setprop("controls/engines/engine[0]/training", 0);
  95. setprop("/controls/switches/ecp/trainswitch", 0);
  96. setprop("/instrumentation/efis/vmd/training-aborted", m);
  97. if (m) {
  98. settimer(func {setprop("/instrumentation/efis/vmd/training-aborted", 0);} ,10 );
  99. }
  100. },
  101. testtrain: func() {
  102. #if rotor rpm drops below 92% abort training mode automatically
  103. if ( getprop("/rotors/main/rpm") < 383*0.92 ) {
  104. me.aborttrain(1);
  105. } else {
  106. settimer( func { me.testtrain(); } ,1 );
  107. }
  108. }
  109. };
  110. engswitch.init();
  111. # This is the model-specifc part of the auto-startup procedure object defined in bk117.nas
  112. procedure["process"] = func(id) {
  113. id == me.loopid or return;
  114. # startup
  115. if (me.stage == 1) {
  116. print("", "1: rotor break .. release, fuel prime pumps .. both on, batt mstr .. on --> wait 10 sec for fuel pressure");
  117. interpolate("/controls/rotor/brake", 0, 1);
  118. # power on
  119. setprop("/controls/electric/battery-switch", 1);
  120. setprop("/controls/electric/stbyhor-switch", 1);
  121. fuel_pump_xfer.off(0);
  122. fuel_pump_xfer.off(1);
  123. fuel_pump_prime.on(0);
  124. fuel_pump_prime.on(1);
  125. setprop("engines/startup_proc", 1);
  126. me.next(2);
  127. } elsif (me.stage == 2) {
  128. print("", "2: avio 1,2 switch .. on");
  129. setprop("controls/electric/avionics-switch1", 1);
  130. setprop("controls/electric/avionics-switch2", 1);
  131. me.next(5);
  132. } elsif (me.stage == 3) {
  133. print("", "3: engine #1 main sw .. idle");
  134. if (engswitch.get(0) == 0) engswitch.up(0);
  135. me.next(25);
  136. } elsif (me.stage == 4) {
  137. print("", "4: engine #2 main sw .. idle --> wait for N2~70%");
  138. if (engswitch.get(1) == 0) engswitch.up(1);
  139. me.next(25);
  140. } elsif (me.stage == 5) {
  141. print("", "5: engine #1 main sw .. flight");
  142. if (engswitch.get(0) == 1) engswitch.up(0);
  143. me.next(2);
  144. } elsif (me.stage == 6) {
  145. print("", "6: engine #2 main sw .. flight --> wait for NRO 100%");
  146. if (engswitch.get(1) == 1) engswitch.up(1);
  147. me.next(5);
  148. } elsif (me.stage == 7) {
  149. print("", "7: fuel prime pumps .. both off, fuel xfer pumps .. both on");
  150. fuel_pump_prime.off(0);
  151. fuel_pump_prime.off(1);
  152. fuel_pump_xfer.on(0);
  153. fuel_pump_xfer.on(1);
  154. ### added by StuartC ###
  155. setprop("/controls/electric/engine/generator", 1);
  156. setprop("/controls/electric/engine[1]/generator", 1);
  157. # shutdown
  158. } elsif (me.stage == -1) {
  159. print("", "-1: engines main sw .. both idle --> cool engines");
  160. setprop("engines/shutdown_proc", 1);
  161. if (engswitch.get(0) == 2) engswitch.down(0);
  162. if (engswitch.get(1) == 2) engswitch.down(1);
  163. me.next(20);
  164. } elsif (me.stage == -2) {
  165. print("", "-2: engines main sw .. both off --> wait for NRO decay");
  166. if (engswitch.get(0) == 1) engswitch.down(0);
  167. if (engswitch.get(1) == 1) engswitch.down(1);
  168. me.next(2);
  169. } elsif (me.stage == -3) {
  170. print("", "-3: fuel xfer pumps .. both off");
  171. fuel_pump_xfer.off(0);
  172. fuel_pump_xfer.off(1);
  173. me.next(30);
  174. } elsif (me.stage == -4) {
  175. print("", "-4: rotor brake .. apply");
  176. setprop("engines/shutdown_proc",0);
  177. interpolate("/controls/rotor/brake", 1, 2);
  178. me.next(20);
  179. } elsif (me.stage == -5) {
  180. print("", "-5: batt mstr.. off");
  181. setprop("controls/electric/avionics-switch1", 0);
  182. setprop("controls/electric/avionics-switch2", 0);
  183. setprop("/controls/electric/battery-switch", 0);
  184. }
  185. };