engines.nas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # engine.nas by geed
  2. var pi = 3.14159;
  3. var PWR2TRQ = 60 / 2 / pi * 6.931;
  4. var PWR2TRQPCT = PWR2TRQ / 986 * 100;
  5. var max = func(a, b) a > b ? a : b;
  6. var min = func(a, b) a < b ? a : b;
  7. #set caution ranges for enigines oil temp and press gauges
  8. setprop("/engines/oilt-caution-lo-degc",30);
  9. setprop("/engines/oilt-caution-hi-degc",120);
  10. setprop("/engines/oilp-caution-lo-bar",1.5);
  11. setprop("/engines/oilp-caution-hi-bar",8);
  12. setprop("/engines/oilp-ratio-bar-to-psi",21); # this is the ratio for the OIL PSI instrument to show the right value, not the real life ratio (which is 14.5038)
  13. var oilpressure = func(n){
  14. oilpres_low = props.globals.getNode("/engines/engine[" ~ n ~ "]/oil-pressure-low", 1);
  15. oilpres_norm = props.globals.getNode("/engines/engine[" ~ n ~ "]/oil-pressure-norm", 1);
  16. oilpres_bar = props.globals.getNode("/engines/engine[" ~ n ~ "]/oil-pressure-bar", 1);
  17. var rpm = props.globals.getValue("/engines/engine[" ~ n ~ "]/n2-rpm") or 0;
  18. if ( rpm > 0 ) oilpres_low.setDoubleValue((15-22000/rpm)*0.0689);
  19. if ( rpm > 0 ) oilpres_norm.setDoubleValue((60-22000/rpm)*0.0689);
  20. settimer(func { oilpressure(n) }, 0);
  21. }
  22. oilpressure(0);
  23. oilpressure(1);
  24. ##############
  25. var oilpressurebar = func(n){
  26. oilpres_bar = props.globals.getNode("/engines/engine[" ~ n ~ "]/oil-pressure-bar", 1);
  27. var rpm = props.globals.getValue("/engines/engine[" ~ n ~ "]/n2-rpm") or 0;
  28. var oilpres_low = props.globals.getValue("/engines/engine[" ~ n ~ "]/oil-pressure-low") or 0;
  29. var oilpres_norm = props.globals.getValue("/engines/engine[" ~ n ~ "]/oil-pressure-norm") or 0;
  30. # by litzi clamp oilpressure >= 0
  31. if ((rpm > 0) and (rpm < 23000)){
  32. interpolate ("/engines/engine[" ~ n ~ "]/oil-pressure-bar", max(oilpres_low, 0) , 1.5);
  33. }elsif (rpm > 23000) {
  34. interpolate ("/engines/engine[" ~ n ~ "]/oil-pressure-bar", max(oilpres_norm, 0) , 2);
  35. }
  36. settimer(func { oilpressurebar(n) }, 0.1);
  37. }
  38. oilpressurebar(0);
  39. oilpressurebar(1);
  40. ##################
  41. var oiltemp = func(n){
  42. var OAT = props.globals.getValue("/environment/temperature-degc") or 0;
  43. var oilpres_bar = props.globals.getValue("/engines/engine[" ~ n ~ "]/oil-pressure-bar") or 0;
  44. var rpm = props.globals.getValue("/engines/engine[" ~ n ~ "]/n2-rpm") or 0;
  45. ot = props.globals.getNode("/engines/engine[" ~ n ~ "]/oil-temperature-degc", 1);
  46. if (oilpres_bar >1){
  47. interpolate ("/engines/engine[" ~ n ~ "]/oil-temperature-degc", ((25-22000/rpm)*oilpres_bar)+OAT , 20);
  48. } else {
  49. interpolate ("/engines/engine[" ~ n ~ "]/oil-temperature-degc", OAT , 20);
  50. }
  51. settimer( func { oiltemp(n) }, 0);
  52. }
  53. oiltemp(0);
  54. oiltemp(1);
  55. #########################################
  56. ###main gear box oil pressure###
  57. var mgbp = func {
  58. #create oilpressure#
  59. mgb_oilpres_low = props.globals.getNode("/rotors/gear/mgb-oil-pressure-low", 1);
  60. mgb_oilpres_norm = props.globals.getNode("/rotors/gear/mgb-oil-pressure-norm", 1);
  61. mgb_oilpres_bar = props.globals.getNode("/rotors/gear/mgb-oil-pressure-bar", 1);
  62. var rpm = props.globals.getValue("/rotors/main/rpm") or 0;
  63. if ( rpm > 0 ) mgb_oilpres_low.setDoubleValue((15-230/rpm)*0.0689);
  64. if ( rpm > 0 ) mgb_oilpres_norm.setDoubleValue((60-230/rpm)*0.0689);
  65. settimer(mgbp, 0);
  66. }
  67. mgbp();
  68. ##############
  69. var mgbp_bar = func{
  70. mgb_oilpres_bar = props.globals.getNode("/rotors/gear/mgb-oil-pressure-bar", 1);
  71. var rpm = props.globals.getValue("/rotors/main/rpm") or 0;
  72. mgb_oilpres_low = props.globals.getValue("/rotors/gear/mgb-oil-pressure-low") or 0;
  73. mgb_oilpres_norm = props.globals.getValue("/rotors/gear/mgb-oil-pressure-norm") or 0;
  74. if ((rpm > 0) and (rpm < 280)){
  75. interpolate ("/rotors/gear/mgb-oil-pressure-bar",max(mgb_oilpres_low,0), 1.5);
  76. }elsif (rpm > 280) {
  77. interpolate ("/rotors/gear/mgb-oil-pressure-bar",max(mgb_oilpres_norm,0), 2);
  78. }
  79. settimer(mgbp_bar, 0.1);
  80. }
  81. mgbp_bar();