as350_electrical.nas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Initialize properties
  2. setprop("/systems/electrical/battery/voltage", 0);
  3. setprop("/systems/electrical/battery/current", 0);
  4. setprop("/controls/electric/battery-switch", 0);
  5. setprop("/controls/electric/avionics-switch", 0);
  6. setprop("/controls/electric/engine/generator", 0);
  7. setprop("/systems/electrical/generator/voltage", 0);
  8. setprop("/systems/electrical/generator/current", 0);
  9. setprop("/systems/electrical/avionics/power", 0);
  10. setprop("/systems/electrical/lights/beacon", 0);
  11. setprop("/systems/electrical/lights/landing", 0);
  12. setprop("/systems/electrical/lights/nav", 0);
  13. setprop("/systems/electrical/lights/strobe", 0);
  14. setprop("/systems/electrical/lights/search", 0);
  15. setprop("/controls/lighting/instrument-lights", 0);
  16. setprop("/systems/electrical/outputs/com1", 0);
  17. setprop("/systems/electrical/outputs/nav1", 0);
  18. var batteryCapacity = 17;
  19. var temperature = getprop("/environment/temperature-degc");
  20. var generatorOn = getprop("/controls/electric/engine/generator");
  21. var batteryCharge = func(temperature) {
  22. if (temperature >= -39 and temperature <= 69) {
  23. if (temperature < 3 or temperature > 55) {
  24. batteryCapacity = batteryCapacity / 2;
  25. }
  26. } else {
  27. return 0;
  28. }
  29. return batteryCapacity;
  30. };
  31. var voltageOutput = func(batteryCapacity) {
  32. if (batteryCapacity > 0) {
  33. return 26.4;
  34. } else {
  35. return 0;
  36. }
  37. };
  38. var currentOutput = func(voltageOutput) {
  39. if (voltageOutput > 0) {
  40. return 500;
  41. } else {
  42. return 0;
  43. }
  44. };
  45. setlistener("/controls/electric/battery-switch", func {
  46. if (getprop("/controls/electric/battery-switch") == 1) {
  47. var temperature = getprop("/environment/temperature-degc");
  48. var capacity = batteryCharge(temperature);
  49. var outputVoltage = voltageOutput(capacity);
  50. var outputCurrent = currentOutput(outputVoltage);
  51. if (outputVoltage > 0 and outputCurrent > 0) {
  52. setprop("/systems/electrical/battery/voltage", outputVoltage);
  53. setprop("/systems/electrical/battery/current", outputCurrent);
  54. setprop("/controls/electric/avionics-switch", 1);
  55. } else {
  56. setprop("/controls/electric/avionics-switch", 0);
  57. }
  58. } else {
  59. setprop("/systems/electrical/battery/voltage", 0);
  60. setprop("/systems/electrical/battery/current", 0);
  61. setprop("/controls/electric/avionics-switch", 0);
  62. }
  63. });
  64. setlistener("/controls/electric/engine/generator", func {
  65. if (getprop("/controls/electric/engine/generator") == 1) {
  66. setprop("/systems/electrical/generator/voltage", 28);
  67. setprop("/systems/electrical/generator/current", 500);
  68. # Check if the battery is not fully charged
  69. if (batteryCapacity < 17) {
  70. batteryCapacity = math.min(batteryCapacity + 0.1, 17); # Increment the battery capacity while charging
  71. }
  72. } else {
  73. setprop("/systems/electrical/generator/voltage", 0);
  74. setprop("/systems/electrical/generator/current", 0);
  75. }
  76. });
  77. setlistener("/controls/electric/avionics-switch", func {
  78. var avionicsPower = getprop("/controls/electric/avionics-switch");
  79. if (avionicsPower == 1) {
  80. setprop("/systems/electrical/avionics/power", 1);
  81. setprop("/systems/electrical/lights/beacon", 1);
  82. setprop("/systems/electrical/lights/landing", 1);
  83. setprop("/systems/electrical/lights/nav", 1);
  84. setprop("/systems/electrical/lights/strobe", 1);
  85. setprop("/systems/electrical/lights/search", 1);
  86. setprop("/controls/lighting/instrument-lights", 1);
  87. setprop("/systems/electrical/outputs/com1", 1);
  88. setprop("/systems/electrical/outputs/nav1", 1);
  89. } else {
  90. setprop("/systems/electrical/avionics/power", 0);
  91. setprop("/systems/electrical/lights/beacon", 0);
  92. setprop("/systems/electrical/lights/landing", 0);
  93. setprop("/systems/electrical/lights/nav", 0);
  94. setprop("/systems/electrical/lights/strobe", 0);
  95. setprop("/systems/electrical/lights/search", 0);
  96. setprop("/controls/lighting/instrument-lights", 0);
  97. setprop("/systems/electrical/outputs/com1", 0);
  98. setprop("/systems/electrical/outputs/nav1", 0);
  99. }
  100. });