electrical.nas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. #A-10 electrical system.
  2. # A-10 external-battery-switch assumed always on
  3. # A-10 external pwr assumed never connected
  4. var battery = nil;
  5. var alternator = nil;
  6. var last_time = 0.0;
  7. var bat_src_volts = 0.0;
  8. var external_volts = 0.0;
  9. var battery_bus_volts = 0.0;
  10. var L_DC_bus_volts = 0.0;
  11. var R_DC_bus_volts = 0.0;
  12. var L_AC_bus_volts = 0.0;
  13. var R_AC_bus_volts = 0.0;
  14. var L_conv_volts = 0.0;
  15. var R_conv_volts = 0.0;
  16. var AC_ESSEN_bus_volts = 0.0;
  17. var DC_ESSEN_bus_volts = 0.0;
  18. var ammeter_ave = 0.0;
  19. var APU_Running = props.globals.getNode("sim/model/A-10/systems/apu/running");
  20. var APU_Rpm = props.globals.getNode("sim/model/A-10/systems/apu/rpm-norm");
  21. var init_electrical = func {
  22. battery = BatteryClass.new();
  23. alternator = AlternatorClass.new();
  24. setprop("controls/switches/master-avionics", 0);
  25. setprop("controls/electric/battery-switch", 0);
  26. setprop("controls/electric/external-power", 0);
  27. setprop("controls/electric/engine[0]/generator", 0);
  28. setprop("controls/electric/engine[1]/generator", 0);
  29. setprop("sim/model/A-10/controls/switches/inverter", 1);
  30. setprop("systems/electrical/power_source", "none");
  31. setprop("systems/electrical/L-conv-volts", 0.0);
  32. setprop("systems/electrical/R-conv-volts", 0.0);
  33. setprop("systems/electrical/inverter-volts", 0.0);
  34. setprop("systems/electrical/radar", 24.0);
  35. # radar only used to allow Air to Air Refueling code to work.
  36. }
  37. var BatteryClass = {};
  38. BatteryClass.new = func {
  39. var obj = { parents : [BatteryClass],
  40. ideal_volts : 26.0,
  41. ideal_amps : 30.0,
  42. amp_hours : 12.75,
  43. charge_percent : 1.0,
  44. charge_amps : 7.0 };
  45. return obj;
  46. }
  47. BatteryClass.apply_load = func( amps, dt ) {
  48. var amphrs_used = amps * dt / 3600.0;
  49. var percent_used = amphrs_used / me.amp_hours;
  50. me.charge_percent -= percent_used;
  51. if ( me.charge_percent < 0.0 ) {
  52. me.charge_percent = 0.0;
  53. } elsif ( me.charge_percent > 1.0 ) {
  54. me.charge_percent = 1.0;
  55. }
  56. return me.amp_hours * me.charge_percent;
  57. }
  58. BatteryClass.get_output_volts = func {
  59. var x = 1.0 - me.charge_percent;
  60. var factor = x / 10;
  61. return me.ideal_volts - factor;
  62. }
  63. BatteryClass.get_output_amps = func {
  64. var x = 1.0 - me.charge_percent;
  65. var tmp = -(3.0 * x - 1.0);
  66. var factor = (tmp*tmp*tmp*tmp*tmp + 32) / 32;
  67. return me.ideal_amps * factor;
  68. }
  69. var AlternatorClass = {};
  70. AlternatorClass.new = func {
  71. var obj = { parents : [AlternatorClass],
  72. ideal_volts : 26.0,
  73. ideal_amps : 60.0 };
  74. return obj;
  75. }
  76. AlternatorClass.apply_load = func( amps, dt, src ) {
  77. var rpm = getprop(src);
  78. var factor = 0;
  79. # A-10 APU can have 0 rpm
  80. if (rpm > 0) {
  81. factor = math.ln(rpm)/4;
  82. }
  83. var available_amps = me.ideal_amps * factor;
  84. return available_amps - amps;
  85. }
  86. AlternatorClass.get_output_volts = func( src ) {
  87. var rpm = getprop(src);
  88. var factor = 0;
  89. # A-10 APU can have 0 rpm
  90. if (rpm > 0) {
  91. factor = math.ln(rpm)/4;
  92. }
  93. return me.ideal_volts * factor;
  94. }
  95. AlternatorClass.get_output_amps = func(src ){
  96. rpm = getprop(src);
  97. var factor = 0;
  98. # A-10 APU can have 0 rpm
  99. if (rpm > 0) {
  100. factor = math.ln(rpm)/4;
  101. }
  102. return me.ideal_amps * factor;
  103. }
  104. var update_electrical = func {
  105. var time = getprop("sim/time/elapsed-sec");
  106. var dt = time - last_time;
  107. last_time = time;
  108. update_virtual_bus( dt );
  109. check_bleed_air();
  110. }
  111. var update_virtual_bus = func( dt ) {
  112. var eng_outof = getprop("engines/engine[0]/out-of-fuel");
  113. # var eng_outof1 = getprop("engines/engine[1]/out-of-fuel");
  114. var master_bat = getprop("controls/electric/battery-switch");
  115. var master_apu = getprop("controls/APU/generator");
  116. var master_alt = getprop("controls/electric/engine[0]/generator");
  117. var master_alt1 = getprop("controls/electric/engine[1]/generator");
  118. var master_inv = getprop("sim/model/A-10/controls/switches/inverter");
  119. var L_gen_volts = 0.0;
  120. var R_gen_volts = 0.0;
  121. var APU_gen_volts = 0.0;
  122. #var INV_volts = getprop("systems/electrical/inverter-volts");
  123. var INV_volts = 0.0;
  124. battery_volts = battery.get_output_volts();
  125. L_AC_bus_volts = 0.0;
  126. R_AC_bus_volts = 0.0;
  127. load = 0.0;
  128. AC_ESSEN_bus_volts = 0.0;
  129. R_conv_volts = 0.0;
  130. L_conv_volts = 0.0;
  131. var power_source = nil;
  132. #var ammeter = 0.0;
  133. if (master_alt and !eng_outof) {
  134. L_gen_volts = alternator.get_output_volts("sim/model/A-10/engines/engine[0]/n2");
  135. }
  136. # if (master_alt1 and !eng_outof1) {
  137. # R_gen_volts = alternator.get_output_volts("sim/model/A-10/engines/engine[1]/n2");
  138. # }
  139. if(master_apu and getprop("controls/APU/generator-serviceable")) {
  140. APU_gen_volts = alternator.get_output_volts("sim/model/A-10/systems/apu/rpm-norm");
  141. }
  142. # determine power source
  143. if ( master_bat == 1 ) { bat_src_volts = battery_volts; }
  144. if (APU_gen_volts >= 23) {
  145. R_conv_volts = APU_gen_volts;
  146. if ((L_gen_volts < 23) and (R_gen_volts < 23)) {
  147. L_AC_bus_volts = APU_gen_volts;
  148. R_AC_bus_volts = APU_gen_volts;
  149. AC_ESSEN_bus_volts = APU_gen_volts;
  150. L_conv_volts = APU_gen_volts;
  151. power_source = "apu";
  152. }
  153. if ((L_gen_volts < 23) and (R_gen_volts >= 23)) {
  154. L_AC_bus_volts = R_gen_volts;
  155. R_AC_bus_volts = R_gen_volts;
  156. AC_ESSEN_bus_volts = R_gen_volts;
  157. L_conv_volts = R_gen_volts;
  158. }
  159. if ((L_gen_volts >= 23) and (R_gen_volts < 23)) {
  160. L_AC_bus_volts = L_gen_volts;
  161. R_AC_bus_volts = L_gen_volts;
  162. AC_ESSEN_bus_volts = L_gen_volts;
  163. L_conv_volts = L_gen_volts;
  164. }
  165. if ((L_gen_volts >= 23) and (R_gen_volts >= 23)) {
  166. L_AC_bus_volts = L_gen_volts;
  167. R_AC_bus_volts = R_gen_volts;
  168. AC_ESSEN_bus_volts = L_gen_volts;
  169. L_conv_volts = L_gen_volts;
  170. }
  171. }
  172. if (APU_gen_volts < 23) {
  173. if ((L_gen_volts < 23) and (R_gen_volts < 23)) {
  174. L_AC_bus_volts = 0.0;
  175. R_AC_bus_volts = 0.0;
  176. AC_ESSEN_bus_volts = INV_volts;
  177. L_conv_volts = 0.0;
  178. R_conv_volts = 0.0;
  179. }
  180. if ((L_gen_volts < 23) and (R_gen_volts >= 23)) {
  181. L_AC_bus_volts = R_gen_volts;
  182. R_AC_bus_volts = R_gen_volts;
  183. AC_ESSEN_bus_volts = R_gen_volts;
  184. L_conv_volts = R_gen_volts;
  185. R_conv_volts = R_gen_volts;
  186. }
  187. if ((L_gen_volts >= 23) and (R_gen_volts < 23)) {
  188. L_AC_bus_volts = L_gen_volts;
  189. R_AC_bus_volts = L_gen_volts;
  190. AC_ESSEN_bus_volts = L_gen_volts;
  191. L_conv_volts = L_gen_volts;
  192. R_conv_volts = L_gen_volts;
  193. }
  194. if ((L_gen_volts >= 23) and (R_gen_volts >= 23)) {
  195. L_AC_bus_volts = L_gen_volts;
  196. R_AC_bus_volts = R_gen_volts;
  197. AC_ESSEN_bus_volts = L_gen_volts;
  198. L_conv_volts = L_gen_volts;
  199. R_conv_volts = L_gen_volts;
  200. }
  201. }
  202. if ((L_conv_volts >= 23) and (R_conv_volts >= 23)) {
  203. DC_ESSEN_bus_volts = L_conv_volts;
  204. AUX_DC_ESSEN_bus_volts = L_conv_volts;
  205. battery_bus_volts = L_conv_volts;
  206. L_DC_bus_volts = L_conv_volts;
  207. R_DC_bus_volts = R_conv_volts;
  208. bat_src_volts = L_conv_volts;
  209. power_source = "none";
  210. }
  211. if ((L_conv_volts < 23) and (R_conv_volts >= 23)) {
  212. DC_ESSEN_bus_volts = R_conv_volts;
  213. AUX_DC_ESSEN_bus_volts = R_conv_volts;
  214. battery_bus_volts = R_conv_volts;
  215. L_DC_bus_volts = R_conv_volts;
  216. R_DC_bus_volts = R_conv_volts;
  217. bat_src_volts = R_conv_volts;
  218. power_source = "none";
  219. }
  220. if ((L_conv_volts >= 23) and (R_conv_volts < 23)) {
  221. DC_ESSEN_bus_volts = L_conv_volts;
  222. AUX_DC_ESSEN_bus_volts = L_conv_volts;
  223. battery_bus_volts = L_conv_volts;
  224. L_DC_bus_volts = L_conv_volts;
  225. R_DC_bus_volts = L_conv_volts;
  226. bat_src_volts = L_conv_volts;
  227. power_source = "none";
  228. }
  229. if ((L_conv_volts < 23) and (R_conv_volts < 23)) {
  230. DC_ESSEN_bus_volts = bat_src_volts;
  231. AUX_DC_ESSEN_bus_volts = bat_src_volts;
  232. battery_bus_volts = bat_src_volts;
  233. L_DC_bus_volts = 0.0;
  234. R_DC_bus_volts = 0.0;
  235. power_source = "battery";
  236. }
  237. if (( master_bat == 0 ) and (L_conv_volts < 23) and (L_conv_volts < 23)) {
  238. DC_ESSEN_bus_volts = 0.0;
  239. AUX_DC_ESSEN_bus_volts = 0.0;
  240. }
  241. # Inverter
  242. if (( master_inv == 2 ) and (L_gen_volts < 20) and (R_gen_volts < 20)) {
  243. INV_volts = bat_src_volts;
  244. power_source = "battery"; # Does not mean that the battery is
  245. # connected to any bus.
  246. } elsif ( master_inv == 1 ) {
  247. INV_volts = 0.0;
  248. } elsif ( master_inv == 0 ) {
  249. INV_volts = bat_src_volts;
  250. power_source = "battery";
  251. }
  252. load += BATT_bus();
  253. load += DC_ESSEN_bus();
  254. load += AUX_DC_ESSEN_bus();
  255. load += L_DC_bus();
  256. load += R_DC_bus();
  257. load += L_AC_bus();
  258. load += R_AC_bus();
  259. load += AC_ESSEN_bus();
  260. if ( bat_src_volts > 1.0 ) {
  261. # normal load
  262. load += 15.0;
  263. # ammeter gauge
  264. #if ( power_source == "battery" ) {
  265. # ammeter = -load;
  266. #} else {
  267. # ammeter = battery.charge_amps;
  268. #}
  269. }
  270. # charge/discharge the battery
  271. if ( power_source == "battery" ) {
  272. battery.apply_load( load, dt );
  273. #setprop( "systems/electrical/power_source", power_source );
  274. } elsif ( bat_src_volts > battery_volts ) {
  275. battery.apply_load( -battery.charge_amps, dt );
  276. }
  277. setprop("systems/electrical/power_source", power_source);
  278. # filter ammeter needle pos
  279. #ammeter_ave = 0.8 * ammeter_ave + 0.2 * ammeter;
  280. # outputs
  281. setprop("systems/electrical/amps", ammeter_ave);
  282. setprop("systems/electrical/volts", bat_src_volts);
  283. #setprop("systems/electrical/ac_amps", AC_bus_amps);
  284. setprop("systems/electrical/inverter-volts", INV_volts);
  285. setprop("systems/electrical/APU-gen-volts", APU_gen_volts);
  286. setprop("systems/electrical/L-AC-volts", L_AC_bus_volts);
  287. setprop("systems/electrical/R-AC-volts", R_AC_bus_volts);
  288. setprop("systems/electrical/L-conv-volts", L_conv_volts);
  289. setprop("systems/electrical/R-conv-volts", R_conv_volts);
  290. return load;
  291. }
  292. var BATT_bus = func() {
  293. load = 0.0;
  294. if ( getprop("controls/switches/cabin-lights") ) {
  295. setprop("systems/electrical/outputs/cabin-lights", battery_bus_volts);
  296. } else {
  297. setprop("systems/electrical/outputs/cabin-lights", 0.0);
  298. }
  299. return load;
  300. }
  301. var DC_ESSEN_bus = func() {
  302. load = 0.0;
  303. var DC_ESSEN_ok = 0;
  304. setprop("systems/electrical/outputs/nav[0]", DC_ESSEN_bus_volts);
  305. setprop("systems/electrical/outputs/com[0]", DC_ESSEN_bus_volts);
  306. setprop("systems/electrical/outputs/nav[1]", DC_ESSEN_bus_volts);
  307. setprop("systems/electrical/outputs/com[1]", DC_ESSEN_bus_volts);
  308. setprop("systems/electrical/outputs/nav[2]", DC_ESSEN_bus_volts);
  309. setprop("systems/electrical/outputs/ldg-warning-system", DC_ESSEN_bus_volts);
  310. #setprop("systems/electrical/outputs/apu-start-system", DC_ESSEN_bus_volts);
  311. setprop("systems/electrical/outputs/caution-panel", DC_ESSEN_bus_volts);
  312. if ( DC_ESSEN_bus_volts >= 20) {
  313. DC_ESSEN_ok = 1;
  314. }
  315. load += A10fuel.DC_boost_pump.getBoolValue() * 15;
  316. # APU starter
  317. if ( APU_Rpm.getValue() < 60 and APU_Running.getBoolValue() ) {
  318. load += 120.0;
  319. }
  320. # Cross Feed switch
  321. if ( getprop("sim/model/A-10/controls/fuel/cross-feed-sw") and DC_ESSEN_ok ) {
  322. setprop("systems/A-10-fuel/cross-feed-valve", 1);
  323. load += 0.2;
  324. } else {
  325. setprop("systems/A-10-fuel/cross-feed-valve", 0);
  326. }
  327. # Tank Gate switch
  328. if ( getprop("sim/model/A-10/controls/fuel/tk-gate-switch") and DC_ESSEN_ok ) {
  329. setprop("systems/A-10-fuel/tank-gate-valve", 1);
  330. load += 0.2;
  331. } else {
  332. setprop("systems/A-10-fuel/tank-gate-valve", 0)
  333. }
  334. # external tank pumps to feed internal tanks
  335. var int_tanks_filled = 0;
  336. for( var i = 0; i < 4; i += 1 ) {
  337. if ( getprop("consumables/fuel/tank["~i~"]/fill-valve") ) {
  338. int_tanks_filled += 1;
  339. }
  340. }
  341. # external wing tanks
  342. if (
  343. int_tanks_filled > 0
  344. and getprop("controls/fuel/tank[4]/boost-pump[0]")
  345. and !getprop("systems/refuel/receiver-lever")
  346. and getprop("controls/fuel/tank[4]/boost-pump-serviceable")
  347. and getprop("consumables/fuel/tank[4]/level-gal_us") > 1.56
  348. and getprop("systems/bleed-air/psi") > 7
  349. and DC_ESSEN_ok
  350. ) {
  351. A10fuel.Left_External.set_boost_pump(1);
  352. load += 15.0;
  353. } else {
  354. A10fuel.Left_External.set_boost_pump(0);
  355. }
  356. # note: right external wing pump is controlled by controls/fuel/tank[4]/boost-pump[0] too
  357. if (
  358. int_tanks_filled > 0
  359. and getprop("controls/fuel/tank[4]/boost-pump[0]")
  360. and !getprop("systems/refuel/receiver-lever")
  361. and getprop("controls/fuel/tank[6]/boost-pump-serviceable")
  362. and getprop("consumables/fuel/tank[6]/level-gal_us") > 1.56
  363. and getprop("systems/bleed-air/psi") > 7
  364. and DC_ESSEN_ok
  365. ) {
  366. A10fuel.Right_External.set_boost_pump(1);
  367. load += 15.0;
  368. } else {
  369. A10fuel.Right_External.set_boost_pump(0);
  370. }
  371. # external fuselage tank
  372. if (
  373. int_tanks_filled > 0
  374. and getprop("controls/fuel/tank[5]/boost-pump[0]")
  375. and !getprop("systems/refuel/receiver-lever")
  376. and getprop("controls/fuel/tank[5]/boost-pump-serviceable")
  377. and getprop("consumables/fuel/tank[5]/level-gal_us") > 1.56
  378. and ! A10fuel.Left_External.get_boost_pump()
  379. and ! A10fuel.Right_External.get_boost_pump()
  380. and getprop("systems/bleed-air/psi") > 7
  381. and DC_ESSEN_ok
  382. ) {
  383. A10fuel.Fuse_External.set_boost_pump(1);
  384. load += 15.0;
  385. } else {
  386. A10fuel.Fuse_External.set_boost_pump(0);
  387. }
  388. # Left and right gravity valve.
  389. if (
  390. getprop("consumables/fuel/tank[1]/level-gal_us") < 93.75
  391. and getprop("consumables/fuel/tank[0]/level-gal_us") > 2.34
  392. and ! A10fuel.Left_Wing.get_boost_pump()
  393. and DC_ESSEN_ok
  394. ) {
  395. A10fuel.Left_Wing.set_transfering(1);
  396. load += 0.2;
  397. } else {
  398. A10fuel.Left_Wing.set_transfering(0);
  399. }
  400. if (
  401. getprop("consumables/fuel/tank[2]/level-gal_us") < 93.75
  402. and getprop("consumables/fuel/tank[3]/level-gal_us") > 2.34
  403. and ! A10fuel.Right_Wing.get_boost_pump()
  404. and DC_ESSEN_ok
  405. ) {
  406. A10fuel.Right_Wing.set_transfering(1);
  407. load += 0.2;
  408. } else {
  409. A10fuel.Right_Wing.set_transfering(0)
  410. }
  411. return load;
  412. }
  413. var AUX_DC_ESSEN_bus = func() {
  414. load = 0.0;
  415. setprop("systems/electrical/outputs/engines-ignitors", AC_ESSEN_bus_volts);
  416. return load;
  417. }
  418. var L_DC_bus = func() {
  419. load = 0.0;
  420. setprop("systems/electrical/outputs/rwr", L_DC_bus_volts);
  421. foreach (var t; A10fuel.Tank.list) { load += t.get_fill_valve() * 0.2 }
  422. return load;
  423. }
  424. var R_DC_bus = func() {
  425. load = 0.0;
  426. setprop("systems/electrical/outputs/uhf-adf", R_DC_bus_volts);
  427. setprop("systems/electrical/outputs/vhf-comm", R_DC_bus_volts);
  428. setprop("systems/electrical/outputs/vhf-fm", R_DC_bus_volts);
  429. setprop("systems/electrical/outputs/ils", R_DC_bus_volts);
  430. setprop("systems/electrical/outputs/gau-8", R_DC_bus_volts);
  431. return load;
  432. }
  433. var L_AC_bus = func() {
  434. load = 0.0;
  435. # Left wing and main fuel pumps power
  436. if (
  437. getprop("controls/fuel/tank[0]/boost-pump[0]")
  438. and getprop("controls/fuel/tank[0]/boost-pump-serviceable")
  439. and getprop("consumables/fuel/tank[0]/level-gal_us") > 1.56
  440. and L_AC_bus_volts >= 20
  441. ) {
  442. A10fuel.Left_Wing.set_boost_pump(1);
  443. load += 15.0;
  444. } else {
  445. A10fuel.Left_Wing.set_boost_pump(0);
  446. }
  447. if (
  448. getprop("controls/fuel/tank[1]/boost-pump[0]")
  449. and getprop("controls/fuel/tank[1]/boost-pump-serviceable")
  450. and getprop("consumables/fuel/tank[1]/level-gal_us") > 1.56
  451. and L_AC_bus_volts >= 20
  452. and ! A10fuel.Left_Wing.get_boost_pump()
  453. ) {
  454. A10fuel.Left_Main.set_boost_pump(1);
  455. load += 15.0;
  456. } else {
  457. A10fuel.Left_Main.set_boost_pump(0);
  458. }
  459. return load;
  460. }
  461. var R_AC_bus = func() {
  462. load = 0.0;
  463. setprop("systems/electrical/outputs/tacan", R_AC_bus_volts);
  464. setprop("systems/electrical/outputs/hsi", R_AC_bus_volts);
  465. setprop("systems/electrical/outputs/adi", R_AC_bus_volts);
  466. setprop("systems/electrical/outputs/cadc", R_AC_bus_volts);
  467. setprop("systems/electrical/outputs/nav-mode", R_AC_bus_volts);
  468. setprop("systems/electrical/outputs/aoa-indexer", R_AC_bus_volts);
  469. var hud_mode = getprop("sim/model/A-10/controls/hud/mode-selector");
  470. if (hud_mode > 0) {
  471. setprop("systems/electrical/outputs/hud", R_AC_bus_volts);
  472. } else {
  473. setprop("systems/electrical/outputs/hud", 0);
  474. }
  475. setprop("instrumentation/attitude-indicator/spin", R_AC_bus_volts/30);
  476. setprop("systems/electrical/outputs/DG", R_AC_bus_volts);
  477. # Right wing and main fuel pumps power
  478. if (
  479. getprop("controls/fuel/tank[3]/boost-pump[0]")
  480. and getprop("controls/fuel/tank[3]/boost-pump-serviceable")
  481. and getprop("consumables/fuel/tank[3]/level-gal_us") > 1.56
  482. and R_AC_bus_volts >= 20
  483. ) {
  484. A10fuel.Right_Wing.set_boost_pump(1);
  485. load += 15.0;
  486. } else {
  487. A10fuel.Right_Wing.set_boost_pump(0);
  488. }
  489. if (
  490. getprop("controls/fuel/tank[2]/boost-pump[0]")
  491. and getprop("controls/fuel/tank[2]/boost-pump-serviceable")
  492. and getprop("consumables/fuel/tank[2]/level-gal_us") > 1.56
  493. and R_AC_bus_volts >= 20
  494. and ! A10fuel.Right_Wing.get_boost_pump()
  495. ) {
  496. A10fuel.Right_Main.set_boost_pump(1);
  497. load += 15.0;
  498. } else {
  499. A10fuel.Right_Main.set_boost_pump(0);
  500. }
  501. return load;
  502. }
  503. var AC_ESSEN_bus = func() {
  504. load = 0.0;
  505. setprop("systems/electrical/outputs/fuel-gauge-sel", AC_ESSEN_bus_volts);
  506. for(var i=0; i<2; i+=1) {
  507. for(var j=0; j<2; j+=1) {
  508. if(getprop("controls/engines/engine["~i~"]/engines-ignitors["~j~"]")) {
  509. setprop("systems/electrical/outputs/engine["~i~"]/engines-ignitors["~j~"]", AC_ESSEN_bus_volts);
  510. load += 25.0;
  511. } else {
  512. setprop("systems/electrical/outputs/engine["~i~"]/engines-ignitors["~j~"]", 0);
  513. }
  514. }
  515. }
  516. return load;
  517. }
  518. # bleed air system
  519. # ----------------
  520. var check_bleed_air= func {
  521. # max ECS incomming pressure : 65 psi ( from Environment Control System valve)
  522. # nin rpm from a running TF34 engine to start the other one : 85 %rpm
  523. # All numbers below guessed from above
  524. # min pressure for TF34 engine start : 50 psi
  525. # nominal APU : 70 psi @ 100 %rpm @ standard day (pressure = 29.92inhg)
  526. # nominal TF34 : 60 psi @ 90 %rpm
  527. var p0 = getprop("sim/model/A-10/engines/engine[0]/n2") * 0.67;
  528. # var p1 = getprop("sim/model/A-10/engines/engine[1]/n2") * 0.67;
  529. # APU provide bleed air psi > 50 psi up to an altitude of 10'000 ft @ standard day and 100% RPM
  530. var p2 = (getprop("environment/pressure-inhg")*2.13538+6.1093)*(getprop("sim/model/A-10/systems/apu/rpm-norm")/100);
  531. var bleed_air = p0;
  532. # if(p1 > bleed_air) { bleed_air = p1; }
  533. if(p2 > bleed_air) { bleed_air = p2; }
  534. setprop("systems/bleed-air/psi", bleed_air);
  535. # TODO: add bleed air temperature to monitor in warn panel BLEED AIR LEAK (warn light on if temp > 400°F => 204°C)
  536. }
  537. # other electrical power controls
  538. # -------------------------------
  539. var inverter_switch = func {
  540. var inv_pos = props.globals.getNode("sim/model/A-10/controls/switches/inverter", 1);
  541. var pos = inv_pos.getValue();
  542. var input = arg[0];
  543. if ( input == 1 ) {
  544. if ( pos == 0 ) {
  545. inv_pos.setIntValue(1);
  546. } elsif ( pos == 1 ) {
  547. inv_pos.setIntValue(2);
  548. }
  549. } else {
  550. if ( pos == 2 ) {
  551. inv_pos.setIntValue(1);
  552. } elsif ( pos == 1 ) {
  553. inv_pos.setIntValue(0);
  554. }
  555. }
  556. }
  557. # lighting controls
  558. # -----------------
  559. var nav_lights_switcher = func {
  560. var flash = props.globals.getNode("sim/model/A-10/controls/lighting/nav-lights-flash", 1);
  561. var s_pos = props.globals.getNode("sim/model/A-10/controls/lighting/nav-lights-switch", 1);
  562. var pos = s_pos.getValue();
  563. var input = arg[0];
  564. if ( input == 1 ) {
  565. if ( pos == 0 ) {
  566. s_pos.setIntValue(1);
  567. } elsif ( pos == 1 ) {
  568. s_pos.setIntValue(2);
  569. flash.setBoolValue(1);
  570. }
  571. } else {
  572. if ( pos == 2 ) {
  573. s_pos.setIntValue(1);
  574. flash.setBoolValue(0);
  575. } elsif ( pos == 1 ) {
  576. s_pos.setIntValue(0);
  577. }
  578. }
  579. }
  580. var land_lights_switcher = func {
  581. var s_pos = props.globals.getNode("sim/model/A-10/controls/lighting/land-lights-switch", 1);
  582. var pos = s_pos.getValue();
  583. var input = arg[0];
  584. if ( input == 1 ) {
  585. if ( pos == 0 ) {
  586. s_pos.setIntValue(1);
  587. } elsif ( pos == 1 ) {
  588. s_pos.setIntValue(2);
  589. }
  590. } else {
  591. if ( pos == 2 ) {
  592. s_pos.setIntValue(1);
  593. } elsif ( pos == 1 ) {
  594. s_pos.setIntValue(0);
  595. }
  596. }
  597. }