Make battery charge/discharge always, organize code

This commit is contained in:
Joshua Davidson 2017-05-11 17:26:31 -04:00
parent 417cfcd528
commit 188afcf7c2
2 changed files with 70 additions and 96 deletions

View file

@ -198,7 +198,7 @@
</binding> </binding>
</button> </button>
<!--<checkbox> <checkbox>
<label>Enable Baggage Ramp</label> <label>Enable Baggage Ramp</label>
<halign>left</halign> <halign>left</halign>
<enable> <enable>
@ -209,7 +209,7 @@
<command>dialog-apply</command> <command>dialog-apply</command>
</binding> </binding>
<live>true</live> <live>true</live>
</checkbox>--> </checkbox>
<checkbox> <checkbox>
<label>Enable External Power Box</label> <label>Enable External Power Box</label>
@ -255,20 +255,6 @@
<live>true</live> <live>true</live>
</checkbox> </checkbox>
<checkbox>
<label>Enable Battery Charging</label>
<halign>left</halign>
<property>/systems/electrical/batchgenabled</property>
<binding>
<command>property-toggle</command>
<property>/systems/electrical/batchgenabled</property>
</binding>
<binding>
<command>dialog-apply</command>
</binding>
<live>true</live>
</checkbox>
<button> <button>
<legend>FBW Settings</legend> <legend>FBW Settings</legend>
<halign>center</halign> <halign>center</halign>

View file

@ -1,4 +1,4 @@
# Electrical system for A320 by Joshua Davidson (it0uchpods/411). # Electrical system for A320 by Joshua Davidson (it0uchpods) and Johnathan Redpath (legoboyvdlp).
############# #############
# Init Vars # # Init Vars #
@ -50,7 +50,6 @@ var elec_init = func {
setprop("/systems/electrical/extra/battery/bat2-contact", 0); setprop("/systems/electrical/extra/battery/bat2-contact", 0);
setprop("/systems/electrical/gen-apu", 0); setprop("/systems/electrical/gen-apu", 0);
setprop("/systems/electrical/gen-ext", 0); setprop("/systems/electrical/gen-ext", 0);
setprop("/systems/electrical/batchgenabled", 0);
setprop("/systems/electrical/on", 0); setprop("/systems/electrical/on", 0);
setprop("/controls/electrical/xtie/xtieL", 0); setprop("/controls/electrical/xtie/xtieL", 0);
setprop("/controls/electrical/xtie/xtieR", 0); setprop("/controls/electrical/xtie/xtieR", 0);
@ -125,7 +124,6 @@ var master_elec = func {
var galley_shed = getprop("/systems/electrical/extra/galleyshed"); var galley_shed = getprop("/systems/electrical/extra/galleyshed");
var bat1_con = getprop("/systems/electrical/extra/battery/bat1-contact"); var bat1_con = getprop("/systems/electrical/extra/battery/bat1-contact");
var bat2_con = getprop("/systems/electrical/extra/battery/bat2-contact"); var bat2_con = getprop("/systems/electrical/extra/battery/bat2-contact");
var bat_chg = getprop("/systems/electrical/batchgenabled");
# Left cross tie yes? # Left cross tie yes?
@ -258,21 +256,18 @@ var master_elec = func {
setprop("/systems/electrical/bus/galley", 0); setprop("/systems/electrical/bus/galley", 0);
} }
# Galley Shedding Logic if (!gen_apu and !gen_ext_sw and (!gen1_sw or !gen2_sw)) {
if (!gen_apu and !gen_ext_sw and (!gen1_sw or !gen2_sw)) { # this is when one of the generators is not working or turned off as it reads 0 V
setprop("/systems/electrical/extra/galleyshed", 1); setprop("/systems/electrical/extra/galleyshed", 1);
} else { } else {
setprop("/systems/electrical/extra/galleyshed", 0); setprop("/systems/electrical/extra/galleyshed", 0);
} }
# APU Generator: Make it only come online when the apu is running. This is needed to make galley shed work properly.
if (rpmapu >= 94.9 and gen_apu_sw) { if (rpmapu >= 94.9 and gen_apu_sw) {
setprop("/systems/electrical/gen-apu", 1); setprop("/systems/electrical/gen-apu", 1);
} else { } else {
setprop("/systems/electrical/gen-apu", 0); setprop("/systems/electrical/gen-apu", 0);
} }
# Make EXT PWR only come online when connected and turned on to make ECAM work properly
if (extpwr_on and gen_ext_sw) { if (extpwr_on and gen_ext_sw) {
setprop("/systems/electrical/gen-ext", 1); setprop("/systems/electrical/gen-ext", 1);
} else { } else {
@ -292,47 +287,40 @@ var master_elec = func {
setprop("/systems/electrical/battery2-amps", 0); setprop("/systems/electrical/battery2-amps", 0);
} }
# DC BAT logic
if ((dc1 > 0) or (dc2 > 0)) { if ((dc1 > 0) or (dc2 > 0)) {
setprop("/systems/electrical/bus/dcbat", dc_volt_std); setprop("/systems/electrical/bus/dcbat", dc_volt_std);
} else { } else {
setprop("/systems/electrical/bus/dcbat", 0); setprop("/systems/electrical/bus/dcbat", 0);
} }
# Battery Charge Limiter if (battery1_volts > 27.9 or (dcbat == 0)) {
if (battery1_volts > 27.9 or (dcbat == 0)) { # above 27.9 volts close contact to stop charge at 28 or else stop if the dcbat is unpowered
setprop("/systems/electrical/extra/battery/bat1-contact", 0); setprop("/systems/electrical/extra/battery/bat1-contact", 0);
if (bat_chg) {
charge1.stop(); charge1.stop();
} }
}
if (battery2_volts > 27.9 or (dcbat == 0)) { if (battery2_volts > 27.9 or (dcbat == 0)) {
setprop("/systems/electrical/extra/battery/bat2-contact", 0); setprop("/systems/electrical/extra/battery/bat2-contact", 0);
if (bat_chg) {
charge2.stop(); charge2.stop();
} }
}
# Battery Charge Start if ((dcbat > 0) and battery1_sw) {
if ((dcbat > 0) and battery1_sw and bat_chg) { # pen contact to begin charge as long as DC BAT is powered unless at 28V
setprop("/systems/electrical/extra/battery/bat1-contact", 1); setprop("/systems/electrical/extra/battery/bat1-contact", 1);
decharge1.stop(); decharge1.stop();
charge1.start(); # I need to use a timer to avoid problems charge1.start();
} }
if ((dcbat > 0) and battery2_sw and bat_chg) { if ((dcbat > 0) and battery2_sw) {
setprop("/systems/electrical/extra/battery/bat2-contact", 1); setprop("/systems/electrical/extra/battery/bat2-contact", 1);
decharge1.stop(); decharge1.stop();
charge2.start(); charge2.start();
} }
# Battery Decharge
if (!bat1_con and (dcbat == 0) and battery1_sw and bat_chg) { # No supply to DC BAT to charge, so DC is not powered, meaning batteries only. Therefore the battery begins to decharge if (!bat1_con and (dcbat == 0) and battery1_sw) {
decharge1.start(); decharge1.start();
} }
if (!bat2_con and (dcbat == 0) and battery2_sw and bat_chg) { if (!bat2_con and (dcbat == 0) and battery2_sw) {
decharge2.start(); decharge2.start();
} }
@ -412,24 +400,24 @@ var update_electrical = func {
master_elec(); master_elec();
} }
var elec_timer = maketimer(0.2, update_electrical); ##########
# Timers #
##########
var charge1 = maketimer(6, func { # I know 1 volt per minute is really slow but it is fast compared to real aircraft and I can add a reset function var elec_timer = maketimer(0.2, update_electrical);
var charge1 = maketimer(6, func {
var bat1_volts = getprop("/systems/electrical/battery1-volts"); var bat1_volts = getprop("/systems/electrical/battery1-volts");
setprop("/systems/electrical/battery1-volts", bat1_volts + 0.1); setprop("/systems/electrical/battery1-volts", bat1_volts + 0.1);
}); });
var charge2 = maketimer(6, func {
var charge2 = maketimer(6, func {
var bat2_volts = getprop("/systems/electrical/battery2-volts"); var bat2_volts = getprop("/systems/electrical/battery2-volts");
setprop("/systems/electrical/battery2-volts", bat2_volts + 0.1); setprop("/systems/electrical/battery2-volts", bat2_volts + 0.1);
}); });
var decharge1 = maketimer(60, func {
var decharge1 = maketimer(60, func { # allow about 20 min of flight to 25.9 volts this is until I know what voltage a320 powers down
var bat1_volts = getprop("/systems/electrical/battery1-volts"); var bat1_volts = getprop("/systems/electrical/battery1-volts");
setprop("/systems/electrical/battery1-volts", bat1_volts - 0.1); setprop("/systems/electrical/battery1-volts", bat1_volts - 0.1);
}); });
var decharge2 = maketimer(60, func {
var decharge2 = maketimer(60, func {
var bat2_volts = getprop("/systems/electrical/battery2-volts"); var bat2_volts = getprop("/systems/electrical/battery2-volts");
setprop("/systems/electrical/battery2-volts", bat2_volts - 0.1); setprop("/systems/electrical/battery2-volts", bat2_volts - 0.1);
}); });