r44.nas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. ############################################################
  2. ## Adapted from R22.nas for R44 by Clement DE L'HAMAIDE ##
  3. ## Date : 05/05/2011 ##
  4. ############################################################
  5. var RPM_arm=props.globals.getNode("/instrumentation/alerts/rpm",1);
  6. var last_time = 0;
  7. var start_timer=0;
  8. var GPS = 0.002222; ### avg cruise = 8 gph
  9. var Fuel_Density=6.0;
  10. var Fuel1_Level= props.globals.getNode("/consumables/fuel/tank/level-gal_us",1);
  11. var Fuel1_LBS= props.globals.getNode("/consumables/fuel/tank/level-lbs",1);
  12. var Fuel2_Level= props.globals.getNode("/consumables/fuel/tank[1]/level-gal_us",1);
  13. var Fuel2_LBS= props.globals.getNode("/consumables/fuel/tank[1]/level-lbs",1);
  14. var TotalFuelG=props.globals.getNode("/consumables/fuel/total-fuel-gals",1);
  15. var TotalFuelP=props.globals.getNode("/consumables/fuel/total-fuel-lbs",1);
  16. var NoFuel=props.globals.getNode("/engines/engine/out-of-fuel",1);
  17. var firstTime = 1;
  18. var FHmeter = aircraft.timer.new("/instrumentation/clock/flight-meter-sec", 10);
  19. FHmeter.stop();
  20. setlistener("/sim/signals/fdm-initialized", func {
  21. Fuel_Density=props.globals.getNode("/consumables/fuel/tank/density-ppg").getValue();
  22. setprop("/instrumentation/clock/flight-meter-hour",0);
  23. RPM_arm.setBoolValue(0);
  24. print("Systems ... Check");
  25. settimer(update_systems,2);
  26. splash_vec_loop();
  27. setprop("sim/model/sound/volume", 0.5);
  28. setprop("/instrumentation/doors/Rcrew/position-norm",1);
  29. setprop("controls/engines/engine[0]/mixture",0);
  30. # COMM1 (according to its documentation)
  31. aircraft.data.add(
  32. "instrumentation/comm[0]/power-btn",
  33. "instrumentation/comm[0]/volume",
  34. "instrumentation/comm[0]/frequencies/selected-mhz",
  35. "instrumentation/comm[0]/frequencies/standby-mhz",
  36. "instrumentation/comm[0]/frequencies/dial-khz",
  37. "instrumentation/comm[0]/frequencies/dial-mhz",
  38. "instrumentation/comm[0]/test-btn",
  39. "instrumentation/nav[0]/audio-btn",
  40. "instrumentation/nav[0]/power-btn",
  41. "instrumentation/nav[0]/volume",
  42. "instrumentation/nav[0]/frequencies/selected-mhz",
  43. "instrumentation/nav[0]/frequencies/standby-mhz",
  44. "instrumentation/nav[0]/frequencies/dial-khz",
  45. "instrumentation/nav[0]/frequencies/dial-mhz",
  46. "instrumentation/nav[0]/radials/selected-deg",
  47. );
  48. setprop("/r44/engines/engine[0]/mp-pressure",1);
  49. setprop("/sim/model/r44/gps-visible",1);
  50. setprop("sim/model/r44/tv",0);
  51. setprop("/sim/model/r44/cluthLight",0);
  52. # mhab merged from woolthread.nas
  53. # Simple vibrating yawstring
  54. var yawstring = func {
  55. var airspeed = getprop("/velocities/airspeed-kt");
  56. # mhab fix
  57. if ( airspeed == nil ) airspeed=0;
  58. var rpm = getprop("/rotors/main/rpm");
  59. var severity = 0;
  60. if ( (airspeed < 137) and (rpm >170)) {
  61. severity = ( math.sin (math.pi*airspeed/137) * (rand()*12) ) ;
  62. }
  63. var position = getprop("/orientation/side-slip-deg") + severity ;
  64. setprop("/instrumentation/yawstring",position);
  65. settimer(yawstring,0);
  66. }
  67. # Start the yawstring ASAP
  68. yawstring();
  69. });
  70. setlistener("/sim/signals/reinit", func {
  71. RPM_arm.setBoolValue(0);
  72. setprop("/controls/engines/engine/throttle",1);
  73. });
  74. setlistener("/controls/lighting/instruments-norm", func {
  75. var light = getprop("/controls/lighting/instruments-norm");
  76. setprop("controls/lighting/radio-norm",light);
  77. });
  78. setlistener("sim/model/r44/remove-door-rr", func {
  79. var weight = getprop("yasim/gross-weight-lbs");
  80. if(getprop("sim/model/r44/remove-door-rr") == 1) {
  81. setprop("yasim/gross-weight-lbs",weight-7);
  82. } else {
  83. setprop("yasim/gross-weight-lbs",weight+7);
  84. }
  85. });
  86. #subtract the weight of the doors if they are removed
  87. setlistener("sim/model/r44/remove-door-rf", func {
  88. var weight = getprop("yasim/gross-weight-lbs");
  89. if(getprop("sim/model/r44/remove-door-rf") == 1) {
  90. setprop("yasim/gross-weight-lbs",weight-7.5);
  91. } else {
  92. setprop("yasim/gross-weight-lbs",weight+7.5);
  93. }
  94. });
  95. setlistener("sim/model/r44/remove-door-lr", func {
  96. var weight = getprop("yasim/gross-weight-lbs");
  97. if(getprop("sim/model/r44/remove-door-lr") == 1) {
  98. setprop("yasim/gross-weight-lbs",weight-7);
  99. } else {
  100. setprop("yasim/gross-weight-lbs",weight+7);
  101. }
  102. });
  103. setlistener("sim/model/r44/remove-door-lf", func {
  104. var weight = getprop("yasim/gross-weight-lbs");
  105. if(getprop("sim/model/r44/remove-door-lf") == 1) {
  106. setprop("yasim/gross-weight-lbs",weight-7.5);
  107. } else {
  108. setprop("yasim/gross-weight-lbs",weight+7.5);
  109. }
  110. });
  111. setlistener("/sim/current-view/view-number", func(vw) {
  112. var nm = vw.getValue();
  113. setprop("sim/model/sound/volume", 1.0);
  114. if(nm == 0 or nm == 7)setprop("sim/model/sound/volume", 0.5);
  115. },1,0);
  116. setlistener("/gear/gear[1]/wow", func(gr) {
  117. if(gr.getBoolValue()){
  118. FHmeter.stop();
  119. }else{FHmeter.start();}
  120. },0,0);
  121. setlistener("/engines/engine/out-of-fuel", func(fl) {
  122. var nofuel = fl.getBoolValue();
  123. if(nofuel)kill_engine();
  124. },0,0);
  125. setlistener("/controls/electric/key", func(key){
  126. var key = key.getValue();
  127. if(key == 0)kill_engine();
  128. },0,0);
  129. setlistener("controls/engines/engine[0]/clutch", func(clutch){
  130. var clutch= clutch.getBoolValue();
  131. if(clutch and props.globals.getNode("/engines/engine/running",1).getBoolValue()){
  132. setprop("/engines/engine/clutch-engaged",1);
  133. setprop("/sim/model/r44/cluthLight",1);
  134. }else{
  135. setprop("/engines/engine/clutch-engaged",0);
  136. setprop("/sim/model/r44/cluthLight",0);
  137. }
  138. },0,0);
  139. ##############################################
  140. ######### AUTOSTART / AUTOSHUTDOWN ###########
  141. ##############################################
  142. setlistener("/sim/model/start-idling", func(idle){
  143. var run= idle.getBoolValue();
  144. if(run){
  145. Startup();
  146. }else{
  147. Shutdown();
  148. }
  149. },0,0);
  150. var Startup = func {
  151. setprop("/controls/electric/battery-switch",1);
  152. setprop("controls/engines/engine[0]/mixture",1);
  153. setprop("/controls/electric/engine/generator",1);
  154. setprop("/controls/electric/key",4);
  155. setprop("/engines/engine/rpm",2700);
  156. setprop("/engines/engine/running",1);
  157. setprop("/controls/engines/engine/clutch",1);
  158. }
  159. var Shutdown = func {
  160. setprop("controls/engines/engine[0]/mixture",0);
  161. setprop("/controls/electric/battery-switch",0);
  162. setprop("/controls/electric/engine/generator",0);
  163. setprop("/controls/electric/key",0);
  164. setprop("/engines/engine/rpm",0);
  165. setprop("/engines/engine/running",0);
  166. setprop("/controls/engines/engine/clutch",0);
  167. }
  168. ###############################################
  169. ###############################################
  170. ###############################################
  171. var flight_meter = func{
  172. var fmeter = getprop("/instrumentation/clock/flight-meter-sec");
  173. var fminute = fmeter * 0.016666;
  174. var fhour = fminute * 0.016666;
  175. setprop("/instrumentation/clock/flight-meter-hour",fhour);
  176. }
  177. var kill_engine=func{
  178. setprop("/controls/engines/engine/magnetos",0);
  179. setprop("/engines/engine/clutch-engaged",0);
  180. setprop("/engines/engine/running",0);
  181. setprop("/engines/engine/rpm",0);
  182. start_timer=0;
  183. }
  184. var update_fuel = func{
  185. var amnt = arg[0] * GPS;
  186. amnt = amnt * 0.5;
  187. var lvl = Fuel1_Level.getValue();
  188. var lvl2 = Fuel2_Level.getValue();
  189. lvl = lvl-amnt;
  190. if(lvl2 > 0){lvl2 = lvl2-amnt;
  191. }else{
  192. lvl = lvl-amnt;
  193. }
  194. if(lvl < 0.0)lvl = 0.0;
  195. if(lvl2 < 0.0)lvl2 = 0.0;
  196. var ttl = lvl+lvl2;
  197. Fuel1_Level.setDoubleValue(lvl);
  198. Fuel1_LBS.setDoubleValue(lvl * Fuel_Density);
  199. Fuel2_Level.setDoubleValue(lvl2);
  200. Fuel2_LBS.setDoubleValue(lvl2 * Fuel_Density);
  201. TotalFuelG.setDoubleValue(ttl);
  202. TotalFuelP.setDoubleValue(ttl * Fuel_Density);
  203. if(ttl < 0.2){
  204. if(!NoFuel.getBoolValue()){
  205. NoFuel.setBoolValue(1);
  206. }
  207. }
  208. }
  209. var update_systems = func {
  210. var time = getprop("/sim/time/elapsed-sec");
  211. var dt = time - last_time;
  212. last_time = time;
  213. var throttle = getprop("/controls/rotor/engine-throttle");
  214. if(getprop("engines/engine/running"))update_fuel(dt);
  215. flight_meter();
  216. if(!RPM_arm.getBoolValue()){
  217. if(getprop("/rotors/main/rpm") > 525)RPM_arm.setBoolValue(1);
  218. }
  219. if(getprop("/rotors/main/rpm") > 475) {
  220. setprop("/sim/model/r44/cluthLight",0);
  221. }
  222. if(getprop("/systems/electrical/outputs/starter") > 11){
  223. if(getprop("/controls/electric/key") > 2){
  224. setprop("/engines/engine/cranking",1);
  225. }
  226. if(getprop("/controls/engines/engine/clutch")){
  227. setprop("/engines/engine/clutch-engaged",1);
  228. } else {
  229. setprop("/engines/engine/clutch-engaged",0);
  230. }
  231. }else{
  232. setprop("/engines/engine/cranking",0);
  233. }
  234. if(getprop("/engines/engine/cranking") != 0){
  235. if(!getprop("/engines/engine/running")){
  236. start_timer +=1;
  237. }else{start_timer = 0;}
  238. }
  239. if(start_timer > 40){
  240. setprop("/engines/engine/running",1);
  241. start_timer = 0;
  242. }
  243. if(getprop("/engines/engine/running")){
  244. #when engine on moves fuel pressure and temperature gaguges NOTE: not realistic!! fix later
  245. interpolate("oilpressure",24,0.6);
  246. interpolate("oiltemp",24,20);
  247. var engineTrottle = getprop("/controls/engines/engine/throttle"); #mp gauge based on throttle
  248. interpolate("/r44/engines/engine[0]/mp-pressure", (engineTrottle*0.44) + 0.45, 0.9);
  249. if(getprop("/engines/engine/amp-v") > 0){
  250. if(getprop("/engines/engine/clutch-engaged")){
  251. interpolate("/rotors/main/rpm", 2700 * throttle, 0.9);
  252. interpolate("/rotors/tail/rpm", 2700 * throttle, 0.9);
  253. }else{
  254. interpolate("/rotors/main/rpm", 0, 0.2);
  255. interpolate("/rotors/tail/rpm", 0, 0.2);
  256. }
  257. interpolate("/engines/engine/rpm", 2700 * throttle, 0.8);
  258. } else {
  259. }
  260. }else{
  261. interpolate("oilpressure",0,0.6);
  262. interpolate("oiltemp",0,20);
  263. interpolate("/engines/engine/rpm", 0, 0.8);
  264. interpolate("/rotors/main/rpm", 0, 0.4);
  265. interpolate("/rotors/tail/rpm", 0, 0.4);
  266. setprop("/r44/engines/engine[0]/mp-pressure",1);
  267. }
  268. if(getprop("/consumables/fuel/total-fuel-lbs") == 0) {
  269. kill_engine();
  270. }
  271. if(getprop("controls/engines/engine[0]/mixture") < 0.6) {
  272. kill_engine();
  273. }
  274. if(getprop("/controls/electric/key") == 0) {
  275. kill_engine();
  276. }
  277. settimer(update_systems,0);
  278. }
  279. var splash_vec_loop = func(){
  280. var airspeed = getprop("/velocities/airspeed-kt");
  281. var airspeed_max = 120;
  282. if (airspeed > airspeed_max) {
  283. airspeed = airspeed_max;
  284. }
  285. airspeed = math.sqrt(airspeed / airspeed_max);
  286. var splash_x = -0.1 - 2 * airspeed;
  287. var splash_y = 0.0;
  288. var splash_z = -1*(1.0 - 1.35 * airspeed);
  289. setprop("/environment/aircraft-effects/splash-vector-x", splash_x);
  290. setprop("/environment/aircraft-effects/splash-vector-y", splash_y);
  291. setprop("/environment/aircraft-effects/splash-vector-z", splash_z);
  292. settimer(func(){
  293. splash_vec_loop();
  294. }, 0.16);
  295. }