Esempio n. 1
0
        public FCSFunction(FlightControlSystem fcs, XmlElement element)
            : base(fcs, element)
        {
            XmlNodeList childs = element.GetElementsByTagName("function");

            if (childs != null && childs.Count > 0)
            {
                function = new Function(fcs.GetPropertyManager(), childs[0] as XmlElement);
            }

            base.Bind();
        }
Esempio n. 2
0
        public Gain(FlightControlSystem fcs, XmlElement element)
            : base(fcs, element)
        {
            XmlElement  scale_element, zero_centered;
            XmlNodeList childs;
            string      gain_string, sZeroCentered;

            XmlElement gainElement = element.GetElementsByTagName("gain")[0] as XmlElement;

            if (compType.Equals("PURE_GAIN"))
            {
                if (gainElement == null)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("No GAIN specified (default: 1.0)");
                    }
                }
            }
            if (gainElement != null)
            {
                gain_string = gainElement.InnerText.Trim();
                Match match = testRegex.Match(gain_string);
                if (match.Success && match.Groups["prop1"].Value.Length != 0)
                { // property
                    gainPropertyNode = fcs.GetPropertyManager().GetPropertyNode(match.Groups["prop1"].Value);
                }
                else
                {
                    gain = FormatHelper.ValueAsNumber(gainElement);
                }
            }
            if (compType.Equals("AEROSURFACE_SCALE"))
            {
                scale_element = element.GetElementsByTagName("domain")[0] as XmlElement;
                if (scale_element != null)
                {
                    childs = scale_element.GetElementsByTagName("max");
                    inMax  = FormatHelper.ValueAsNumber(childs[0] as XmlElement);
                    childs = scale_element.GetElementsByTagName("min");
                    inMin  = FormatHelper.ValueAsNumber(childs[0] as XmlElement);
                }

                scale_element = element.GetElementsByTagName("range")[0] as XmlElement;
                if (scale_element == null)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("No range supplied for aerosurface scale component");
                    }

                    throw new Exception("No range supplied for aerosurface scale component");
                }
                try
                {
                    childs = scale_element.GetElementsByTagName("max");
                    outMax = FormatHelper.ValueAsNumber(childs[0] as XmlElement);
                    childs = scale_element.GetElementsByTagName("min");
                    outMin = FormatHelper.ValueAsNumber(childs[0] as XmlElement);
                }
                catch (Exception e)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("Maximum and minimum output values must be supplied for the " +
                                  "aerosurface scale component");
                    }
                    throw new Exception("Maximum and minimum output values must be supplied. Catch exception: " + e);
                }
                zeroCentered  = true;
                zero_centered = element.GetElementsByTagName("zero_centered")[0] as XmlElement;
                if (zero_centered != null)
                {
                    sZeroCentered = zero_centered.InnerText.Trim();
                    if (sZeroCentered.Equals("0") || sZeroCentered.Equals("false"))
                    {
                        zeroCentered = false;
                    }
                }
            }

            if (compType.Equals("SCHEDULED_GAIN"))
            {
                XmlElement tableElement = element.GetElementsByTagName("table")[0] as XmlElement;
                if (tableElement != null)
                {
                    table = new Table(fcs.GetPropertyManager(), tableElement);
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("A table must be provided for the scheduled gain component");
                    }
                    throw new Exception("A table must be provided for the scheduled gain component");
                }
            }

            base.Bind();
        }
Esempio n. 3
0
        /// Constructor
        public FCSComponent(FlightControlSystem fcsParent, XmlElement element)
        {
            fcs             = fcsParent;
            propertyManager = fcs.GetPropertyManager();

            compType = "";
            isOutput = false;
            name     = element.GetAttribute("name");
            compType = element.GetAttribute("type"); // Old, deprecated format
            if (compType.Length == 0)
            {
                if (element.LocalName.Equals("lag_filter"))
                {
                    compType = "LAG_FILTER";
                }
                else if (element.LocalName.Equals("lead_lag_filter"))
                {
                    compType = "LEAD_LAG_FILTER";
                }
                else if (element.LocalName.Equals("washout_filter"))
                {
                    compType = "WASHOUT_FILTER";
                }
                else if (element.LocalName.Equals("second_order_filter"))
                {
                    compType = "SECOND_ORDER_FILTER";
                }
                else if (element.LocalName.Equals("integrator"))
                {
                    compType = "INTEGRATOR";
                }
                else if (element.LocalName.Equals("summer"))
                {
                    compType = "SUMMER";
                }
                else if (element.LocalName.Equals("pure_gain"))
                {
                    compType = "PURE_GAIN";
                }
                else if (element.LocalName.Equals("scheduled_gain"))
                {
                    compType = "SCHEDULED_GAIN";
                }
                else if (element.LocalName.Equals("aerosurface_scale"))
                {
                    compType = "AEROSURFACE_SCALE";
                }
                else if (element.LocalName.Equals("switch"))
                {
                    compType = "SWITCH";
                }
                else if (element.LocalName.Equals("kinematic"))
                {
                    compType = "KINEMATIC";
                }
                else if (element.LocalName.Equals("deadband"))
                {
                    compType = "DEADBAND";
                }
                else if (element.LocalName.Equals("fcs_function"))
                {
                    compType = "FCS_FUNCTION";
                }
                else if (element.LocalName.Equals("sensor"))
                {
                    compType = "SENSOR";
                }
                else
                { // illegal component in this channel
                    compType = "UNKNOWN";
                }
            }


            foreach (XmlNode currentNode in element.ChildNodes)
            {
                if (currentNode.NodeType == XmlNodeType.Element)
                {
                    XmlElement currentElement = (XmlElement)currentNode;

                    if (currentElement.LocalName.Equals("input"))
                    {
                        string inputTxt = currentElement.InnerText.Trim();
                        if (inputTxt[0] == '-')
                        {
                            inputSigns.Add(-1.0f);
                            inputTxt = inputTxt.Remove(0, 1);
                        }
                        else
                        {
                            inputSigns.Add(1.0f);
                        }
                        inputNodes.Add(ResolveSymbol(inputTxt));
                    }
                    else if (currentElement.LocalName.Equals("output"))
                    {
                        isOutput   = true;
                        outputNode = propertyManager.GetPropertyNode(currentElement.InnerText.Trim());
                        if (outputNode == null)
                        {
                            log.Error("  Unable to process property: " + currentElement.InnerText);
                            throw new Exception("Invalid output property name in flight control definition");
                        }
                        else if (currentElement.LocalName.Equals("clipto"))
                        {
                            XmlNodeList childs;
                            string      clip_string;
                            childs = currentElement.GetElementsByTagName("min");
                            if (childs != null)
                            {
                                clip_string = ((XmlElement)childs[0]).InnerText.Trim();
                            }
                            else
                            {
                                throw new Exception("clipto doesn't have a min tag");
                            }

                            if (!clip_string.StartsWith("+-.0123456789"))
                            { // it's a property
                                if (clip_string[0] == '-')
                                {
                                    clipMinSign = -1.0f;
                                }
                                clip_string         = clip_string.Remove(0, 1); //TODO test it
                                ClipMinPropertyNode = propertyManager.GetPropertyNode(clip_string);
                            }
                            else
                            {
                                clipmin = double.Parse(clip_string, FormatHelper.numberFormatInfo);
                            }

                            childs = currentElement.GetElementsByTagName("max");
                            if (childs != null)
                            {
                                clip_string = ((XmlElement)childs[0]).InnerText.Trim();
                            }
                            else
                            {
                                throw new Exception("clipto doesn't have a max tag");
                            }
                            if (!clip_string.StartsWith("+-.0123456789"))
                            { // it's a property
                                if (clip_string[0] == '-')
                                {
                                    clipMaxSign = -1.0f;
                                }
                                clip_string         = clip_string.Remove(0, 1); //TODO test it
                                ClipMaxPropertyNode = propertyManager.GetPropertyNode(clip_string);
                            }
                            else
                            {
                                clipmax = double.Parse(clip_string, FormatHelper.numberFormatInfo);
                            }

                            clip = true;
                        }
                    }
                }
            }
        }