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

m
→‎/Nasal/fbw.nas: use methods to increment and decrement the throttles
m (→‎/Nasal/fbw.nas: introduce new helpers to help increment/decrement throttles)
m (→‎/Nasal/fbw.nas: use methods to increment and decrement the throttles)
Line 84: Line 84:
  return ((value <= min) and (value >= max));
  return ((value <= min) and (value >= max));
}
}
var inc_throttles = func {
  throttles[0] += INCREMENT * me.fpsfix;
  throttles[1] += INCREMENT * me.fpsfix;
}
var dec_throttles = func {
  throttles[0] -= INCREMENT * me.fpsfix;
  throttles[1] -= INCREMENT * me.fpsfix;
}


var fbw = {
var fbw = {
Line 175: Line 163:
# use a vector of throttles, this can be later on used to support more than
# use a vector of throttles, this can be later on used to support more than
# just two engines
# just two engines
var throttles = [nil,nil];  
# TODO: move to constructor
me.throttles = [nil,nil];  


throttles[0] = getprop("controls/engines/engine[0]/throttle");
me.throttles[0] = getprop("controls/engines/engine[0]/throttle");
throttles[1] = getprop("controls/engines/engine[1]/throttle");
me.throttles[1] = getprop("controls/engines/engine[1]/throttle");


## This is where the FBW actually does its job ;)
## This is where the FBW actually does its job ;)
Line 234: Line 223:
### Disconnect Throttle fix if manually overridden
### Disconnect Throttle fix if manually overridden


if (throttles[0] != me.throttle) {
if (me.throttles[0] != me.throttle) {
me.throttlefix = 0;
me.throttlefix = 0;
me.turnthrottlefix = 0;
me.turnthrottlefix = 0;
Line 245: Line 234:


if (me.turnthrottlefix == 0) {
if (me.turnthrottlefix == 0) {
me.throttleinit = throttles[0];
me.throttleinit = me.throttles[0];
me.turnthrottlefix = 1;
me.turnthrottlefix = 1;
}
}
Line 251: Line 240:
me.targetthrottle = me.throttleinit + (me.throttleinit * math.sin(math.abs(me.roll * DEG2RAD)))/2;
me.targetthrottle = me.throttleinit + (me.throttleinit * math.sin(math.abs(me.roll * DEG2RAD)))/2;


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


Line 264: Line 253:




if (throttles[0] <= me.throttleinit - 0.05) {
if (me.throttles[0] <= me.throttleinit - 0.05) {
throttles[0] += INCREMENT * me.fpsfix;
me.throttles[0] += INCREMENT * me.fpsfix;
throttles[1] += INCREMENT * me.fpsfix;
me.throttles[1] += INCREMENT * me.fpsfix;
} elsif (throttles[0] > me.throttleinit + 0.05) {
} elsif (me.throttles[0] > me.throttleinit + 0.05) {
throttles[0] -= INCREMENT * me.fpsfix;
me.throttles[0] -= INCREMENT * me.fpsfix;
throttles[1] -= INCREMENT * me.fpsfix;
me.throttles[1] -= INCREMENT * me.fpsfix;
} else me.turnthrottlefix = 0;
} else me.turnthrottlefix = 0;
}
}
Line 275: Line 264:
### Reduce throttle if aircraft is faster than 250 KIAS under 10000 ft
### Reduce throttle if aircraft is faster than 250 KIAS under 10000 ft


if ((airspeedkt >= 250) and (altitudemsl <= 10000) and (throttles[0] != 0) and (throttles[1] != 0)) {
if ((airspeedkt >= 250) and (altitudemsl <= 10000) and (me.throttles[0] != 0) and (me.throttles[1] != 0)) {
throttles[0] -= INCREMENT * me.fpsfix;
me.throttles[0] -= INCREMENT * me.fpsfix;
throttles[1] -= INCREMENT * me.fpsfix;
me.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 (me.throttles[0] != 1) and (throttles[1] != 1)) {
throttles[0] += INCREMENT * me.fpsfix;
me.throttles[0] += INCREMENT * me.fpsfix;
throttles[1] += INCREMENT * me.fpsfix;
me.throttles[1] += INCREMENT * me.fpsfix;
}
}


Line 420: Line 409:
}
}
}
}
},
inc_throttles: func {
forindex(var t; me.throttles)
  throttles[t] += INCREMENT * me.fpsfix;
},
dec_throttles:func {
forindex(var t; me.throttles)
  throttles[t] -= INCREMENT * me.fpsfix;
},
},
     reset : func {
     reset : func {