Howto:Implement a Fly-By-Wire System for Airliners: Difference between revisions

m
→‎/Nasal/fbw.nas: localize use of 0.001 constant
m (→‎/Nasal/fbw.nas: use a separate method to check if power is on)
m (→‎/Nasal/fbw.nas: localize use of 0.001 constant)
Line 70: Line 70:
var RAD2DEG = 57.2957795;
var RAD2DEG = 57.2957795;
var DEG2RAD = 0.0174532925;
var DEG2RAD = 0.0174532925;
var INCREMENT = 0.001;


# helpers:
# helpers:
Line 86: Line 87:
var fbw = {
var fbw = {
init : func {  
init : func {  
         me.UPDATE_INTERVAL = 0.001;  
         me.UPDATE_INTERVAL = INCREMENT;  
         me.loopid = 0;  
         me.loopid = 0;  
me.throttle = 0;
me.throttle = 0;
Line 239: Line 240:


if (me.targetthrottle > throttles[0]) {
if (me.targetthrottle > throttles[0]) {
throttles[0] += 0.001 * me.fpsfix;
throttles[0] += INCREMENT * me.fpsfix;
throttles[1] += 0.001 * me.fpsfix;
throttles[1] += INCREMENT * me.fpsfix;
} elsif (me.targetthrottle < throttles[0]) {
} elsif (me.targetthrottle < throttles[0]) {
throttles[0] -= 0.001 * me.fpsfix;
throttles[0] -= INCREMENT * me.fpsfix;
throttles[1] -= 0.001 * me.fpsfix;
throttles[1] -= INCREMENT * me.fpsfix;
}  
}  


Line 252: Line 253:


if (throttles[0] <= me.throttleinit - 0.05) {
if (throttles[0] <= me.throttleinit - 0.05) {
throttles[0] += 0.001 * me.fpsfix;
throttles[0] += INCREMENT * me.fpsfix;
throttles[1] += 0.001 * me.fpsfix;
throttles[1] += INCREMENT * me.fpsfix;
} elsif (throttles[0] > me.throttleinit + 0.05) {
} elsif (throttles[0] > me.throttleinit + 0.05) {
throttles[0] -= 0.001 * me.fpsfix;
throttles[0] -= INCREMENT * me.fpsfix;
throttles[1] -= 0.001 * me.fpsfix;
throttles[1] -= INCREMENT * me.fpsfix;
} else me.turnthrottlefix = 0;
} else me.turnthrottlefix = 0;
}
}
Line 263: Line 264:


if ((airspeedkt >= 250) and (altitudemsl <= 10000) and (throttles[0] != 0) and (throttles[1] != 0)) {
if ((airspeedkt >= 250) and (altitudemsl <= 10000) and (throttles[0] != 0) and (throttles[1] != 0)) {
throttles[0] -= 0.001 * me.fpsfix;
throttles[0] -= INCREMENT * me.fpsfix;
throttles[1] -= 0.001 * me.fpsfix;
throttles[1] -= INCREMENT * me.fpsfix;
me.throttlefix = 1;
me.throttlefix = 1;
}
}


if ((me.throttlefix == 1) and (airspeedkt < 245) and (altitudemsl <= 10000) and (throttles[0] != 1) and (throttles[1] != 1)) {
if ((me.throttlefix == 1) and (airspeedkt < 245) and (altitudemsl <= 10000) and (throttles[0] != 1) and (throttles[1] != 1)) {
throttles[0] += 0.001 * me.fpsfix;
throttles[0] += INCREMENT * me.fpsfix;
throttles[1] += 0.001 * me.fpsfix;
throttles[1] += INCREMENT * me.fpsfix;
}
}


Line 276: Line 277:


if ((airspeedkt >= 350) and (altitudemsl > 10000) and (throttles[0] != 0) and (throttles[1] != 0)) {
if ((airspeedkt >= 350) and (altitudemsl > 10000) and (throttles[0] != 0) and (throttles[1] != 0)) {
throttles[0] -= 0.001 * me.fpsfix;
throttles[0] -= INCREMENT * me.fpsfix;
throttles[1] -= 0.001 * me.fpsfix;
throttles[1] -= INCREMENT * me.fpsfix;
me.throttlefix = 1;
me.throttlefix = 1;
}
}


if ((me.throttlefix == 1) and (airspeedkt < 340) and (altitudemsl > 10000) and (throttles[0] != 1) and (throttles[1] != 1)) {
if ((me.throttlefix == 1) and (airspeedkt < 340) and (altitudemsl > 10000) and (throttles[0] != 1) and (throttles[1] != 1)) {
throttles[0] += 0.001 * me.fpsfix;
throttles[0] += INCREMENT * me.fpsfix;
throttles[1] += 0.001 * me.fpsfix;
throttles[1] += INCREMENT * me.fpsfix;
}
}


Line 289: Line 290:


if ((airspeedkt < 125) and (me.altitudeagl > 250) and (throttles[0] != 1) and (throttles[1] != 1)) {
if ((airspeedkt < 125) and (me.altitudeagl > 250) and (throttles[0] != 1) and (throttles[1] != 1)) {
throttles[0] += 0.001 * me.fpsfix;
throttles[0] += INCREMENT * me.fpsfix;
throttles[1] += 0.001 * me.fpsfix;
throttles[1] += INCREMENT * me.fpsfix;


### Also help by pushing forward on the stick
### Also help by pushing forward on the stick