449
edits
No edit summary |
|||
Line 243: | Line 243: | ||
throttle1 -= 0.001 * fpsfix; | throttle1 -= 0.001 * fpsfix; | ||
} | } | ||
} | |||
if ((roll > -5) and (roll <= 5) and (me.turnthrottlefix == 1)) { | |||
if (throttle0 <= me.throttleinit - 0.05) { | |||
throttle0 += 0.001 * fpsfix; | |||
throttle1 += 0.001 * fpsfix; | |||
} elsif (throttle0 > me.throttleinit + 0.05) { | |||
throttle0 -= 0.001 * fpsfix; | |||
throttle1 -= 0.001 * fpsfix; | |||
} else me.turnthrottlefix = 0; | |||
} | |||
### Reduce throttle if aircraft is faster than 250 KIAS under 10000 ft | |||
if ((airspeedkt >= 250) and (altitudemsl <= 10000) and (throttle0 != 0) and (throttle1 != 0)) { | |||
throttle0 -= 0.001 * fpsfix; | |||
throttle1 -= 0.001 * fpsfix; | |||
me.throttlefix = 1; | |||
} | |||
if ((me.throttlefix == 1) and (airspeedkt < 245) and (altitudemsl <= 10000) and (throttle0 != 1) and (throttle1 != 1)) { | |||
throttle0 += 0.001 * fpsfix; | |||
throttle1 += 0.001 * fpsfix; | |||
} | |||
### Adjust Throttle to stay under Vne | |||
if ((airspeedkt >= 350) and (altitudemsl > 10000) and (throttle0 != 0) and (throttle1 != 0)) { | |||
throttle0 -= 0.001 * fpsfix; | |||
throttle1 -= 0.001 * fpsfix; | |||
me.throttlefix = 1; | |||
} | |||
if ((me.throttlefix == 1) and (airspeedkt < 340) and (altitudemsl > 10000) and (throttle0 != 1) and (throttle1 != 1)) { | |||
throttle0 += 0.001 * fpsfix; | |||
throttle1 += 0.001 * fpsfix; | |||
} | |||
### Adjust Throttle to keep from stalling | |||
if ((airspeedkt < 125) and (altitudeagl > 250) and (throttle0 != 1) and (throttle1 != 1)) { | |||
throttle0 += 0.001 * fpsfix; | |||
throttle1 += 0.001 * fpsfix; | |||
### Also help by pushing forward on the stick | |||
elevatorout += 0.02; | |||
} | |||
## RUDDER CONTROLS | |||
if (getprop("/controls/fbw/rudder")) { | |||
if ((roll < -5) or (roll > 5)) { | |||
me.targetrudder = aileronout / 2; | |||
if (me.targetrudder < rudderout) rudderout -= 0.015; | |||
if (me.targetrudder > rudderout) rudderout += 0.015; | |||
} } | |||
## YAW DAMPER | |||
if (getprop("/controls/fbw/yaw-damper")) { | |||
if (rudderin > rudderout) rudderout += 0.05 * fpsfix; | |||
if (rudderin < rudderout) rudderout -= 0.05 * fpsfix; | |||
} else { | |||
rudderout = rudderin; | |||
} | |||
# Transmit output signals to surfaces | |||
setprop(fcs~"aileron-fbw-output", aileronout); | |||
setprop(fcs~"elevator-fbw-output", elevatorout); | |||
setprop(fcs~"rudder-fbw-output", rudderout); | |||
setprop("controls/engines/engine[0]/throttle", throttle0); | |||
setprop("controls/engines/engine[1]/throttle", throttle1); | |||
me.throttle = throttle0; # This is to find out if the pilot moved the throttle | |||
} else { | |||
# Transmit input signals directly to surfaces | |||
setprop(fcs~"aileron-fbw-output", aileronin); | |||
setprop(fcs~"elevator-fbw-output", elevatorin); | |||
setprop(fcs~"rudder-fbw-output", rudderin); | |||
} | |||
}, | |||
reset : func { | |||
me.loopid += 1; | |||
me._loop_(me.loopid); | |||
}, | |||
_loop_ : func(id) { | |||
id == me.loopid or return; | |||
me.update(); | |||
settimer(func { me._loop_(id); }, me.UPDATE_INTERVAL); | |||
} | |||
}; | |||
fbw.init(); | |||
print("Fly-By-Wire ......... Initialized"); | |||
# *Power-by-wire : corresponds to power steering in cars | |||
</syntaxhighlight> | |||
=== -set.xml === | |||
Call the Nasal file in your aircraft's -set.xml file by adding the following code inside <nasal></nasal> | |||
<syntaxhighlight lang="xml"> | |||
<fbw> | |||
<file>Aircraft/787-8/Nasal/fbw.nas</file> | |||
</fbw> | |||
</syntaxhighlight> | |||
Replace '787-8' with your aircraft folder name. | |||
=== JSBSim FDM === | |||
Replace 'aileron-cmd-norm' with 'aileron-fbw-output', replace 'elevator-cmd-norm' with 'elevator-fbw-output' and finally, replace 'rudder-cmd-norm' with 'rudder-fbw-output'. | |||
For example, | |||
<syntaxhighlight lang="xml"> | |||
<summer name="Pitch Trim Sum"> | |||
<input>fcs/elevator-cmd-norm</input> | |||
<input>fcs/pitch-trim-cmd-norm</input> | |||
<clipto> | |||
<min> -1 </min> | |||
<max> 1 </max> | |||
</clipto> | |||
</summer> | |||
</syntaxhighlight> | |||
was changed to | |||
<syntaxhighlight lang="xml"> | |||
<summer name="Pitch Trim Sum"> | |||
<input>fcs/elevator-fbw-output</input> | |||
<input>fcs/pitch-trim-cmd-norm</input> | |||
<clipto> | |||
<min> -1 </min> | |||
<max> 1 </max> | |||
</clipto> | |||
</summer> | |||
</syntaxhighlight> | |||
== Configuration == | |||
Add the following switches anywhere (preferably the CDU) to be able to configure the CDU in FlightGear: | |||
* /controls/fbw/active (controls whether the fly-by-wire system is active or not) | |||
* /controls/fbw/yaw-damper (controls the yaw damper) | |||
* /controls/fbw/rudder (controls whether the fly-by-wire controls rudder or not) | |||
* /controls/fbw/bank-limit (controls the aircraft's bank limit) | |||
If you don't want any of the configurations to be edited in Flightgear, but configured generally, add the following under </sim> to your -set.xml for the appropriate properties you want to configure: | |||
<syntaxhighlight lang="xml"> | |||
<controls> | |||
<fbw> | |||
<yaw-damper type="int">1</yawdamper> | |||
<rudder type="int">1</rudder> | |||
<bank-limit type="int">30</bank-limit> <!-- 30 degrees bank permitted --> | |||
</fbw> | |||
</controls> | |||
</syntaxhighlight> | |||
[[Category:Howto]] | |||
[[Category:Nasal]] |
edits