20,741
edits
m (→Examples) |
|||
Line 148: | Line 148: | ||
Come up with a framework that allows modeling instrument/equipment failures for systems implemented in scripting space and C++, focus on airborne equipment and prepare hooks for also supporting ground equipment failures such as navaids. | Come up with a framework that allows modeling instrument/equipment failures for systems implemented in scripting space and C++, focus on airborne equipment and prepare hooks for also supporting ground equipment failures such as navaids. | ||
== Examples (by Necolatis) == | |||
{{FGCquote | |||
|Here is a speed trigger and a value actuator: | |||
|{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212581#p212581 | |||
|title=<nowiki>Gear fail at too high speed</nowiki> | |||
|author=<nowiki>Necolatis</nowiki> | |||
|date=<nowiki>Sat Jun 14</nowiki> | |||
}} | |||
}} | |||
<syntaxhighlight lang="nasal">## | |||
# Trigger object that will fire when aircraft air-speed is over | |||
# min, specified in knots. Probability of failing will | |||
# be 0% at min speed and 100% at max speed and beyond. | |||
# When the specified property is 0 there is zero chance of failing. | |||
var SpeedTrigger = { | |||
parents: [FailureMgr.Trigger], | |||
requires_polling: 1, | |||
new: func(min, max, prop) { | |||
if(min == nil or max == nil) | |||
die("SpeedTrigger.new: min and max must be specified"); | |||
if(min >= max) | |||
die("SpeedTrigger.new: min must be less than max"); | |||
if(min < 0 or max <= 0) | |||
die("SpeedTrigger.new: min must be positive or zero and max larger than zero"); | |||
if(prop == nil or prop == "") | |||
die("SpeedTrigger.new: prop must be specified"); | |||
var m = FailureMgr.Trigger.new(); | |||
m.parents = [SpeedTrigger]; | |||
m.params["min-speed-kt"] = min; | |||
m.params["max-speed-kt"] = max; | |||
m.params["property"] = prop; | |||
m._speed_prop = "/velocities/airspeed-kt"; | |||
return m; | |||
}, | |||
to_str: func { | |||
sprintf("Increasing probability of fails between %d and %d kt air-speed", | |||
int(me.params["min-speed-kt"]), int(me.params["max-speed-kt"])) | |||
}, | |||
update: func { | |||
if(getprop(me.params["property"]) != 0) { | |||
var speed = getprop(me._speed_prop); | |||
var min = me.params["min-speed-kt"]; | |||
var max = me.params["max-speed-kt"]; | |||
var speed_d = 0; | |||
if(speed > min) { | |||
speed_d = speed-min; | |||
var delta_factor = 1/(max - min); | |||
var factor = speed <= max ? delta_factor*speed_d : 1; | |||
if(rand() < factor) { | |||
return 1; | |||
} | |||
} | |||
} | |||
return 0; | |||
} | |||
}; | |||
## | |||
# Returns an actuator object that will set a property at | |||
# a value when triggered. | |||
var set_value = func(path, value) { | |||
var default = getprop(path); | |||
return { | |||
parents: [FailureMgr.FailureActuator], | |||
set_failure_level: func(level) setprop(path, level > 0 ? value : default), | |||
get_failure_level: func { getprop(path) == default ? 0 : 1 } | |||
} | |||
} | |||
</syntaxhighlight> | |||
{{FGCquote | |||
|And a jsbsim example of how to use it on individual gears: | |||
|{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212581#p212581 | |||
|title=<nowiki>Gear fail at too high speed</nowiki> | |||
|author=<nowiki>Necolatis</nowiki> | |||
|date=<nowiki>Sat Jun 14</nowiki> | |||
}} | |||
}} | |||
<syntaxhighlight lang="nasal"> | |||
#front gear locking mechanism might fail when deployed at too high speeds | |||
var prop = "gear/gear[0]/position-norm"; | |||
var trigger_gear0 = SpeedTrigger.new(350, 500, prop); | |||
var actuator_gear0 = set_value("fdm/jsbsim/gear/unit[0]/z-position", 0.001); | |||
FailureMgr.add_failure_mode("controls/gear0", "Front gear locking mechanism", actuator_gear0); | |||
FailureMgr.set_trigger("controls/gear0", trigger_gear0); | |||
</syntaxhighlight> | |||
== Current Situation == | == Current Situation == |