fgukelectrical.nas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. ##
  2. # FGUK Electrical System in Nasal - Based on DH2 Electrial.
  3. ##
  4. # Initialize internal values
  5. #
  6. var battery = nil;
  7. var alternator = nil;
  8. var last_time = 0.0;
  9. var vbus_volts = 0.0;
  10. var main_bus_volts = 0.0;
  11. var essential_bus_volts = 0.0;
  12. var avionic_bus_1_volts = 0.0;
  13. var avionic_bus_2_volts = 0.0;
  14. var ammeter_ave = 0.0;
  15. ##
  16. # Initialize the electrical system
  17. #
  18. init_electrical = func {
  19. battery = BatteryClass.new();
  20. alternator = AlternatorClass.new();
  21. ###
  22. ### Initialise electrical stuff ###
  23. ### (move to electric system init once electrical system exists complete) ###
  24. ###
  25. props.globals.getNode("/systems/electrical/volts", 1).setDoubleValue(0.0);
  26. props.globals.getNode("/systems/electrical/amps", 1).setDoubleValue(0.0);
  27. props.globals.getNode("/systems/electrical/alternator", 1).setDoubleValue(0.0);
  28. props.globals.getNode("instrumentation/warning-panel/lovolt-norm", 1).setDoubleValue(0.0);
  29. props.globals.getNode("instrumentation/warning-panel/fuel-norm", 1).setDoubleValue(0.0);
  30. props.globals.getNode("controls/circuit-breakers/start-ctrl", 1).setBoolValue(1);
  31. props.globals.getNode("controls/circuit-breakers/start-ctrl", 1).setBoolValue(1);
  32. props.globals.getNode("controls/circuit-breakers/gen-ctrl", 1).setBoolValue(1);
  33. props.globals.getNode("controls/circuit-breakers/strobe-white", 1).setBoolValue(1);
  34. props.globals.getNode("controls/circuit-breakers/strobe-red", 1).setBoolValue(1);
  35. props.globals.getNode("controls/circuit-breakers/panel-lights", 1).setBoolValue(1);
  36. props.globals.getNode("controls/circuit-breakers/avionic-blower", 1).setBoolValue(1);
  37. props.globals.getNode("controls/circuit-breakers/pitot-heat", 1).setBoolValue(1);
  38. props.globals.getNode("controls/circuit-breakers/fuel-pump", 1).setBoolValue(1);
  39. props.globals.getNode("controls/circuit-breakers/eng-instr-2", 1).setBoolValue(1);
  40. props.globals.getNode("controls/circuit-breakers/gps", 1).setBoolValue(1);
  41. props.globals.getNode("controls/circuit-breakers/com2-nav2", 1).setBoolValue(1);
  42. props.globals.getNode("controls/circuit-breakers/avionic-bus-2", 1).setBoolValue(1);
  43. props.globals.getNode("controls/circuit-breakers/dme", 1).setBoolValue(1);
  44. props.globals.getNode("controls/circuit-breakers/audio-marker", 1).setBoolValue(1);
  45. props.globals.getNode("controls/circuit-breakers/att-indic-2", 1).setBoolValue(1);
  46. props.globals.getNode("controls/circuit-breakers/land-light", 1).setBoolValue(1);
  47. props.globals.getNode("controls/circuit-breakers/map-light", 1).setBoolValue(1);
  48. props.globals.getNode("controls/circuit-breakers/nav-lights", 1).setBoolValue(1);
  49. props.globals.getNode("controls/circuit-breakers/eng-instr-1", 1).setBoolValue(1);
  50. props.globals.getNode("controls/circuit-breakers/instr-lights", 1).setBoolValue(1);
  51. props.globals.getNode("controls/circuit-breakers/rpm-ind", 1).setBoolValue(1);
  52. props.globals.getNode("controls/circuit-breakers/lo-volt-warning", 1).setBoolValue(1);
  53. props.globals.getNode("controls/circuit-breakers/tands", 1).setBoolValue(1);
  54. props.globals.getNode("controls/circuit-breakers/fuel-lo-lev", 1).setBoolValue(1);
  55. props.globals.getNode("controls/circuit-breakers/att-indic-1", 1).setBoolValue(1);
  56. props.globals.getNode("controls/circuit-breakers/stall-warning", 1).setBoolValue(1);
  57. props.globals.getNode("controls/circuit-breakers/ess-bus", 1).setBoolValue(1);
  58. props.globals.getNode("controls/circuit-breakers/main-bus", 1).setBoolValue(1);
  59. props.globals.getNode("controls/circuit-breakers/gen", 1).setBoolValue(1);
  60. props.globals.getNode("controls/circuit-breakers/avionic-relay", 1).setBoolValue(1);
  61. props.globals.getNode("controls/circuit-breakers/flaps", 1).setBoolValue(1);
  62. props.globals.getNode("controls/circuit-breakers/mute", 1).setBoolValue(1);
  63. props.globals.getNode("controls/circuit-breakers/hsi", 1).setBoolValue(1);
  64. props.globals.getNode("controls/circuit-breakers/alt-encoder", 1).setBoolValue(1);
  65. props.globals.getNode("controls/circuit-breakers/transponder", 1).setBoolValue(1);
  66. props.globals.getNode("controls/circuit-breakers/nav1", 1).setBoolValue(1);
  67. props.globals.getNode("controls/circuit-breakers/com1", 1).setBoolValue(1);
  68. props.globals.getNode("controls/circuit-breakers/avionic-bus-1", 1).setBoolValue(1);
  69. props.globals.getNode("/controls/electric/battery-switch", 1).setBoolValue(0);
  70. props.globals.getNode("/controls/switches/avionic-master", 1).setBoolValue(0);
  71. props.globals.getNode("/controls/electric/engine/generator", 1).setBoolValue(0);
  72. props.globals.getNode("/controls/switches/landing-light", 1).setBoolValue(0);
  73. props.globals.getNode("/controls/switches/nav-lights", 1).setBoolValue(0);
  74. props.globals.getNode("/controls/switches/pitot-heat", 1).setBoolValue(0);
  75. props.globals.getNode("/controls/switches/strobes", 1).setIntValue(0);
  76. props.globals.getNode("/controls/anti-ice/engine/carb-heat", 1).setBoolValue(0);
  77. props.globals.getNode("/controls/switches/instr-lights", 1).setBoolValue(0);
  78. props.globals.getNode("/controls/lighting/instruments-dim", 1).setDoubleValue(0.0);
  79. props.globals.getNode("/controls/lighting/panel-dim", 1).setDoubleValue(0.0);
  80. props.globals.getNode("/controls/lighting/map-dim", 1).setDoubleValue(0.0);
  81. props.globals.getNode("/systems/electrical/outputs/start-ctrl", 1).setDoubleValue(0.0);
  82. props.globals.getNode("/systems/electrical/outputs/instrument-lights", 1).setDoubleValue(0.0);
  83. props.globals.getNode("/systems/electrical/outputs/lo-volt-warning", 1).setDoubleValue(0.0);
  84. props.globals.getNode("/systems/electrical/outputs/audio-marker", 1).setDoubleValue(0.0);
  85. print("Nasal Electrical System : initialised");
  86. props.globals.getNode("/sim/signals/electrical-initialized", 1).setBoolValue(0);
  87. # Request that the update fuction be called next frame
  88. settimer(update_electrical, 0);
  89. }
  90. BatteryClass = {};
  91. BatteryClass.new = func {
  92. obj = { parents : [BatteryClass],
  93. ideal_volts : 24.0,
  94. ideal_amps : 30.0,
  95. amp_hours : 12.75,
  96. charge_percent : 1.0,
  97. charge_amps : 7.0 };
  98. return obj;
  99. }
  100. BatteryClass.apply_load = func( amps, dt ) {
  101. amphrs_used = amps * dt / 3600.0;
  102. percent_used = amphrs_used / me.amp_hours;
  103. me.charge_percent -= percent_used;
  104. if ( me.charge_percent < 0.0 ) {
  105. me.charge_percent = 0.0;
  106. } elsif ( me.charge_percent > 1.0 ) {
  107. me.charge_percent = 1.0;
  108. }
  109. # print( "battery percent = ", me.charge_percent);
  110. return me.amp_hours * me.charge_percent;
  111. }
  112. BatteryClass.get_output_volts = func {
  113. x = 1.0 - me.charge_percent;
  114. tmp = -(3.0 * x - 1.0);
  115. factor = (tmp*tmp*tmp*tmp*tmp + 32) / 32;
  116. return me.ideal_volts * factor;
  117. }
  118. BatteryClass.get_output_amps = func {
  119. x = 1.0 - me.charge_percent;
  120. tmp = -(3.0 * x - 1.0);
  121. factor = (tmp*tmp*tmp*tmp*tmp + 32) / 32;
  122. return me.ideal_amps * factor;
  123. }
  124. AlternatorClass = {};
  125. AlternatorClass.new = func {
  126. obj = { parents : [AlternatorClass],
  127. rpm_source : "/engines/engine[0]/rpm",
  128. rpm_threshold : 600.0,
  129. ideal_volts : 28.0,
  130. ideal_amps : 60.0 };
  131. setprop( obj.rpm_source, 0.0 );
  132. return obj;
  133. }
  134. AlternatorClass.apply_load = func( amps, dt ) {
  135. # Scale alternator output for rpms < 600. For rpms >= 600
  136. # give full output. This is just a WAG, and probably not how
  137. # it really works but I'm keeping things "simple" to start.
  138. rpm = getprop( me.rpm_source );
  139. factor = rpm / me.rpm_threshold;
  140. if ( factor > 1.0 ) {
  141. factor = 1.0;
  142. }
  143. # print( "alternator amps = ", me.ideal_amps * factor );
  144. available_amps = me.ideal_amps * factor;
  145. return available_amps - amps;
  146. }
  147. AlternatorClass.get_output_volts = func {
  148. # scale alternator output for rpms < 600. For rpms >= 600
  149. # give full output. This is just a WAG, and probably not how
  150. # it really works but I'm keeping things "simple" to start.
  151. rpm = getprop( me.rpm_source );
  152. factor = rpm / me.rpm_threshold;
  153. if ( factor > 1.0 ) {
  154. factor = 1.0;
  155. }
  156. # print( "alternator volts = ", me.ideal_volts * factor );
  157. return me.ideal_volts * factor;
  158. }
  159. AlternatorClass.get_output_amps = func {
  160. # scale alternator output for rpms < 600. For rpms >= 600
  161. # give full output. This is just a WAG, and probably not how
  162. # it really works but I'm keeping things "simple" to start.
  163. rpm = getprop( me.rpm_source );
  164. factor = rpm / me.rpm_threshold;
  165. if ( factor > 1.0 ) {
  166. factor = 1.0;
  167. }
  168. # print( "alternator amps = ", ideal_amps * factor );
  169. return me.ideal_amps * factor;
  170. }
  171. update_electrical = func {
  172. time = getprop("/sim/time/elapsed-sec");
  173. dt = time - last_time;
  174. last_time = time;
  175. update_virtual_bus( dt );
  176. # Request that the update fuction be called again next frame
  177. settimer(update_electrical, 0);
  178. }
  179. update_virtual_bus = func( dt ) {
  180. battery_volts = battery.get_output_volts();
  181. alternator_volts = alternator.get_output_volts();
  182. external_volts = 0.0;
  183. load = 0.0;
  184. # switch state
  185. master_alt = getprop("/controls/switches/generator");
  186. # determine power source
  187. bus_volts = 0.0;
  188. power_source = "none";
  189. if ( getprop("/controls/electric/battery-switch") ) {
  190. bus_volts = battery_volts;
  191. power_source = "battery";
  192. }
  193. if ( getprop("/controls/switches/generator") and
  194. getprop("/controls/circuit-breakers/gen") and
  195. (alternator_volts > bus_volts) ) {
  196. bus_volts = alternator_volts;
  197. power_source = "alternator";
  198. }
  199. if ( external_volts > bus_volts ) {
  200. bus_volts = external_volts;
  201. power_source = "external";
  202. }
  203. # print( "virtual bus volts = ", bus_volts );
  204. # starter
  205. if (getprop("/systems/electrical/outputs/start-ctrl") > 16 ) {
  206. setprop("/systems/electrical/outputs/starter[0]", bus_volts);
  207. if (getprop("/controls/switches/starter")==1) {
  208. load += 10.0;
  209. }
  210. } else {
  211. setprop("/systems/electrical/outputs/starter[0]", 0.0);
  212. }
  213. # flaps
  214. if ( getprop("/controls/circuit-breakers/flaps") ) {
  215. setprop("/systems/electrical/outputs/flaps", bus_volts);
  216. } else {
  217. setprop("/systems/electrical/outputs/flaps", 0.0);
  218. }
  219. # bus network (1. these must be called in the right order, 2. the
  220. # bus routine itself determins where it draws power from.)
  221. load += main_bus();
  222. load += essential_bus();
  223. load += avionic_bus_1();
  224. load += avionic_bus_2();
  225. # system loads and ammeter gauge
  226. ammeter = 0.0;
  227. if ( bus_volts > 1.0 ) {
  228. # ammeter gauge
  229. if ( power_source == "battery" ) {
  230. ammeter = -load;
  231. } else {
  232. ammeter = battery.charge_amps;
  233. }
  234. }
  235. # print( "ammeter = ", ammeter );
  236. # charge/discharge the battery
  237. if ( power_source == "battery" ) {
  238. battery.apply_load( load, dt );
  239. } elsif ( bus_volts > battery_volts ) {
  240. battery.apply_load( -battery.charge_amps, dt );
  241. }
  242. # filter ammeter needle pos
  243. ammeter_ave = 0.8 * ammeter_ave + 0.2 * ammeter;
  244. # outputs
  245. setprop("/systems/electrical/amps", ammeter_ave);
  246. setprop("/systems/electrical/volts", bus_volts);
  247. setprop("/systems/electrical/alternator", alternator_volts);
  248. vbus_volts = bus_volts;
  249. return load;
  250. }
  251. main_bus = func() {
  252. # fed from the "virtual" bus via the main bus breaker (30A)
  253. if ( getprop("/controls/circuit-breakers/main-bus") ) {
  254. main_bus_volts = vbus_volts;
  255. } else {
  256. main_bus_volts = 0.0;
  257. }
  258. load = 0.0;
  259. # Start Ctrl (7.5A)
  260. if ( getprop("/controls/circuit-breakers/start-ctrl") ) {
  261. setprop("/systems/electrical/outputs/start-ctrl", main_bus_volts);
  262. load += 0.5;
  263. } else {
  264. setprop("/systems/electrical/outputs/start-ctrl", 0.0);
  265. }
  266. # Gen Ctrl (3A)
  267. if ( getprop("/controls/circuit-breakers/gen-ctrl") ) {
  268. setprop("/systems/electrical/outputs/gen-ctrl", main_bus_volts);
  269. load += 0.25;
  270. } else {
  271. setprop("/systems/electrical/outputs/gen-ctrl", 0.0);
  272. }
  273. # White Strobe (10A)
  274. var strobeswitch=getprop("/controls/switches/strobes");
  275. if ( getprop("/controls/circuit-breakers/strobe-white") and
  276. strobeswitch==1 ) {
  277. setprop("/systems/electrical/outputs/white-strobe", main_bus_volts);
  278. load += 6.0;
  279. } else {
  280. setprop("/systems/electrical/outputs/white-strobe", 0.0);
  281. }
  282. # Red Strobe (7.5A)
  283. if ( getprop("/controls/circuit-breakers/strobe-red") and
  284. strobeswitch==-1 ) {
  285. setprop("/systems/electrical/outputs/red-strobe", main_bus_volts);
  286. load += 3;
  287. } else {
  288. setprop("/systems/electrical/outputs/red-strobe", 0.0);
  289. }
  290. # Panel Lights (5A)
  291. if ( getprop("/controls/circuit-breakers/panel-lights") ) {
  292. setprop("/systems/electrical/outputs/panel-lights", main_bus_volts);
  293. setprop("/controls/lighting/panel-norm", getprop("/systems/electrical/outputs/panel-lights") * getprop("/controls/lighting/panel-dim") * 0.041666);
  294. load += 0.7*getprop("/controls/lighting/panel-dim");
  295. } else {
  296. setprop("/systems/electrical/outputs/panel-lights", 0.0);
  297. setprop("/controls/lighting/panel-norm", 0.0);
  298. }
  299. # Avionic Blower (1A)
  300. if ( getprop("/controls/circuit-breakers/avionic-blower") ) {
  301. setprop("/systems/electrical/outputs/avionic-blower", main_bus_volts);
  302. load += 0.45;
  303. } else {
  304. setprop("/systems/electrical/outputs/avionic-blower", 0.0);
  305. }
  306. # Pitot Heat (7.5A)
  307. if ( getprop("/controls/circuit-breakers/pitot-heat") and
  308. getprop("/controls/switches/pitot-heat") ) {
  309. setprop("/systems/electrical/outputs/pitot-heat", main_bus_volts);
  310. load += 2.5;
  311. } else {
  312. setprop("/systems/electrical/outputs/pitot-heat", 0.0);
  313. }
  314. # Fuel Pump (5A)
  315. if ( getprop("/controls/circuit-breakers/fuel-pump") and
  316. getprop("/controls/engines/engine/fuel-pump") ) {
  317. setprop("/systems/electrical/outputs/fuel-pump", main_bus_volts);
  318. load += 3;
  319. } else {
  320. setprop("/systems/electrical/outputs/fuel-pump", 0.0);
  321. }
  322. # Eng Instr 2 (3A)
  323. if ( getprop("/controls/circuit-breakers/eng-instr-2") ) {
  324. setprop("/systems/electrical/outputs/eng-instr-2", main_bus_volts);
  325. load += 0.12;
  326. } else {
  327. setprop("/systems/electrical/outputs/eng-instr-2", 0.0);
  328. }
  329. # pop breaker if over current
  330. if ( load>30.0 ) {
  331. setprop("/controls/circuit-breakers/main-bus",0);
  332. }
  333. # return cumulative load
  334. if ( getprop("/controls/circuit-breakers/main-bus") ) {
  335. setprop("/systems/electrical/debug/main-load", load);
  336. setprop("/systems/electrical/debug/main-volts", main_bus_volts);
  337. return load;
  338. } else {
  339. return 0.0;
  340. }
  341. }
  342. essential_bus = func() {
  343. # fed from the "virtual" bus via the ess bus breaker (15A)
  344. if ( getprop("/controls/circuit-breakers/ess-bus") ) {
  345. essential_bus_volts = vbus_volts;
  346. } else {
  347. essential_bus_volts = 0.0;
  348. }
  349. load = 0.0;
  350. # Landing Light (7.5A)
  351. if ( getprop("/controls/circuit-breakers/land-light") ) {
  352. setprop("/systems/electrical/outputs/land-light", essential_bus_volts);
  353. load += 3.5;
  354. } else {
  355. setprop("/systems/electrical/outputs/land-light", 0.0);
  356. }
  357. # Map Light (5A)
  358. if ( getprop("/controls/circuit-breakers/map-light") ) {
  359. setprop("/systems/electrical/outputs/map-light", essential_bus_volts);
  360. setprop("/controls/lighting/map-norm", essential_bus_volts * getprop("/controls/lighting/instruments-dim") * 0.041666);
  361. load += 0.3*getprop("/controls/lighting/map-dim");
  362. } else {
  363. setprop("/systems/electrical/outputs/map-light", 0.0);
  364. }
  365. # Nav Lights (7.5A)
  366. if ( getprop("/controls/circuit-breakers/nav-lights") and
  367. getprop("/controls/switches/nav-lights") ) {
  368. setprop("/systems/electrical/outputs/nav-lights", essential_bus_volts);
  369. setprop("/controls/lighting/nav-lights-norm", getprop("/systems/electrical/outputs/nav-lights") * 0.041666);
  370. load += 4.0;
  371. } else {
  372. setprop("/systems/electrical/outputs/nav-lights", 0.0);
  373. setprop("/controls/lighting/nav-lights-norm", 0.0);
  374. }
  375. # Eng Instr 1 (3A)
  376. if ( getprop("/controls/circuit-breakers/eng-instr-1") ) {
  377. setprop("/systems/electrical/outputs/eng-instr-1", essential_bus_volts);
  378. load += 0.05;
  379. } else {
  380. setprop("/systems/electrical/outputs/eng-instr-1", 0.0);
  381. }
  382. # Instr Lights (5A)
  383. if ( getprop("/controls/circuit-breakers/instr-lights") and
  384. getprop("/controls/switches/instr-lights") ) {
  385. setprop("/systems/electrical/outputs/instr-lights", essential_bus_volts);
  386. setprop("/controls/lighting/instruments-norm", getprop("/systems/electrical/outputs/instr-lights") * getprop("/controls/lighting/instruments-dim") * 0.041666);
  387. load += 1*getprop("/controls/lighting/instruments-dim");
  388. } else {
  389. setprop("/systems/electrical/outputs/instr-lights", 0.0);
  390. setprop("/controls/lighting/instruments-norm", 0.0);
  391. }
  392. # RPM Ind (3A)
  393. if ( getprop("/controls/circuit-breakers/rpm-ind") ) {
  394. setprop("/systems/electrical/outputs/rpm-ind", essential_bus_volts);
  395. load += 0.04;
  396. } else {
  397. setprop("/systems/electrical/outputs/rpm-ind", 0.0);
  398. }
  399. # Lo Volt Warning (3A)
  400. if ( getprop("/controls/circuit-breakers/lo-volt-warning") ) {
  401. setprop("/systems/electrical/outputs/lo-volt-warning", essential_bus_volts);
  402. } else {
  403. setprop("/systems/electrical/outputs/lo-volt-warning", 0.0);
  404. }
  405. if ( getprop("/instrumentation/warning-panel/lovolt-norm") > 0 ) {
  406. load += 0.02;
  407. }
  408. # T&S (5A)
  409. if ( getprop("/controls/circuit-breakers/tands") ) {
  410. setprop("/systems/electrical/outputs/turn-coordinator", essential_bus_volts);
  411. load += 0.3;
  412. } else {
  413. setprop("/systems/electrical/outputs/turn-coordinator", 0.0);
  414. }
  415. # Fuel Lo Lev (0.5A)
  416. if ( getprop("/controls/circuit-breakers/fuel-lo-lev") ) {
  417. setprop("/systems/electrical/outputs/fuel-lo-lev", essential_bus_volts);
  418. } else {
  419. setprop("/systems/electrical/outputs/fuel-lo-lev", 0.0);
  420. }
  421. if ( getprop("/instrumentation/warning-panel/fuel-norm") > 0 ) {
  422. load += 0.02;
  423. }
  424. # Att Indic 1 (3A)
  425. if ( getprop("/controls/circuit-breakers/att-indic-1") ) {
  426. setprop("/systems/electrical/outputs/att-indic-1", essential_bus_volts);
  427. load += 0.6;
  428. } else {
  429. setprop("/systems/electrical/outputs/att-indic-1", 0.0);
  430. }
  431. # pop breaker if over current
  432. if ( load>15.0 ) {
  433. setprop("/controls/circuit-breakers/ess-bus",0);
  434. }
  435. # return cumulative load
  436. if ( getprop("/controls/circuit-breakers/ess-bus") ) {
  437. setprop("/systems/electrical/debug/ess-load", load);
  438. setprop("/systems/electrical/debug/ess-volts", main_bus_volts);
  439. return load;
  440. } else {
  441. setprop("/systems/electrical/debug/ess-load", 0);
  442. setprop("/systems/electrical/debug/ess-volts", 0);
  443. return 0.0;
  444. };
  445. }
  446. avionic_bus_1 = func() {
  447. # fed from the "virtual" bus via the avionic bus 1 breaker (15A)
  448. if ( getprop("/controls/circuit-breakers/avionic-bus-1") ) {
  449. avionic_bus_1_volts = vbus_volts;
  450. } else {
  451. main_bus_volts = 0.0;
  452. }
  453. load = 0.0;
  454. # Mute (3A)
  455. if ( getprop("/controls/circuit-breakers/mute") ) {
  456. setprop("/systems/electrical/outputs/mute", avionic_bus_1_volts);
  457. } else {
  458. setprop("/systems/electrical/outputs/mute", 0.0);
  459. }
  460. # HSI (3A)
  461. if ( getprop("/controls/circuit-breakers/hsi") ) {
  462. setprop("/systems/electrical/outputs/hsi", avionic_bus_1_volts / 2);
  463. load += 1.5;
  464. } else {
  465. setprop("/systems/electrical/outputs/hsi", 0.0);
  466. }
  467. # Alt Encoder (1A)
  468. if ( getprop("/controls/circuit-breakers/alt-encoder") ) {
  469. setprop("/systems/electrical/outputs/alt-encoder", avionic_bus_1_volts);
  470. load += 1.2;
  471. } else {
  472. setprop("/systems/electrical/outputs/alt-encoder", 0.0);
  473. }
  474. # Xpdr (3A)
  475. if ( getprop("/controls/circuit-breakers/xpdr") ) {
  476. setprop("/systems/electrical/outputs/xpdr", avionic_bus_1_volts);
  477. load += 0.1;
  478. } else {
  479. setprop("/systems/electrical/outputs/xpdr", 0.0);
  480. }
  481. # Nav1 (3A)
  482. if ( getprop("/controls/circuit-breakers/nav1") ) {
  483. setprop("/systems/electrical/outputs/nav1", avionic_bus_1_volts);
  484. load += 0.35;
  485. } else {
  486. setprop("/systems/electrical/outputs/nav1", 0.0);
  487. }
  488. # Com1 (10A)
  489. if ( getprop("/controls/circuit-breakers/com1") ) {
  490. setprop("/systems/electrical/outputs/com1", avionic_bus_1_volts);
  491. # Rx 0.6A
  492. # Tx 8A
  493. load += 0.6;
  494. } else {
  495. setprop("/systems/electrical/outputs/com1", 0.0);
  496. }
  497. # pop breaker if over current
  498. if ( load>15.0 ) {
  499. setprop("/controls/circuit-breakers/avionic-bus-1",0);
  500. }
  501. # return cumulative load
  502. if ( getprop("/controls/circuit-breakers/avionic-bus-1") ) {
  503. setprop("/systems/electrical/debug/ab1-load", load);
  504. setprop("/systems/electrical/debug/ab1-volts", avionic_bus_1_volts);
  505. return load;
  506. } else {
  507. setprop("/systems/electrical/debug/ab1-load", 0);
  508. setprop("/systems/electrical/debug/ab1-volts", 0);
  509. return 0.0;
  510. };
  511. }
  512. avionic_bus_2 = func() {
  513. # fed from the "virtual" bus via the avionic bus 2 breaker (15A)
  514. if ( getprop("/controls/circuit-breakers/avionic-bus-2") ) {
  515. avionic_bus_2_volts = vbus_volts;
  516. } else {
  517. avionic_bus_2_volts = 0.0;
  518. }
  519. load = 0.0;
  520. # GPS (3A)
  521. if ( getprop("/controls/circuit-breakers/gps") ) {
  522. setprop("/systems/electrical/outputs/gps", avionic_bus_2_volts);
  523. load +=1;
  524. } else {
  525. setprop("/systems/electrical/outputs/gps", 0.0);
  526. }
  527. # Com2/Nav2 (10A)
  528. if ( getprop("/controls/circuit-breakers/com2nav2") ) {
  529. setprop("/systems/electrical/outputs/com2nav2", avionic_bus_2_volts);
  530. # Rx 0.6A
  531. # Tx 6A
  532. load += 0.6;
  533. } else {
  534. setprop("/systems/electrical/outputs/com2nav2", 0.0);
  535. }
  536. # DME (3A)
  537. if ( getprop("/controls/circuit-breakers/dme") ) {
  538. setprop("/systems/electrical/outputs/dme", avionic_bus_2_volts);
  539. load += 0.55;
  540. } else {
  541. setprop("/systems/electrical/outputs/dme", 0.0);
  542. }
  543. # Audio Marker (3A)
  544. if ( getprop("/controls/circuit-breakers/audio-marker") ) {
  545. setprop("/systems/electrical/outputs/audio-marker", avionic_bus_2_volts);
  546. # Keep Instrumentation/marker_beacon.cxx happy
  547. setprop("/systems/electrical/outputs/nav", avionic_bus_2_volts);
  548. load += 0.5;
  549. } else {
  550. setprop("/systems/electrical/outputs/audio-marker", 0.0);
  551. }
  552. # Att Indic 2 (3A)
  553. if ( getprop("/controls/circuit-breakers/att-indic-2") ) {
  554. setprop("/systems/electrical/outputs/att-indic-2", avionic_bus_2_volts);
  555. load += 1;
  556. } else {
  557. setprop("/systems/electrical/outputs/att-indic-2", 0.0);
  558. }
  559. # pop breaker if over current
  560. if ( load>15.0 ) {
  561. setprop("/controls/circuit-breakers/avionic-bus-2",0);
  562. }
  563. # return cumulative load
  564. if ( getprop("/controls/circuit-breakers/avionic-bus-2") ) {
  565. setprop("/systems/electrical/debug/ab1-load", load);
  566. setprop("/systems/electrical/debug/ab1-volts", avionic_bus_2_volts);
  567. return load;
  568. } else {
  569. setprop("/systems/electrical/debug/ab1-load", 0);
  570. setprop("/systems/electrical/debug/ab1-volts", 0);
  571. return 0.0;
  572. };
  573. }
  574. # Setup a timer based call to initialized the electrical system as
  575. # soon as possible.
  576. setlistener("/sim/signals/fdm-initialized",init_electrical);