2020-07-25 23:13:54 +00:00
# A3XX Autobrake and Braking
# Joshua Davidson (Octal450)
# Copyright (c) 2020 Josh Davidson (Octal450)
2019-12-02 18:25:19 +00:00
##########################################################################
# Simple Brake Simulation System
# 2010, Thorsten Brehm
#
# Simple simulation of brake energy absorption and cooling effects.
#
# This module computes (approximates... :-) ) an energy level which
# (faintly) resembles the kinetic energy absorption and cooling effects
# of a brake system. But instead of computing real temperatures, this
# is just meant to distinguish normal energy levels from exceptionally
# high levels. The target is to drive EICAS "brakes overheat" messages
# and gear effects only, to "reward" pilots with exceptionally bad
2020-02-02 20:40:05 +00:00
# landings...
2019-12-02 18:25:19 +00:00
#
# To avoid complicated calculations of different braking effects (roll/air
# drag, reverse thrust etc), we simply assume the brake system to cause a
# fixed deceleration (me.BrakeDecel). With this deceleration we approximate
# the speed difference which would be caused by the brake system alone for
# any given simulation interval. The difference of the kinetic energy level
# at the current speed and the decelerated speed are then added up to the
# total absorbed brake energy.
# Units (knots/lbs/Kg) do not matter much here. Eventually a magic scaling
# divisor is used to scale the output level. Any output > 1 means
# "overheated brakes", any level <=1 means "brake temperature OK".
# No exact science here - but good enough for now :-).
##########################################################################
2020-01-27 18:01:33 +00:00
#
# Added brakes temp calculations and adapted for A320-family
# 2020, Andrea Vezzali
#
##########################################################################
2019-12-02 18:25:19 +00:00
var BrakeSystem =
{
2020-02-02 20:40:05 +00:00
new : func()
{
var m = { parents : [BrakeSystem]};
# deceleration caused by brakes alone (knots/s2)
m.BrakeDecel = 1.0; # kt/s^2
# Higher value means quicker cooling
2020-02-02 21:02:30 +00:00
m.CoolingFactor = 0.000125;
2020-02-02 20:40:05 +00:00
# Scaling divisor. Use this to scale the energy output.
# Manually tune this value: a total energy output
# at "/gear/brake-thermal-energy" > 1.0 means overheated brakes,
# anything below <= 1.0 means energy absorbed by brakes is OK.
#m.ScalingDivisor= 700000*450.0;
2020-01-08 22:39:10 +00:00
2020-02-02 20:40:05 +00:00
m.ScalingDivisor = 0.000000006;
m.LSmokeActive = 0;
m.LSmokeToggle = 0;
m.RSmokeActive = 0;
m.RSmokeToggle = 0;
# m.LnCoolFactor = math.ln(1-m.CoolingFactor);
2019-12-02 18:25:19 +00:00
2020-02-02 20:40:05 +00:00
m.reset();
2019-12-02 18:25:19 +00:00
2020-02-02 20:40:05 +00:00
return m;
},
2019-12-02 18:25:19 +00:00
2020-02-02 20:40:05 +00:00
reset : func()
{
# Initial thermal energy
setprop("gear/gear[1]/Lbrake-thermal-energy",0.0);
setprop("gear/gear[2]/Rbrake-thermal-energy",0.0);
2020-01-27 18:01:33 +00:00
2020-07-25 23:13:54 +00:00
setprop("/controls/gear/brake-fans",0);
2020-02-02 20:40:05 +00:00
setprop("gear/gear[1]/Lbrake-smoke",0);
setprop("gear/gear[2]/Rbrake-smoke",0);
setprop("gear/gear[1]/L-Thrust",0);
setprop("gear/gear[2]/R-Thrust",0);
2020-01-27 18:01:33 +00:00
#Introducing a random error on temp sensors (max 5°C)
2020-03-17 23:10:29 +00:00
setprop("gear/gear[1]/L1error-temp-degc", math.round(rand()*(5)));
setprop("gear/gear[1]/L2error-temp-degc", math.round(rand()*(5)));
setprop("gear/gear[2]/R3error-temp-degc", math.round(rand()*(5)));
setprop("gear/gear[2]/R4error-temp-degc", math.round(rand()*(5)));
2020-01-27 18:01:33 +00:00
2020-02-07 19:39:12 +00:00
#var atemp = getprop("environment/temperature-degc") or 0;
#var vmach = getprop("velocities/mach") or 0;
var tatdegc = getprop("/systems/navigation/probes/tat-1/compute-tat") or 0;
2020-02-02 20:40:05 +00:00
var atemp = getprop("environment/temperature-degc") or 0;
var vmach = getprop("velocities/mach") or 0;
2020-07-25 23:13:54 +00:00
var tatdegc = getprop("/systems/navigation/probes/tat-1/compute-tat");
2020-01-27 18:01:33 +00:00
2020-02-02 20:40:05 +00:00
setprop("gear/gear[1]/L1brake-temp-degc",tatdegc+getprop("gear/gear[1]/L1error-temp-degc"));
setprop("gear/gear[1]/L2brake-temp-degc",tatdegc+getprop("gear/gear[1]/L2error-temp-degc"));
setprop("gear/gear[2]/R3brake-temp-degc",tatdegc+getprop("gear/gear[2]/R3error-temp-degc"));
setprop("gear/gear[2]/R4brake-temp-degc",tatdegc+getprop("gear/gear[2]/R4error-temp-degc"));
2020-01-27 18:01:33 +00:00
2020-07-25 23:13:54 +00:00
setprop("/sim/animation/fire-services",0);
2020-02-02 20:40:05 +00:00
me.LastSimTime = 0.0;
},
2019-12-02 18:25:19 +00:00
2020-02-02 20:40:05 +00:00
# update brake energy
update : func()
{
2020-07-25 23:13:54 +00:00
var CurrentTime = getprop("/sim/time/elapsed-sec");
2020-02-02 20:40:05 +00:00
var dt = CurrentTime - me.LastSimTime;
var LThermalEnergy = getprop("gear/gear[1]/Lbrake-thermal-energy");
var RThermalEnergy = getprop("gear/gear[2]/Rbrake-thermal-energy");
2020-01-27 18:01:33 +00:00
var LBrakeLevel = getprop("fdm/jsbsim/fcs/left-brake-cmd-norm");
2020-02-02 20:40:05 +00:00
var RBrakeLevel = getprop("fdm/jsbsim/fcs/right-brake-cmd-norm");
2020-02-07 19:39:12 +00:00
#var atemp = getprop("environment/temperature-degc") or 0;
#var vmach = getprop("velocities/mach") or 0;
#var tatdegc = atemp * (1 + (0.2 * math.pow(vmach, 2)));
var tatdegc = getprop("/systems/navigation/probes/tat-1/compute-tat") or 0;
2020-01-27 18:01:33 +00:00
var L_thrust_lb = getprop("engines/engine[0]/thrust_lb");
var R_thrust_lb = getprop("engines/engine[1]/thrust_lb");
2019-12-02 18:25:19 +00:00
2020-07-25 23:13:54 +00:00
if (getprop("/sim/freeze/replay-state")==0 and dt<1.0) {
2020-02-02 20:40:05 +00:00
var OnGround = getprop("gear/gear[1]/wow");
2020-01-27 18:01:33 +00:00
#cooling effect: adjust cooling factor by a value proportional to the environment temp (m.CoolingFactor + environment temp-degc * 0.00001)
var LCoolingRatio = me.CoolingFactor+(tatdegc*0.000001);
var RCoolingRatio = me.CoolingFactor+(tatdegc*0.000001);
2020-07-25 23:13:54 +00:00
if (getprop("/controls/gear/brake-fans")) {
2020-02-02 20:40:05 +00:00
#increase CoolingRatio if Brake Fans are active
LCoolingRatio = LCoolingRatio * 3;
RCoolingRatio = RCoolingRatio * 3;
2020-04-26 07:59:12 +00:00
};
if (getprop("gear/gear[1]/position-norm")) {
2020-02-02 20:40:05 +00:00
#increase CoolingRatio if gear down according to airspeed
LCoolingRatio = LCoolingRatio * getprop("velocities/airspeed-kt");
2020-01-27 18:01:33 +00:00
} else {
2020-02-02 20:40:05 +00:00
#Reduced CoolingRatio if gear up
2020-01-27 18:01:33 +00:00
LCoolingRatio = LCoolingRatio * 0.1;
2020-04-26 07:59:12 +00:00
};
if (getprop("gear/gear[2]/position-norm")) {
2020-02-02 20:40:05 +00:00
#increase CoolingRatio if gear down according to airspeed
RCoolingRatio = RCoolingRatio * getprop("velocities/airspeed-kt");
2020-01-27 18:01:33 +00:00
} else {
2020-02-02 20:40:05 +00:00
#Reduced CoolingRatio if gear up
2020-01-27 18:01:33 +00:00
RCoolingRatio = RCoolingRatio * 0.1;
2020-04-26 07:59:12 +00:00
};
if (LBrakeLevel>0) {
2020-02-02 20:40:05 +00:00
#Reduced CoolingRatio if Brakes used
LCoolingRatio = LCoolingRatio * 0.1 * LBrakeLevel;
2020-04-26 07:59:12 +00:00
};
if (RBrakeLevel>0) {
2020-02-02 20:40:05 +00:00
#Reduced CoolingRatio if Brakes used
RCoolingRatio = RCoolingRatio * 0.1 * RBrakeLevel;
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
var LnCoolFactor = math.ln(1-LCoolingRatio);
var RnCoolFactor = math.ln(1-RCoolingRatio);
2020-01-04 22:36:43 +00:00
2020-02-02 20:40:05 +00:00
L_thrust_lb = math.abs(getprop("engines/engine[0]/thrust_lb"));
2020-04-26 07:59:12 +00:00
if (L_thrust_lb < 1) {
2020-02-02 20:40:05 +00:00
L_thrust_lb = 1
2020-04-26 07:59:12 +00:00
};
2020-02-07 19:39:12 +00:00
#Disabling thrust computation on Brakes temperature
#L_Thrust = math.pow((math.log10(L_thrust_lb)),10)*0.0000000002;
L_Thrust = 0;
2020-01-27 18:01:33 +00:00
2020-02-02 20:40:05 +00:00
R_thrust_lb = math.abs(getprop("engines/engine[1]/thrust_lb"));
2020-04-26 07:59:12 +00:00
if (R_thrust_lb < 1) {
2020-02-02 20:40:05 +00:00
R_thrust_lb = 1
2020-04-26 07:59:12 +00:00
};
2020-02-07 19:39:12 +00:00
#Disabling thrust computation on Brakes temperature
#R_Thrust = math.pow((math.log10(R_thrust_lb)),10)*0.0000000002;
R_Thrust = 0;
2020-01-27 18:01:33 +00:00
2020-04-26 07:59:12 +00:00
if (OnGround) {
2020-02-02 20:40:05 +00:00
var V1 = getprop("velocities/groundspeed-kt");
var Mass = getprop("fdm/jsbsim/inertia/weight-lbs")*(me.ScalingDivisor);
2020-01-27 18:01:33 +00:00
2020-02-02 20:40:05 +00:00
# absorb some kinetic energy:
# dE= 1/2 * m * V1^2 - 1/2 * m * V2^2)
2020-01-27 18:01:33 +00:00
var V2_L = V1 - me.BrakeDecel * dt * LBrakeLevel;
2020-02-02 20:40:05 +00:00
var V2_R = V1 - me.BrakeDecel * dt * RBrakeLevel;
2020-04-26 07:59:12 +00:00
2020-02-21 22:27:52 +00:00
LThermalEnergy += (Mass * getprop("gear/gear[1]/compression-norm") * (math.pow(V1, 2) - math.pow(V2_L, 2)) / 2);
2020-07-25 23:13:54 +00:00
if (getprop("/services/chocks/enable")) {
if (!getprop("/controls/gear/brake-parking")) {
2020-01-27 18:01:33 +00:00
# cooling effect: reduce thermal energy by (LnCoolFactor) * dt
LThermalEnergy = LThermalEnergy * math.exp(LnCoolFactor * dt);
} else {
#LThermalEnergy += L_Thrust;
2020-02-02 20:40:05 +00:00
# cooling effect: reduce thermal energy by (LnCoolFactor) * dt
LThermalEnergy = (LThermalEnergy * math.exp(LnCoolFactor * dt)) + (L_Thrust * dt);
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
} else {
2020-07-25 23:13:54 +00:00
if (!getprop("/controls/gear/brake-parking")) {
2020-04-26 07:59:12 +00:00
if (LBrakeLevel>0) {
if (V2_L>0) {
2020-02-02 20:40:05 +00:00
#LThermalEnergy += (Mass * (math.pow(V1, 2) - math.pow(V2_L, 2)) / 2) + L_thrust;
# cooling effect: reduce thermal energy by (LnCoolFactor) * dt
LThermalEnergy = LThermalEnergy * math.exp(LnCoolFactor * dt);
} else {
#LThermalEnergy += math.abs(L_Thrust);
# cooling effect: reduce thermal energy by (LnCoolFactor) * dt
LThermalEnergy = (LThermalEnergy * math.exp(LnCoolFactor * dt)) + (L_Thrust * dt);
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
} else {
# cooling effect: reduce thermal energy by (LnCoolFactor) * dt
LThermalEnergy = LThermalEnergy * math.exp(LnCoolFactor * dt);
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
} else {
#LThermalEnergy += math.abs(L_Thrust);
2020-02-02 20:40:05 +00:00
# cooling effect: reduce thermal energy by (LnCoolFactor) * dt
LThermalEnergy = (LThermalEnergy * math.exp(LnCoolFactor * dt)) + (L_Thrust * dt);
2020-04-26 07:59:12 +00:00
};
};
2020-01-27 18:01:33 +00:00
2020-02-21 22:27:52 +00:00
RThermalEnergy += (Mass * getprop("gear/gear[2]/compression-norm") * (math.pow(V1, 2) - math.pow(V2_R, 2)) / 2);
2020-07-25 23:13:54 +00:00
if (getprop("/services/chocks/enable")) {
if (!getprop("/controls/gear/brake-parking")) {
2020-01-27 18:01:33 +00:00
# cooling effect: reduce thermal energy by (RnCoolFactor) * dt
RThermalEnergy = RThermalEnergy * math.exp(RnCoolFactor * dt);
} else {
#RThermalEnergy += math.abs(R_Thrust);
2020-02-02 20:40:05 +00:00
# cooling effect: reduce thermal energy by (RnCoolFactor) * dt
RThermalEnergy = (RThermalEnergy * math.exp(RnCoolFactor * dt)) + (R_Thrust * dt);
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
} else {
2020-07-25 23:13:54 +00:00
if (!getprop("/controls/gear/brake-parking")) {
2020-04-26 07:59:12 +00:00
if (RBrakeLevel>0) {
if (V2_R>0) {
2020-02-02 20:40:05 +00:00
#RThermalEnergy += (Mass * (math.pow(V1, 2) - math.pow(V2_R, 2)) / 2) + R_thrust;
# cooling effect: reduce thermal energy by (RnCoolFactor) * dt
RThermalEnergy = RThermalEnergy * math.exp(RnCoolFactor * dt);
} else {
#RThermalEnergy += math.abs(R_Thrust);
# cooling effect: reduce thermal energy by (RnCoolFactor) * dt
RThermalEnergy = (RThermalEnergy * math.exp(RnCoolFactor * dt)) + (R_Thrust * dt);
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
} else {
# cooling effect: reduce thermal energy by (RnCoolFactor) * dt
RThermalEnergy = RThermalEnergy * math.exp(RnCoolFactor * dt);
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
} else {
#RThermalEnergy += math.abs(R_Thrust);
2020-02-02 20:40:05 +00:00
# cooling effect: reduce thermal energy by (RnCoolFactor) * dt
RThermalEnergy = (RThermalEnergy * math.exp(RnCoolFactor * dt)) + (R_Thrust * dt);
2020-04-26 07:59:12 +00:00
};
};
2020-01-27 18:01:33 +00:00
} else {
2020-02-02 20:40:05 +00:00
LThermalEnergy = LThermalEnergy * math.exp(LnCoolFactor * dt);
RThermalEnergy = RThermalEnergy * math.exp(RnCoolFactor * dt);
2020-04-26 07:59:12 +00:00
};
if (LThermalEnergy < 0) {
2020-01-27 18:01:33 +00:00
LThermalEnergy = 0
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
if (LThermalEnergy > 3) {
LThermalEnergy = 3
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
if (RThermalEnergy < 0) {
RThermalEnergy = 0
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
if (RThermalEnergy > 3) {
RThermalEnergy = 3
2020-04-26 07:59:12 +00:00
};
2020-01-27 18:01:33 +00:00
setprop("gear/gear[1]/L-Thrust",L_Thrust);
setprop("gear/gear[2]/R-Thrust",R_Thrust);
2020-02-02 20:40:05 +00:00
setprop("gear/gear[1]/Lbrake-thermal-energy",LThermalEnergy);
setprop("gear/gear[2]/Rbrake-thermal-energy",RThermalEnergy);
2019-12-02 18:25:19 +00:00
2020-02-02 20:40:05 +00:00
#Calculating Brakes temperature
setprop("gear/gear[1]/L1brake-temp-degc",tatdegc+getprop("gear/gear[1]/L1error-temp-degc")+(LThermalEnergy * (300-tatdegc-getprop("gear/gear[1]/L1error-temp-degc"))));
setprop("gear/gear[1]/L2brake-temp-degc",tatdegc+getprop("gear/gear[1]/L2error-temp-degc")+(LThermalEnergy * (300-tatdegc-getprop("gear/gear[1]/L2error-temp-degc"))));
setprop("gear/gear[2]/R3brake-temp-degc",tatdegc+getprop("gear/gear[2]/R3error-temp-degc")+(RThermalEnergy * (300-tatdegc-getprop("gear/gear[2]/R3error-temp-degc"))));
setprop("gear/gear[2]/R4brake-temp-degc",tatdegc+getprop("gear/gear[2]/R4error-temp-degc")+(RThermalEnergy * (300-tatdegc-getprop("gear/gear[2]/R4error-temp-degc"))));
2020-04-26 07:59:12 +00:00
if ((LThermalEnergy>1)and(!me.LSmokeActive)) {
2020-02-02 20:40:05 +00:00
# start smoke processing
me.LSmokeActive = 1;
settimer(func { BrakeSys.Lsmoke(); },0);
2020-04-26 07:59:12 +00:00
};
if ((RThermalEnergy>1)and(!me.RSmokeActive)) {
2020-02-02 20:40:05 +00:00
# start smoke processing
me.RSmokeActive = 1;
settimer(func { BrakeSys.Rsmoke(); },0);
2020-04-26 07:59:12 +00:00
};
};
2020-02-02 20:40:05 +00:00
me.LastSimTime = CurrentTime;
# 5 updates per second are good enough
settimer(func { BrakeSys.update(); },0.2);
},
2019-12-02 18:25:19 +00:00
2020-02-02 20:40:05 +00:00
# smoke processing
Lsmoke : func()
{
2020-04-26 07:59:12 +00:00
if ((me.LSmokeActive)and(getprop("gear/gear[1]/Lbrake-thermal-energy")>1)) {
2020-02-02 20:40:05 +00:00
# make density of smoke effect depend on energy level
var LSmokeDelay=0;
var LThermalEnergy = getprop("gear/gear[1]/Lbrake-thermal-energy");
2020-04-26 07:59:12 +00:00
if (LThermalEnergy < 1.5) {
LSmokeDelay=(1.5-LThermalEnergy);
};
2020-02-02 20:40:05 +00:00
# No smoke when gear retracted
var LSmokeValue = (getprop("gear/gear[1]/position-norm")>0.5);
# toggle smoke to interpolate different densities
2020-04-26 07:59:12 +00:00
if (LSmokeDelay>0.05) {
2020-02-02 20:40:05 +00:00
me.LSmokeToggle = !me.LSmokeToggle;
if (!me.LSmokeToggle)
LSmokeValue = 0;
else
LSmokeDelay = 0;
2020-04-26 07:59:12 +00:00
};
2020-02-02 20:40:05 +00:00
setprop("gear/gear[1]/Lbrake-smoke",LSmokeValue);
settimer(func { BrakeSys.Lsmoke(); },LSmokeDelay);
2020-04-26 07:59:12 +00:00
} else {
2020-02-02 20:40:05 +00:00
# stop smoke processing
setprop("gear/gear[1]/Lbrake-smoke",0);
2020-07-25 23:13:54 +00:00
setprop("/sim/animation/fire-services",0);
2020-02-02 20:40:05 +00:00
me.LSmokeActive = 0;
2020-04-26 07:59:12 +00:00
};
if (getprop("gear/gear[1]/Lbrake-thermal-energy") > 1.5) {
2020-07-25 23:13:54 +00:00
setprop("/sim/animation/fire-services",1);
2020-04-26 07:59:12 +00:00
} else {
2020-07-25 23:13:54 +00:00
setprop("/sim/animation/fire-services",0);
2020-04-26 07:59:12 +00:00
};
2020-02-02 20:40:05 +00:00
},
2019-12-02 18:25:19 +00:00
2020-02-02 20:40:05 +00:00
# smoke processing
Rsmoke : func()
{
2020-04-26 07:59:12 +00:00
if ((me.RSmokeActive)and(getprop("gear/gear[2]/Rbrake-thermal-energy")>1)) {
2020-02-02 20:40:05 +00:00
# make density of smoke effect depend on energy level
var RSmokeDelay=0;
var RThermalEnergy = getprop("gear/gear[2]/Rbrake-thermal-energy");
2020-04-26 07:59:12 +00:00
if (RThermalEnergy < 1.5) {
2020-02-02 20:40:05 +00:00
RSmokeDelay=(1.5-RThermalEnergy);
2020-04-26 07:59:12 +00:00
};
2020-02-02 20:40:05 +00:00
# No smoke when gear retracted
var RSmokeValue = (getprop("gear/gear[2]/position-norm")>0.5);
# toggle smoke to interpolate different densities
2020-04-26 07:59:12 +00:00
if (RSmokeDelay>0.05) {
2020-02-02 20:40:05 +00:00
me.RSmokeToggle = !me.RSmokeToggle;
if (!me.RSmokeToggle)
RSmokeValue = 0;
else
RSmokeDelay = 0;
2020-04-26 07:59:12 +00:00
};
2020-02-02 20:40:05 +00:00
setprop("gear/gear[2]/Rbrake-smoke",RSmokeValue);
settimer(func { BrakeSys.Rsmoke(); },RSmokeDelay);
2020-04-26 07:59:12 +00:00
} else {
2020-02-02 20:40:05 +00:00
# stop smoke processing
setprop("gear/gear[2]/Rbrake-smoke",0);
me.RSmokeActive = 0;
2020-04-26 07:59:12 +00:00
};
if (getprop("gear/gear[2]/Rbrake-thermal-energy") > 1.5) {
2020-07-25 23:13:54 +00:00
setprop("/sim/animation/fire-services",1);
2020-04-26 07:59:12 +00:00
} else {
2020-07-25 23:13:54 +00:00
setprop("/sim/animation/fire-services",0);
2020-04-26 07:59:12 +00:00
};
2020-02-02 20:40:05 +00:00
},
2019-12-02 18:25:19 +00:00
};
var BrakeSys = BrakeSystem.new();
2020-07-25 23:13:54 +00:00
#############
# Autobrake #
#############
var Autobrake = {
active: props.globals.initNode("/controls/autobrake/active", 0, "BOOL"),
mode: props.globals.initNode("/controls/autobrake/mode", 0, "INT"),
decel: props.globals.initNode("/controls/autobrake/decel-rate", 0, "DOUBLE"),
_wow0: 0,
_gnd_speed: 0,
_mode: 0,
_active: 0,
init: func() {
me.active.setBoolValue(0);
me.mode.setValue(0);
me.decel.setValue(0);
},
arm_autobrake: func(mode) {
me._wow0 = pts.Gear.wow[0].getBoolValue();
me._gnd_speed = pts.Velocities.groundspeed.getValue();
if (mode == 0) { # OFF
absChk.stop();
if (me.active.getBoolValue()) {
me.active.setBoolValue(0);
pts.Controls.Gear.brake[0].setValue(0);
pts.Controls.Gear.brake[1].setValue(0);
}
me.decel.setValue(0);
me.mode.setValue(0);
} else if (mode == 1 and !me._wow0) { # LO
me.decel.setValue(2.0);
me.mode.setValue(1);
absChk.start();
} else if (mode == 2 and !me._wow0) { # MED
me.decel.setValue(3);
me.mode.setValue(2);
absChk.start();
} else if (mode == 3 and me._wow0 and me._gnd_speed < 40) { # MAX
me.decel.setValue(6);
me.mode.setValue(3);
absChk.start();
}
},
loop: func() {
me._wow0 = pts.Gear.wow[0].getBoolValue();
me._gnd_speed = pts.Velocities.groundspeed.getValue();
me._mode = me.mode.getValue();
me._active = me.active.getBoolValue();
if (me._gnd_speed > 72) {
if (me._mode != 0 and pts.Controls.Engines.Engine.throttle[0].getValue() < 0.15 and pts.Controls.Engines.Engine.throttle[1].getValue() < 0.15 and me._wow0) {
me.active.setBoolValue(1);
} elsif (me._active) {
me.active.setBoolValue(0);
pts.Controls.Gear.brake[0].setValue(0);
pts.Controls.Gear.brake[1].setValue(0);
}
}
if (me._mode == 3 and !pts.Controls.Gear.gearDown.getBoolValue()) {
me.arm_autobrake(0);
}
if (me._mode != 0 and me._wow0 and me._active and (pts.Controls.Gear.brake[0].getValue() > 0.05 or pts.Controls.Gear.brake[1].getValue() > 0.05)) {
me.arm_autobrake(0);
}
},
};
# Override FG's generic brake
controls.applyBrakes = func(v, which = 0) {
if (!pts.Acconfig.running.getBoolValue()) {
if (which <= 0) {
pts.Controls.Gear.brake[0].setValue(v);
}
if (which >= 0) {
pts.Controls.Gear.brake[1].setValue(v);
}
}
}
setlistener("/sim/signals/fdm-initialized",
2020-04-26 07:59:12 +00:00
# executed on _every_ FDM reset (but not installing new listeners)
func(idle) { BrakeSys.reset(); },
0,0);
2019-12-02 18:25:19 +00:00
2020-07-25 23:13:54 +00:00
settimer(func() { BrakeSys.update(); }, 5);
# Autobrake loop
var absChk = maketimer(0.2, func {
Autobrake.loop();
});