Make battery charge/discharge always, organize code
This commit is contained in:
parent
417cfcd528
commit
188afcf7c2
2 changed files with 70 additions and 96 deletions
|
@ -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>
|
||||||
|
|
|
@ -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 {
|
||||||
|
@ -280,61 +275,54 @@ var master_elec = func {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Battery Amps
|
# Battery Amps
|
||||||
if (battery1_sw) {
|
if (battery1_sw) {
|
||||||
setprop("/systems/electrical/battery1-amps", dc_amps_std);
|
setprop("/systems/electrical/battery1-amps", dc_amps_std);
|
||||||
} else {
|
} else {
|
||||||
setprop("/systems/electrical/battery1-amps", 0);
|
setprop("/systems/electrical/battery1-amps", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (battery2_sw) {
|
|
||||||
setprop("/systems/electrical/battery2-amps", dc_amps_std);
|
|
||||||
} else {
|
|
||||||
setprop("/systems/electrical/battery2-amps", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
# DC BAT logic
|
|
||||||
if ((dc1 > 0) or (dc2 > 0)) {
|
|
||||||
setprop("/systems/electrical/bus/dcbat", dc_volt_std);
|
|
||||||
} else {
|
|
||||||
setprop("/systems/electrical/bus/dcbat", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Battery Charge Limiter
|
|
||||||
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);
|
|
||||||
if (bat_chg) {
|
|
||||||
charge1.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (battery2_volts > 27.9 or (dcbat == 0)) {
|
|
||||||
setprop("/systems/electrical/extra/battery/bat2-contact", 0);
|
|
||||||
if (bat_chg) {
|
|
||||||
charge2.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Battery Charge Start
|
if (battery2_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/battery2-amps", dc_amps_std);
|
||||||
setprop("/systems/electrical/extra/battery/bat1-contact", 1);
|
} else {
|
||||||
decharge1.stop();
|
setprop("/systems/electrical/battery2-amps", 0);
|
||||||
charge1.start(); # I need to use a timer to avoid problems
|
}
|
||||||
}
|
|
||||||
|
if ((dc1 > 0) or (dc2 > 0)) {
|
||||||
if ((dcbat > 0) and battery2_sw and bat_chg) {
|
setprop("/systems/electrical/bus/dcbat", dc_volt_std);
|
||||||
setprop("/systems/electrical/extra/battery/bat2-contact", 1);
|
} else {
|
||||||
decharge1.stop();
|
setprop("/systems/electrical/bus/dcbat", 0);
|
||||||
charge2.start();
|
}
|
||||||
}
|
|
||||||
|
if (battery1_volts > 27.9 or (dcbat == 0)) {
|
||||||
|
setprop("/systems/electrical/extra/battery/bat1-contact", 0);
|
||||||
|
charge1.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (battery2_volts > 27.9 or (dcbat == 0)) {
|
||||||
|
setprop("/systems/electrical/extra/battery/bat2-contact", 0);
|
||||||
|
charge2.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((dcbat > 0) and battery1_sw) {
|
||||||
|
setprop("/systems/electrical/extra/battery/bat1-contact", 1);
|
||||||
|
decharge1.stop();
|
||||||
|
charge1.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((dcbat > 0) and battery2_sw) {
|
||||||
|
setprop("/systems/electrical/extra/battery/bat2-contact", 1);
|
||||||
|
decharge1.stop();
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getprop("/systems/electrical/bus/ac-ess") == 0) {
|
if (getprop("/systems/electrical/bus/ac-ess") == 0) {
|
||||||
setprop("systems/electrical/on", 0);
|
setprop("systems/electrical/on", 0);
|
||||||
|
@ -412,24 +400,24 @@ var update_electrical = func {
|
||||||
master_elec();
|
master_elec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##########
|
||||||
|
# Timers #
|
||||||
|
##########
|
||||||
|
|
||||||
var elec_timer = maketimer(0.2, update_electrical);
|
var elec_timer = maketimer(0.2, update_electrical);
|
||||||
|
var charge1 = maketimer(6, func {
|
||||||
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 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 bat2_volts = getprop("/systems/electrical/battery2-volts");
|
||||||
var charge2 = maketimer(6, func {
|
setprop("/systems/electrical/battery2-volts", bat2_volts + 0.1);
|
||||||
var bat2_volts = getprop("/systems/electrical/battery2-volts");
|
});
|
||||||
setprop("/systems/electrical/battery2-volts", bat2_volts + 0.1);
|
var decharge1 = maketimer(60, func {
|
||||||
});
|
var bat1_volts = getprop("/systems/electrical/battery1-volts");
|
||||||
|
setprop("/systems/electrical/battery1-volts", bat1_volts - 0.1);
|
||||||
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 decharge2 = maketimer(60, func {
|
||||||
setprop("/systems/electrical/battery1-volts", bat1_volts - 0.1);
|
var bat2_volts = getprop("/systems/electrical/battery2-volts");
|
||||||
});
|
setprop("/systems/electrical/battery2-volts", bat2_volts - 0.1);
|
||||||
|
});
|
||||||
var decharge2 = maketimer(60, func {
|
|
||||||
var bat2_volts = getprop("/systems/electrical/battery2-volts");
|
|
||||||
setprop("/systems/electrical/battery2-volts", bat2_volts - 0.1);
|
|
||||||
});
|
|
Reference in a new issue