Failure Manager: Difference between revisions

Jump to navigation Jump to search
3,554 bytes removed ,  17 December 2014
Examples and usage documentation will be added when the API is sufficiently stable
(Examples and usage documentation will be added when the API is sufficiently stable)
Line 80: Line 80:


;FailureMgr: The Failure Manager itself. Keeps a list of supported failure modes that can be added or removed dynamically using a Nasal API. It also offers a Nasal interface for attaching triggers to failure modes (one trigger per failure mode). While enabled, the FailureMgr monitors trigger conditions, and fires the relevant failure modes through their actuators when their trigger becomes active. The FailureMgr can be enabled and disabled on command, both from Nasal and the property tree.
;FailureMgr: The Failure Manager itself. Keeps a list of supported failure modes that can be added or removed dynamically using a Nasal API. It also offers a Nasal interface for attaching triggers to failure modes (one trigger per failure mode). While enabled, the FailureMgr monitors trigger conditions, and fires the relevant failure modes through their actuators when their trigger becomes active. The FailureMgr can be enabled and disabled on command, both from Nasal and the property tree.
== Examples ==
{{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 RandSpeedTrigger = {
        parents: [FailureMgr.Trigger],
        requires_polling: 1,
        new: func(min, max, prop) {
            if(min == nil or max == nil)
                die("RandSpeedTrigger.new: min and max must be specified");
            if(min >= max)
                die("RandSpeedTrigger.new: min must be less than max");
            if(min < 0 or max <= 0)
                die("RandSpeedTrigger.new: min must be positive or zero and max larger than zero");
            if(prop == nil or prop == "")
                die("RandSpeedTrigger.new: prop must be specified");
            var m = FailureMgr.Trigger.new();
            m.parents = [RandSpeedTrigger];
            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 = RandSpeedTrigger.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>


== Roadmap ==
== Roadmap ==
60

edits

Navigation menu