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

no edit summary
No edit summary
Line 10: Line 10:
* -set.xml
* -set.xml
* fbw.nas
* fbw.nas
* FDM xml file
* fly-by-wire.xml
* FDM xml


Note that as the new 787 uses JSBSim, this tutorial will focus on implementing the FBW to an aircraft running with JSBSim.
Note that as the new 787 uses JSBSim, this tutorial will focus on implementing the FBW to an aircraft running with JSBSim.
Line 40: Line 41:
* Reduces thrust when exceeding 250 knots under 10000 ft MSL and when reaching Vne above 10000 ft MSL
* Reduces thrust when exceeding 250 knots under 10000 ft MSL and when reaching Vne above 10000 ft MSL
* Dampens the controls to prevent sudden movements
* Dampens the controls to prevent sudden movements
* Automatically holds the current aircraft pitch and roll degree when stick is brought back to the center! < NEW!




Line 56: Line 59:
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
#########################################
#########################################
## FLY BY WIRE SYSTEM FOR FLIGHTGEAR  ##
## FLY BY WIRE SYSTEM FOR BOEING 787-8 ##
#########################################
#########################################
## Designed by Omega Pilot and Redneck ##
## Designed by Omega Pilot and Redneck ##
Line 72: Line 75:
me.throttle = 0;
me.throttle = 0;
me.throttlefix = 0;
me.throttlefix = 0;
me.vsinit = 0;
me.throttleinit = 0;
me.throttleinit = 0;
me.targetthrottle = 0;
me.targetthrottle = 0;
Line 80: Line 82:
me.targetrudder = 0;
me.targetrudder = 0;
me.adjustelevators = 0;
me.adjustelevators = 0;
me.stabilize = 0;
me.stabpitch = 0;
me.stabroll = 0;


me.disconnectannounce = 0;
me.disconnectannounce = 0;
Line 104: Line 110:
## Fix Damp Rate according to Framerate
## Fix Damp Rate according to Framerate


var fpsfix=1;
if (getprop("/sim/frame-rate") != nil) var fpsfix = 25 / getprop("/sim/frame-rate");
if (getprop("/sim/frame-rate") != nil) fpsfix = 25 / getprop("/sim/frame-rate");
else fpsfix = 1;


## Bank Limit Setting
## Bank Limit Setting
Line 122: Line 128:
var airspeedkt = getprop("/velocities/airspeed-kt");
var airspeedkt = getprop("/velocities/airspeed-kt");


var vsfps = getprop("/velocities/vertical-speed-fps");
## Flight Control System Properties


## Flight Control System Properties
var elevtrim = getprop("/controls/flight/elevator-trim");
var ailtrim = getprop("/controls/flight/aileron-trim");


var aileronin = getprop(fcs~"aileron-cmd-norm");
var aileronin = getprop(fcs~"aileron-cmd-norm");
Line 148: Line 155:


if (getprop("/systems/electrical/outputs/efis") != nil) {
if (getprop("/systems/electrical/outputs/efis") != nil) {
if ((getprop("/systems/electrical/outputs/efis") < 9) and (altitudeagl >= 200)) {
if ((getprop("/systems/electrical/outputs/efis") < 9) and (altitudeagl >= 200)) {
  setprop("/controls/fbw/active", 0);
setprop("/controls/fbw/active", 0);
  if (me.disconnectannounce == 0) {
if (me.disconnectannounce == 0) {
  screen.log.write("Fly By Wire Disconnected!", 1, 0, 0);
screen.log.write("Fly By Wire Disconnected!", 1, 0, 0);
  me.disconnectannounce = 1;
me.disconnectannounce = 1;
  } # end of disconnect announce
} } }
} # end of efis/agl check
}


if (getprop("/controls/fbw/active")) {
if (getprop("/controls/fbw/active")) {
Line 194: Line 199:


if (elevatorin > elevatorout) elevatorout += 0.05 * fpsfix;
if (elevatorin > elevatorout) elevatorout += 0.05 * fpsfix;
if (elevatorin < elevatorout) elevatorout -= 0.05 * fpsfix;
if (elevatorin < elevatorout) elevatorout -= 0.05 * fpsfix;


Line 200: Line 204:
if ((elevatorout - elevatorin < 0.05) and (elevatorin - elevatorout < 0)) elevatorout -= 0.01;  
if ((elevatorout - elevatorin < 0.05) and (elevatorin - elevatorout < 0)) elevatorout -= 0.01;  


### Use elevator to stabilize VS on turns
## AUTO-STABILIZATION
 
### Get the aircraft to maintain pitch and roll when stick is at the center


if ((roll <= -5) or (roll >= 5)) {
if ((elevatorin <= 0.1) and (elevatorin >= -0.1) and (aileronin <= 0.1) and (aileronin >= -0.1)) {


if (me.adjustelevators == 0) {
if (me.stabilize == 0) {
me.adjustelevators = 1;
setprop("/controls/fbw/stabpitch-deg", pitch);
me.vsinit = vsfps;
setprop("/controls/fbw/stabroll-deg", roll);
me.stabilize = 1;
}
}


if (vsfps < me.vsinit) elevatorout -= 0.02;
if ((airspeedkt >= 220) and (altitudeagl >= 3500)) {
if (vsfps > me.vsinit) elevatorout += 0.02;
setprop("/controls/fbw/autostable", 1);
 
} else {
} else {
if (me.adjustelevators == 1) {
setprop("/controls/fbw/autostable", 0);
if (elevtrim > 0) elevtrim -= 0.05;
if (elevtrim < 0) elevtrim += 0.05;
if (ailtrim > 0) ailtrim -= 0.05;
if (ailtrim < 0) ailtrim += 0.05;


if (vsfps < me.vsinit) elevatorout -= 0.02;
setprop("/controls/flight/elevator-trim", elevtrim);
elsif (vsfps > me.vsinit) elevatorout += 0.02;
setprop("/controls/flight/aileron-trim", ailtrim);
else me.adjustelevators = 0;


}
}
} else {
me.stabilize = 0;
setprop("/controls/fbw/autostable", 0);
}
}
## THROTTLE CONTROLS
## THROTTLE CONTROLS


Line 249: Line 261:
throttle0 -= 0.001 * fpsfix;
throttle0 -= 0.001 * fpsfix;
throttle1 -= 0.001 * fpsfix;
throttle1 -= 0.001 * fpsfix;
}
}  
 


}
}
Line 368: Line 379:
# *Power-by-wire : corresponds to power steering in cars
# *Power-by-wire : corresponds to power steering in cars
</syntaxhighlight>
</syntaxhighlight>
=== fly-by-wire.xml ===
Open your aircraft's Systems directory and create a file called 'fly-by-wire.xml'. Copy and paste the following pid controller code in that file and save it.
<syntaxhighlight lang="xml">
<?xml version="1.0"?>
<!-- Fly By Wire, Auto Stabilize Pitch and Roll -->
<PropertyList>
<!-- =============================================================== -->
<!-- Roll Deg Hold -->
<!-- =============================================================== -->
<pid-controller>
<name>FBW Roll Deg Hold</name>
<debug type="bool">false</debug>
<enable>
<prop>/controls/fbw/autostable</prop>
</enable>
<input>
<prop>/orientation/roll-deg</prop>
</input>
<reference>
<prop>/controls/fbw/stabroll-deg</prop>
</reference>
<output>
<prop>/controls/flight/aileron-trim</prop>
</output>
<config>
<Kp>0.05</Kp>
<beta>1</beta>
<alpha>0.1</alpha>
<gamma>0</gamma>
<Ti>10</Ti>
<Td>0.00001</Td>
<u_min>-2</u_min>
<u_max>2</u_max>
</config>
</pid-controller>
<!-- =============================================================== -->
<!-- Pitch Hold -->
<!-- =============================================================== -->
<pid-controller>
    <name>Pitch hold</name>
    <debug>false</debug>
    <enable>
<prop>/controls/fbw/autostable</prop>
    </enable>
    <input>
    <prop>/orientation/pitch-deg</prop>
  </input>
  <reference>
    <prop>/controls/fbw/stabpitch-deg</prop>
  </reference>
  <output>
    <prop>/controls/flight/elevator-trim</prop>
  </output>
  <config>
    <Kp>-0.05</Kp>      <!-- proportional gain -->
    <beta>1.0</beta>    <!-- input value weighing factor -->
    <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
    <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                        <!-- unfiltered derivative error -->
    <Ti>1.0</Ti>        <!-- integrator time -->
    <Td>0.00001</Td>    <!-- derivator time -->
    <u_min>-1.0</u_min> <!-- minimum output clamp -->
    <u_max>1.0</u_max>  <!-- maximum output clamp -->
  </config>
  </pid-controller>
</PropertyList>
</syntaxhighlight>
Note that the above PID Controller is configured for smooth control of the 787-8. You migh thave to tweak the values inside the <config> .. </config> tags to get to smooth with your aircraft.


=== -set.xml ===
=== -set.xml ===
Line 379: Line 483:
</syntaxhighlight>
</syntaxhighlight>


Replace '787-8' with your aircraft folder name.
And also add the following code under </sim>
 
<syntaxhighlight lang="xml">
<systems>
<autopilot>
<path>Aircraft/787-8/Systems/fly-by-wire.xml</path>
</autopilot>
</systems>
</syntaxhighlight>
 
Replace '787-8' with your aircraft folder name in both instances.


=== JSBSim FDM ===
=== JSBSim FDM ===
449

edits