limits.nas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #
  2. # Nasal script to print errors to the screen when aircraft exceed design limits:
  3. # - exceeding MTOW
  4. # - exceeding VNE
  5. # - exceeding RPM rotor limits
  6. # - exceeding TRQ limits
  7. # - exceeding structural G limits
  8. # - exceeding temperature limits
  9. # ...
  10. #
  11. # To use, define one or more of
  12. # limits/vne
  13. # limits/vne-floats
  14. # limits/vne-door-open
  15. # limits/MTOW
  16. # limits/rpm-min
  17. # limits/rpm-max
  18. # limits/trq-max
  19. # limits/tot-max
  20. # limits/ng-max
  21. # limits/max-positive-g
  22. # limits/max-negative-g
  23. # limits/min-temp-degc
  24. # limits/max-temp-degc
  25. #
  26. # LIMIT caution on CWS:
  27. # Not all detected warning situations will light up the LIMIT caution on CWS.
  28. # The LIMIT caution only lights up for the cases described in POH.
  29. # For other checks implemented here, only a message is written to the screen.
  30. # =============================== Pilot G stuff (taken from hurricane.nas) =================================
  31. # fix mhab: this is yasim here !!
  32. #var pilot_g = props.globals.getNode("/fdm/jsbsim/accelerations/a-pilot-z-ft_sec2", 1);
  33. #pilot_g.setDoubleValue(0);
  34. setprop("/accelerations/max-pilot-g",0.999);
  35. setprop("/accelerations/min-pilot-g",0.999);
  36. var updatePilotG = func {
  37. # fix mhab
  38. var g = getprop("/accelerations/pilot-g");
  39. if (g == nil) { g = 0; }
  40. #var g_damp = getprop("/accelerations/pilot-gdamped");
  41. #if (g_damp == nil) { g_damp = 0; }
  42. if ( g > getprop("/accelerations/max-pilot-g") ) { setprop("/accelerations/max-pilot-g",g); }
  43. if ( g < getprop("/accelerations/min-pilot-g") ) { setprop("/accelerations/min-pilot-g",g); }
  44. settimer(updatePilotG, 0.2);
  45. }
  46. var check_G_VNE_MTOW_RPM_TEMP = func {
  47. if (getprop("/sim/freeze/replay-state"))
  48. return;
  49. var limit = 0;
  50. var msg = "";
  51. var msg1 = "";
  52. var msg2 = "";
  53. var max_positive = getprop("/limits/max-positive-g");
  54. var max_negative = getprop("/limits/max-negative-g");
  55. var gmax = getprop("/accelerations/max-pilot-g");
  56. var gmin = getprop("/accelerations/min-pilot-g");
  57. # if ( max_positive != nil and gmax > max_positive ) {
  58. msg = sprintf("Airframe structural positive-g load limit (%2.1f) exceeded (%2.1f)!",max_positive,gmax);
  59. #}
  60. # fill message stack
  61. if ( msg1 == "" ) { msg1 = msg;
  62. } else { msg2 = msg; }
  63. # if ( max_negative != nil and gmin < max_negative ) {
  64. msg = sprintf("Airframe structural negative-g load limit (%2.1f) exceeded (%2.1f)!",max_negative,gmin);
  65. #}
  66. # fill message stack
  67. # if ( msg1 == "" ) { msg1 = msg;
  68. #} else { msg2 = msg; }
  69. # Now check VNE
  70. var airspeed = getprop("/velocities/airspeed-kt");
  71. var vne = getprop("/limits/vne");
  72. if ( vne == nil ) { vne = 155; }
  73. var flt = getprop("/controls/gear/floats-inflat");
  74. var vne_flt = getprop("/limits/vne-floats");
  75. var alt = getprop("/position/altitude-ft");
  76. var pwr = getprop("/controls/engines/engine/power");
  77. var door_open = 0;
  78. var insert = "";
  79. var insert2 = "";
  80. # 1) vne reduction for altitude is 3kts for 1000ft
  81. vne_red_alt = 3.0*alt/1000.0;
  82. vne_corr = vne - vne_red_alt;
  83. # if ( flt and vne_flt != nil ) {
  84. # vne_corr = vne_flt - vne_red_alt;
  85. #}
  86. # 2) vne reduction if doors are open
  87. #
  88. # from pilot handbook:
  89. # LH sliding door manoevering: 70kts (ignored here)
  90. # LH sliding door open+locked: 80kts
  91. # LH sliding door removed: 110kts (ignored here)
  92. # LH sliding door open+locked/removed + RH door removed: 90kts (ignored here)
  93. # LH sliding door open+locked/removed + all right d. removed: 90kts (ignored here)
  94. # LH sliding door open+locked/removed + front doors removed: 90kts (ignored here)
  95. #
  96. # Rem.: configurations with removed doors are ignored for now
  97. if ( getprop("/sim/model/ec130/doors/frontl/position-norm")
  98. or getprop("/sim/model/ec130/doors/frontr/position-norm")
  99. or getprop("/sim/model/ec130/doors/passengerl/position-norm")
  100. or getprop("/sim/model/ec130/doors/passengerr/position-norm") ) {
  101. door_open = 1;
  102. vne_door = getprop("/limits/vne-door-open");
  103. if ( vne_door != nil ) {
  104. vne_corr = vne_door - vne_red_alt;
  105. }
  106. }
  107. # 3) in power off state vne limit is reduced by 30kts
  108. vne_red_pwr = 0;
  109. if ( !pwr ) {
  110. vne_red_pwr = 30;
  111. insert2=" PWR is OFF !"
  112. }
  113. vne_corr = vne_corr - vne_red_pwr;
  114. if ( airspeed != nil and vne != nil and airspeed > vne_corr ) {
  115. if ( flt ) {
  116. insert = "with floats inflated";
  117. setprop("/sim/sound/gong", 1);
  118. }
  119. if ( door_open ) {
  120. insert = "with doors open";
  121. setprop("/sim/sound/gong", 1);
  122. }
  123. msg = sprintf("Airspeed (%3.0f) exceeds VNE %s (%3.0f)! %s",airspeed,insert,vne_corr,insert2);
  124. # if (airspeed > (vne_corr+20)) {
  125. # msg = "EXTREME OVERSPEED !!!";
  126. setprop("/sim/sound/warn2600",1);
  127. } else {
  128. setprop("/sim/sound/warn2600",0);
  129. }
  130. if (airspeed > (vne_corr+45)) {
  131. # cutoff engine
  132. setprop("/controls/engines/engine/cutoffguard",0);
  133. setprop("/controls/engines/engine/cutoff",1);
  134. setprop("/controls/engines/engine/cutoff-norm",1);
  135. setprop("/controls/rotor/brake",1);
  136. # crash after 30 seconds
  137. settimer(func {setprop("/sim/crashed",1);}, 30);
  138. }
  139. } else {
  140. setprop("/sim/sound/warn2600",0);
  141. }
  142. # fill message stack
  143. if ( msg1 == "" ) { msg1 = msg;
  144. } else { msg2 = msg; }
  145. #Now Check MTOW
  146. var TOW =getprop("/yasim/gross-weight-lbs");
  147. var MTOW = getprop("/limits/mass-and-balance/maximum-takeoff-mass-lbs");
  148. if ( MTOW == nil ) { MTOW = 5350; }
  149. if (TOW > MTOW) {
  150. msg = sprintf("Gross weight (%4.0f lbs) exceeds MTOW of %4.0f lbs!",TOW,MTOW);
  151. }
  152. # fill message stack
  153. if ( msg1 == "" ) { msg1 = msg;
  154. } else { msg2 = msg; }
  155. #Check Rotor rpm - warning sounds activated when Button "Horn" on SCU is engaged
  156. Cont310 = props.globals.getNode("/sim/sound/Cont310", 1);
  157. Int310 = props.globals.getNode("/sim/sound/Intermittent310", 1);
  158. var min_rpm = getprop("/limits/rpm-min");
  159. var max_rpm = getprop("/limits/rpm-max");
  160. var rpm = getprop("/rotors/main/rpm");
  161. if ( rpm == nil ) { rpm = 0; }
  162. var horn = getprop("/systems/electrical/outputs/horn");
  163. if ( horn == nil ) { horn = 0; }
  164. if ( max_rpm != nil and rpm > max_rpm and horn > 24 ) {
  165. # msg = sprintf("Rotor rpm (%3.0f) exceeds max of %3.0f!",rpm,max_rpm);
  166. Int310.setValue(1);
  167. limit = 1;
  168. }else{
  169. Int310.setValue(0);
  170. }
  171. if ( min_rpm != nil and rpm < min_rpm and horn > 24 ) {
  172. # msg = sprintf("Rotor rpm (%3.0f) less than %3.0f!",rpm,min_rpm);
  173. Cont310.setValue(1);
  174. limit = 1;
  175. }else{
  176. Cont310.setValue(0);
  177. }
  178. # fill message stack
  179. if ( msg1 == "" ) { msg1 = msg;
  180. } else { msg2 = msg; }
  181. #Check take-off limits
  182. var trq =getprop("/sim/model/ec130/torque-pct");
  183. var tot =getprop("/engines/engine/tot-degc");
  184. var ng =getprop("/engines/engine/n1-pct");
  185. var max_trq = getprop("/limits/trq-max");
  186. var max_tot = getprop("/limits/tot-max");
  187. var max_ng = getprop("/limits/ng-max");
  188. if ( max_trq != nil and trq > max_trq and horn > 24) {
  189. # msg = sprintf("Engine Torque (%3.0f%%) exceeds max of %3.0f%%!",trq,max_trq);
  190. setprop("/sim/sound/Cont285",1);
  191. limit = 1;
  192. }elsif ( max_tot != nil and tot > max_tot and horn > 24 ) {
  193. # msg = sprintf("Engine T4 (%3.0f) exceeds %3.0f deg!",tot,max_tot);
  194. setprop("/sim/sound/Cont285",1);
  195. limit = 1;
  196. }elsif ( max_ng != nil and ng > max_ng and horn > 24 ) {
  197. # msg = sprintf("Engine NG (%5.1f) exceeds %5.1f%%!",ng,max_ng);
  198. setprop("/sim/sound/Cont285",1);
  199. limit = 1;
  200. }else{
  201. setprop("/sim/sound/Cont285",0);
  202. }
  203. # fill message stack
  204. if ( msg1 == "" ) { msg1 = msg;
  205. } else { msg2 = msg; }
  206. #Check temperature limits
  207. var temp = getprop("/environment/temperature-degc");
  208. var temp_min = getprop("/limits/min-temp-degc");
  209. var temp_max = getprop("/limits/max-temp-degc");
  210. if ( (temp_min != nil and temp < temp_min) or (temp_max != nil and temp > temp_max) ) {
  211. # msg = sprintf("Operation Temperature Limit (%3.0f/%3.0f) exceeded (%3.0f°C) !",temp_min,temp_max,temp);
  212. }
  213. # fill message stack
  214. if ( msg1 == "" ) { msg1 = msg;
  215. } else { msg2 = msg; }
  216. if (msg1 != "") {
  217. # If we have a message on stack, display stack, but don't bother checking for
  218. # any other errors for 5 seconds. Otherwise we're likely to get
  219. # repeated messages.
  220. screen.log.write(msg1);
  221. if (msg2 != "") {
  222. screen.log.write(msg2);
  223. }
  224. # mhab light up LIMIT warning on panel
  225. if ( limit ) { setprop("/instrumentation/annunciators/warning/limit",1); }
  226. settimer(check_G_VNE_MTOW_RPM_TEMP, 5);
  227. } else {
  228. # mhab switch off LIMIT warning on panel
  229. setprop("/instrumentation/annunciators/warning/limit",0);
  230. settimer(check_G_VNE_MTOW_RPM_TEMP, 1);
  231. }
  232. }
  233. setlistener("/sim/signals/fdm-initialized", func {
  234. settimer(func {
  235. check_G_VNE_MTOW_RPM_TEMP();
  236. updatePilotG();
  237. }, 1);
  238. });