double RemoveDeadZone(double power, double deadzone, double max)
 {
     if (power > 0)
     {
         power = Math2.MapValue(0, FlightComputerConfig.MAX_AXIS_VALUE, deadzone, max, power);
     }
     else if (power < 0)
     {
         power = Math2.MapValue(FlightComputerConfig.MIN_AXIS_VALUE, 0, -1 * max, -1 * deadzone, power);
     }
     return(power);
 }
Beispiel #2
0
        private void Update()
        {
            var didAdvanceWaypoint = _plan.UpdateLocation();

            if (didAdvanceWaypoint && _plan.CurrentIndex == 3)
            {
                Trace.WriteLine("Gear up");
                SystemManager.Instance.App.Controller.Press(Interop.XINPUT_GAMEPAD_BUTTONS.LEFT_THUMB, 10);
            }

            // One waypoint before top of G/P
            if (didAdvanceWaypoint && _plan.CurrentIndex == _plan.Points.Count - 3)
            {
                _mcp.ALT        = 800;
                _mcp.IAS        = 80;
                glidePathTopAlt = _mcp.ALT;
            }

            if (didAdvanceWaypoint && IsOnGlideToThreshold)
            {
                isAt75PercentGlide = false;
                isAt4PercentGlide  = false;
                isAt3PercentGlide  = false;
                isFlare            = false;
                Timeline.UpdateLocationFromMenu();
            }

            if (IsOnGlideToThreshold)
            {
                var percent_done = OnGlidePathPercent();

                if (percent_done < .7 && !isAt75PercentGlide)
                {
                    isAt75PercentGlide = true;

                    Timeline.UpdateLocationFromMenu();
                }

                if (percent_done < .5 && !isAt3PercentGlide)
                {
                    isAt3PercentGlide = true;
                    Trace.WriteLine("Gear down");
                    SystemManager.Instance.App.Controller.Press(Interop.XINPUT_GAMEPAD_BUTTONS.LEFT_THUMB, 10);
                }

                if (percent_done < .3 && !isAt4PercentGlide)
                {
                    isAt4PercentGlide = true;

                    Timeline.UpdateLocationFromMenu();
                }


                _mcp.ALT = Math.Round(Math2.MapValue(0, 1, _plan.Destination.Elevation, glidePathTopAlt, percent_done));
            }

            // Flare
            if (_plan.CurrentIndex == _plan.Points.Count - 1)
            {
                _mcp.ALT = _plan.Destination.Elevation;


                if (!isFlare && Timeline.AltitudeAvg < _plan.Destination.Elevation + 25)
                {
                    Trace.WriteLine("Flare");
                    isFlare     = true;
                    _mcp.IAS    = 0;
                    _mcp.VSHold = true;
                    _mcp.VS     = 10;
                }
            }

            // Disconnect
            if (_mcp.IASHold && _plan.CurrentIndex == _plan.Points.Count - 1 &&
                Timeline.Speed < 20)
            {
                if (_mcp.LNAV)
                {
                    Timeline.ResetGameFromSavePointByMenu();
                }

                _mcp.IASHold = false;
                _mcp.VSHold  = false;
                _mcp.LNAV    = false;
            }

            if (_mcp.LNAV)
            {
                var targetHdg = _plan.TargetHeading;

                if (_plan.CurrentIndex > 0)
                {
                    var tightHoldLine = (Timeline.Altitude < 800) ||
                                        (_plan.CurrentIndex >= _plan.Points.Count - 2);
                    var heading_cap = 8;

                    var mult = (tightHoldLine ? 1.5 : 0.5);
                    if (Timeline.Altitude < 150)
                    {
                        mult = 2;
                    }

                    var distanceFromTargetLine = mult * DistanceFromTargetLine;
                    distanceFromTargetLine = Math.Max(Math.Min(heading_cap, distanceFromTargetLine), -1 * heading_cap);

                    targetHdg -= distanceFromTargetLine;
                }
                _mcp.HDG = targetHdg;
            }
        }
Beispiel #3
0
        public void Tick()
        {
            if (Indicator != null)
            {
                double current_x = Width - 1;
                double x_size    = 250f / NUM_FRAMES;

                zeroLine.X1 = 0;
                zeroLine.X2 = Width;
                zeroLine.Y1 = Height / 2;
                zeroLine.Y2 = Height / 2;

                topLine.X1 = 0;
                topLine.X2 = Width;
                topLine.Y1 = 0;
                topLine.Y2 = 0;

                bottomLine.X1 = 0;
                bottomLine.X2 = Width;
                bottomLine.Y1 = Height;
                bottomLine.Y2 = Height;

                bottomText.Text = "" + GetRangeForIndicator()[0];
                topText.Text    = "" + GetRangeForIndicator()[1];

                Canvas.SetTop(topText, 4);
                Canvas.SetLeft(topText, 4);

                Canvas.SetTop(bottomText, Height - 20);
                Canvas.SetLeft(bottomText, 4);

                int           childIndex = SKIP_LINES + NUM_FRAMES;
                TimelineFrame last       = null;
                for (var i = Timeline.LatestFrameId; i >= 0 && i > Timeline.LatestFrameId - NUM_FRAMES; i--)
                {
                    var current = Timeline.Data[i];
                    if (last == null || current == null)
                    {
                        last = current;
                    }
                    else
                    {
                        var l = (Line)Children[childIndex];
                        var s = (Line)Children[childIndex - NUM_FRAMES];

                        if (!double.IsNaN(GetValueForIndicator(current)) && !double.IsNaN(GetValueForIndicator(last)))
                        {
                            l.Stroke = Brushes.Blue;

                            if (Type == IndicatorChartType.Delay)
                            {
                                if (GetValueForIndicator(current) > 0.2)
                                {
                                    l.Stroke = Brushes.Red;
                                }
                                else
                                {
                                    l.Stroke = Brushes.Green;
                                }
                            }


                            l.X1 = current_x;
                            l.X2 = current_x - x_size;
                            l.Y2 = Math2.MapValue(GetRangeForIndicator()[0], GetRangeForIndicator()[1], Height, 0, GetValueForIndicator(current));
                            l.Y1 = Math2.MapValue(GetRangeForIndicator()[0], GetRangeForIndicator()[1], Height, 0, GetValueForIndicator(last));
                        }
                        else
                        {
                            if (Type == IndicatorChartType.Value)
                            {
                                s.X1 = s.X2 = s.Y1 = s.Y2 = 0;
                            }

                            if (Type != IndicatorChartType.InputOutput)
                            {
                                l.Stroke = Brushes.Gray;
                                l.X1     = current_x;
                                l.X2     = current_x;
                                l.Y1     = 0;
                                l.Y2     = Height;
                            }
                            else
                            {
                                l.X1 = l.X2 = l.Y1 = l.Y2 = 0;
                            }
                        }

                        if (Type == IndicatorChartType.Value || Type == IndicatorChartType.InputOutput)
                        {
                            s.X1 = current_x;
                            s.X2 = current_x - x_size;

                            if (!double.IsNaN(GetSetPointForIndicator(current)) && !double.IsNaN(GetSetPointForIndicator(last)))
                            {
                                s.Y1 = Math2.MapValue(GetRangeForIndicator()[0], GetRangeForIndicator()[1], Height, 0, GetSetPointForIndicator(current));
                                s.Y2 = Math2.MapValue(GetRangeForIndicator()[0], GetRangeForIndicator()[1], Height, 0, GetSetPointForIndicator(last));
                            }
                            else
                            {
                                s.X1 = s.X2 = s.Y1 = s.Y2 = 0;
                            }
                        }

                        current_x = current_x - x_size;
                        childIndex++;
                        last = current;
                    }
                }
            }
        }