Systems: Overhaul Battery Charging logic (again)
This commit is contained in:
parent
62af7daa67
commit
0c3aa121fa
2 changed files with 52 additions and 14 deletions
|
@ -1,6 +1,5 @@
|
|||
# A3XX Electrical System
|
||||
# Joshua Davidson (it0uchpods) and Jonathan Redpath (legoboyvdlp)
|
||||
# Some parts are in JSBsim system!
|
||||
|
||||
##############################################
|
||||
# Copyright (c) Joshua Davidson (it0uchpods) #
|
||||
|
@ -38,6 +37,10 @@ setlistener("/sim/signals/fdm-initialized", func {
|
|||
var battery2_volts = getprop("/systems/electrical/battery2-volts");
|
||||
var battery1_amps = getprop("/systems/electrical/battery1-amps");
|
||||
var battery2_amps = getprop("/systems/electrical/battery2-amps");
|
||||
var battery1_percent = getprop("/systems/electrical/battery1-percent");
|
||||
var battery2_percent = getprop("/systems/electrical/battery2-percent");
|
||||
var battery1_percent_calc = 0;
|
||||
var battery2_percent_calc = 0;
|
||||
var rpmapu = getprop("/systems/apu/rpm");
|
||||
var extpwr_on = getprop("/controls/switches/cart");
|
||||
var stateL = getprop("/engines/engine[0]/state");
|
||||
|
@ -158,6 +161,8 @@ var ELEC = {
|
|||
setprop("/systems/electrical/battery2-volts", 26.5);
|
||||
setprop("/systems/electrical/battery1-amps", 0);
|
||||
setprop("/systems/electrical/battery2-amps", 0);
|
||||
setprop("/systems/electrical/battery1-percent", 68);
|
||||
setprop("/systems/electrical/battery2-percent", 68);
|
||||
setprop("/systems/electrical/bus/dc1", 0);
|
||||
setprop("/systems/electrical/bus/dc2", 0);
|
||||
setprop("/systems/electrical/bus/dcbat", 0);
|
||||
|
@ -276,6 +281,8 @@ var ELEC = {
|
|||
battery2_sw = getprop("/controls/electrical/switches/battery2");
|
||||
battery1_volts = getprop("/systems/electrical/battery1-volts");
|
||||
battery2_volts = getprop("/systems/electrical/battery2-volts");
|
||||
battery1_percent = getprop("/systems/electrical/battery1-percent");
|
||||
battery2_percent = getprop("/systems/electrical/battery2-percent");
|
||||
rpmapu = getprop("/systems/apu/rpm");
|
||||
extpwr_on = getprop("/controls/switches/cart");
|
||||
stateL = getprop("/engines/engine[0]/state");
|
||||
|
@ -605,34 +612,65 @@ var ELEC = {
|
|||
dc1 = getprop("/systems/electrical/bus/dc1");
|
||||
dc2 = getprop("/systems/electrical/bus/dc2");
|
||||
|
||||
if (battery1_volts < 27.9 and (dc1 > 25 or dc2 > 25) and battery1_sw and !batt1_fail) {
|
||||
if (getprop("/systems/electrical/battery1-time") + 60 < getprop("/sim/time/elapsed-sec")) {
|
||||
setprop("/systems/electrical/battery1-volts", battery1_volts + 0.02877666); # Roughly 15mins to 25.9
|
||||
if (battery1_percent < 100 and (dc1 > 25 or dc2 > 25) and battery1_sw and !batt1_fail) {
|
||||
if (getprop("/systems/electrical/battery1-time") + 30 < getprop("/sim/time/elapsed-sec")) {
|
||||
battery1_percent_calc = battery1_percent + 4.5; # Roughly 90 percent every 10 mins
|
||||
if (battery1_percent_calc > 100) {
|
||||
battery1_percent_calc = 100;
|
||||
}
|
||||
setprop("/systems/electrical/battery1-percent", battery1_percent_calc);
|
||||
setprop("/systems/electrical/battery1-time", getprop("/sim/time/elapsed-sec"));
|
||||
}
|
||||
} else if (battery1_sw and !batt1_fail) {
|
||||
if (getprop("/systems/electrical/battery1-time") + 60 < getprop("/sim/time/elapsed-sec")) {
|
||||
setprop("/systems/electrical/battery1-volts", battery1_volts - 0.01438833); # Roughly 30mins from 25.9
|
||||
} else if (battery1_amps >= 120 and battery1_sw and !batt1_fail) {
|
||||
if (getprop("/systems/electrical/battery1-time") + 30 < getprop("/sim/time/elapsed-sec")) {
|
||||
battery1_percent_calc = battery1_percent - 1.5; # Roughly 90 percent every 30 mins
|
||||
if (battery1_percent_calc < 0) {
|
||||
battery1_percent_calc = 0;
|
||||
}
|
||||
setprop("/systems/electrical/battery1-percent", battery1_percent_calc);
|
||||
setprop("/systems/electrical/battery1-time", getprop("/sim/time/elapsed-sec"));
|
||||
}
|
||||
} else {
|
||||
setprop("/systems/electrical/battery1-time", getprop("/sim/time/elapsed-sec"));
|
||||
}
|
||||
|
||||
if (battery2_volts < 27.9 and (dc1 > 25 or dc2 > 25) and battery2_sw and !batt2_fail) {
|
||||
if (getprop("/systems/electrical/battery2-time") + 60 < getprop("/sim/time/elapsed-sec")) {
|
||||
setprop("/systems/electrical/battery2-volts", battery2_volts + 0.02877666); # Roughly 15mins to 25.9
|
||||
if (battery1_percent < 100 and (dc1 > 25 or dc2 > 25) and battery2_sw and !batt2_fail) {
|
||||
if (getprop("/systems/electrical/battery2-time") + 30 < getprop("/sim/time/elapsed-sec")) {
|
||||
battery2_percent_calc = battery2_percent + 4.5; # Roughly 90 percent every 10 mins
|
||||
if (battery2_percent_calc > 100) {
|
||||
battery2_percent_calc = 100;
|
||||
}
|
||||
setprop("/systems/electrical/battery2-percent", battery2_percent_calc);
|
||||
setprop("/systems/electrical/battery2-time", getprop("/sim/time/elapsed-sec"));
|
||||
}
|
||||
} else if (battery2_sw and !batt2_fail) {
|
||||
if (getprop("/systems/electrical/battery2-time") + 60 < getprop("/sim/time/elapsed-sec")) {
|
||||
setprop("/systems/electrical/battery2-volts", battery2_volts - 0.01438833); # Roughly 30mins from 25.9
|
||||
} else if (battery2_amps >= 120 and battery2_sw and !batt2_fail) {
|
||||
if (getprop("/systems/electrical/battery2-time") + 30 < getprop("/sim/time/elapsed-sec")) {
|
||||
battery2_percent_calc = battery2_percent - 1.5; # Roughly 90 percent every 30 mins
|
||||
if (battery2_percent_calc < 0) {
|
||||
battery2_percent_calc = 0;
|
||||
}
|
||||
setprop("/systems/electrical/battery2-percent", battery2_percent_calc);
|
||||
setprop("/systems/electrical/battery2-time", getprop("/sim/time/elapsed-sec"));
|
||||
}
|
||||
} else {
|
||||
setprop("/systems/electrical/battery2-time", getprop("/sim/time/elapsed-sec"));
|
||||
}
|
||||
|
||||
battery1_percent = getprop("/systems/electrical/battery1-percent");
|
||||
battery2_percent = getprop("/systems/electrical/battery2-percent");
|
||||
|
||||
if (battery1_percent >= 10) {
|
||||
setprop("/systems/electrical/battery1-volts", math.clamp(24 + (battery1_percent - 10) * (27.9 - 24) / (100 - 10), 24, 27.9));
|
||||
} else {
|
||||
setprop("/systems/electrical/battery1-volts", math.clamp(battery1_percent * (24) / (10), 0, 24));
|
||||
}
|
||||
|
||||
if (battery2_percent >= 10) {
|
||||
setprop("/systems/electrical/battery2-volts", math.clamp(24 + (battery2_percent - 10) * (27.9 - 24) / (100 - 10), 24, 30));
|
||||
} else {
|
||||
setprop("/systems/electrical/battery2-volts", math.clamp(battery2_percent * (24) / (10), 0, 24));
|
||||
}
|
||||
|
||||
if (getprop("/systems/electrical/bus/ac-ess") < 110) {
|
||||
if (getprop("/it-autoflight/output/ap1") == 1) {
|
||||
setprop("/it-autoflight/input/ap1", 0);
|
||||
|
|
|
@ -1 +1 @@
|
|||
4410
|
||||
4411
|
Reference in a new issue