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

Jump to navigation Jump to search
m
→‎/Nasal/fbw.nas: use a separate update_ailerons() method
m (→‎/Nasal/fbw.nas: use a separate update_ailerons() method)
Line 139: Line 139:


var pitch = getprop("/orientation/pitch-deg");
var pitch = getprop("/orientation/pitch-deg");
var roll = getprop("/orientation/roll-deg");
me.roll = getprop("/orientation/roll-deg");


var airspeedkt = getprop("/velocities/airspeed-kt");
var airspeedkt = getprop("/velocities/airspeed-kt");
Line 148: Line 148:
var ailtrim = getprop("/controls/flight/aileron-trim");
var ailtrim = getprop("/controls/flight/aileron-trim");


var aileronin = getprop(fcs~"aileron-cmd-norm");
me.aileronin = getprop(fcs~"aileron-cmd-norm");
me.elevatorin =  getprop(fcs~"elevator-cmd-norm");
me.elevatorin =  getprop(fcs~"elevator-cmd-norm");
me.rudderin = getprop(fcs~"rudder-cmd-norm");
me.rudderin = getprop(fcs~"rudder-cmd-norm");
Line 154: Line 154:
## FBW Output (actual surface positions)
## FBW Output (actual surface positions)


var aileronout = getprop(fcs~"aileron-fbw-output");
me.aileronout = getprop(fcs~"aileron-fbw-output");
me.elevatorout =  getprop(fcs~"elevator-fbw-output");
me.elevatorout =  getprop(fcs~"elevator-fbw-output");
me.rudderout = getprop(fcs~"rudder-fbw-output");
me.rudderout = getprop(fcs~"rudder-fbw-output");
Line 187: Line 187:
me.disconnectannounce = 0;
me.disconnectannounce = 0;


## AILERON CONTROLS
me.update_ailerons();
 
### Set Aileron Direction and Roll Direction
 
var rolldir = 0;
if (roll < 0) rolldir = -1;
if (roll > 0) rolldir = 1;
 
 
if (aileronin < 0) var ailerondir = -1;
if (aileronin > 0) var ailerondir = 1;
if (aileronin == 0) var ailerondir = 0;
 
if ( in_range(roll,[-banklimit,banklimit]) or (rolldir != ailerondir)) {
 
 
if (aileronin > aileronout) aileronout += 0.05 * me.fpsfix;
 
if (aileronin < aileronout) aileronout -= 0.05 * me.fpsfix;
 
} else {
 
### Don't let the plane bank past the bank limit
 
if (roll < -banklimit) me.targetaileron = -(roll + banklimit) * 0.025;
if (roll > banklimit) me.targetaileron = -(roll - banklimit) * 0.025;
 
if (aileronout < me.targetaileron) aileronout += 0.025 * me.fpsfix;
if (aileronout > me.targetaileron) aileronout -= 0.025 * me.fpsfix;
 
}
 
me.update_elevator();
me.update_elevator();


Line 246: Line 215:
if (me.stabilize == 0) {
if (me.stabilize == 0) {
setprop("/controls/fbw/stabpitch-deg", pitch);
setprop("/controls/fbw/stabpitch-deg", pitch);
setprop("/controls/fbw/stabroll-deg", roll);
setprop("/controls/fbw/stabroll-deg", me.roll);
me.stabilize = 1;
me.stabilize = 1;
}
}
Line 272: Line 241:
### Adjust throttle while turning
### Adjust throttle while turning


if ((roll <= -5) or (roll >= 5)) {
if ((me.roll <= -5) or (me.roll >= 5)) {


if (me.turnthrottlefix == 0) {
if (me.turnthrottlefix == 0) {
Line 279: Line 248:
}
}


me.targetthrottle = me.throttleinit + (me.throttleinit * math.sin(math.abs(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 > throttles[0]) {
Line 291: Line 260:
}
}


if ( in_range(roll,[-5,5]) and (me.turnthrottlefix == 1) ) {
if ( in_range(me.roll,[-5,5]) and (me.turnthrottlefix == 1) ) {




Line 345: Line 314:
if (getprop("/controls/fbw/rudder")) {
if (getprop("/controls/fbw/rudder")) {


if ((roll < -5) or (roll > 5)) {
if ((me.roll < -5) or (me.roll > 5)) {
me.targetrudder = aileronout / 2;
me.targetrudder = me.aileronout / 2;


if (me.targetrudder < me.rudderout) me.rudderout -= 0.015;
if (me.targetrudder < me.rudderout) me.rudderout -= 0.015;
Line 357: Line 326:
# Transmit output signals to surfaces
# Transmit output signals to surfaces


setprop(fcs~"aileron-fbw-output", aileronout);
setprop(fcs~"aileron-fbw-output", me.aileronout);
setprop(fcs~"elevator-fbw-output", me.elevatorout);
setprop(fcs~"elevator-fbw-output", me.elevatorout);
setprop(fcs~"rudder-fbw-output", me.rudderout);
setprop(fcs~"rudder-fbw-output", me.rudderout);
Line 370: Line 339:
# Transmit input signals directly to surfaces
# Transmit input signals directly to surfaces


setprop(fcs~"aileron-fbw-output", aileronin);
setprop(fcs~"aileron-fbw-output", me.aileronin);
setprop(fcs~"elevator-fbw-output", me.elevatorin);
setprop(fcs~"elevator-fbw-output", me.elevatorin);
setprop(fcs~"rudder-fbw-output", me.rudderin);
setprop(fcs~"rudder-fbw-output", me.rudderin);
Line 399: Line 368:


     }
     }
},
    update_ailerons: func {
      ## AILERON CONTROLS
      ### Set Aileron Direction and Roll Direction
      me.rolldir = 0;
      if (me.roll < 0) me.rolldir = -1;
      if (me.roll > 0) me.rolldir = 1;
      me.ailerondir = 0;
      if (me.aileronin < 0) me.ailerondir = -1;
      if (me.aileronin > 0) me.ailerondir = 1;
      if ( in_range(me.roll,[-me.banklimit,me.banklimit]) or (me.rolldir != me.ailerondir)) {
      if (me.aileronin > me.aileronout) me.aileronout += 0.05 * me.fpsfix;
      if (me.aileronin < me.aileronout) me.aileronout -= 0.05 * me.fpsfix;
      } else {
      ### Don't let the plane bank past the bank limit
      if (me.roll < -me.banklimit) me.targetaileron = -(me.roll + me.banklimit) * 0.025;
      if (me.roll > me.banklimit) me.targetaileron = -(me.roll - me.banklimit) * 0.025;
      if (me.aileronout < me.targetaileron) me.aileronout += 0.025 * me.fpsfix;
      if (me.aileronout > me.targetaileron) me.aileronout -= 0.025 * me.fpsfix;
      }


},
},

Navigation menu