Ejemplo n.º 1
0
        public async Task initialize()
        {
            var controller = await GpioController.GetDefaultAsync();

            if (controller == null)
            {
                // Rogin?
                return;
            }

            frontFilter = OnlineFilter.CreateDenoise();
            backFilter  = OnlineFilter.CreateDenoise();
            rightFilter = OnlineFilter.CreateDenoise();
            leftFilter  = OnlineFilter.CreateDenoise();


            triggerFrontPin = controller.OpenPin(kTriggerFront);
            triggerBackPin  = controller.OpenPin(kTriggerBack);
            triggerLeftPin  = controller.OpenPin(kTriggerLeft);
            triggerRightPin = controller.OpenPin(kTriggerRight);
            echoFrontPin    = controller.OpenPin(kEchoFront);
            echoBackPin     = controller.OpenPin(kEchoBack);
            echoLeftPin     = controller.OpenPin(kEchoLeft);
            echoRightPin    = controller.OpenPin(kEchoRight);

            triggerFrontPin.SetDriveMode(GpioPinDriveMode.Output);
            triggerBackPin.SetDriveMode(GpioPinDriveMode.Output);
            triggerLeftPin.SetDriveMode(GpioPinDriveMode.Output);
            triggerRightPin.SetDriveMode(GpioPinDriveMode.Output);
            echoFrontPin.SetDriveMode(GpioPinDriveMode.Input);
            echoBackPin.SetDriveMode(GpioPinDriveMode.Input);
            echoLeftPin.SetDriveMode(GpioPinDriveMode.Input);
            echoRightPin.SetDriveMode(GpioPinDriveMode.Input);

            long debounceTicks = Stopwatch.Frequency / (1000 * 1000 * 50);

            echoFrontPin.DebounceTimeout = TimeSpan.FromTicks(debounceTicks);
            echoBackPin.DebounceTimeout  = TimeSpan.FromTicks(debounceTicks);
            echoLeftPin.DebounceTimeout  = TimeSpan.FromTicks(debounceTicks);
            echoRightPin.DebounceTimeout = TimeSpan.FromTicks(debounceTicks);

            echoFrontPin.ValueChanged += EchoFrontPin_ValueChanged;
            echoBackPin.ValueChanged  += EchoBackPin_ValueChanged;
            echoLeftPin.ValueChanged  += EchoLeftPin_ValueChanged;
            echoRightPin.ValueChanged += EchoRightPin_ValueChanged;

            // Every greater than 60 ms per datasheet due to echo.
            // Round robin, so servicing each sonar every 120ms, but
            // allowing for echo by servicing opposite sides.
            timer.Interval = TimeSpan.FromMilliseconds(30);
            timer.Tick    += Timer_Tick;
            timer.Start();
        }
Ejemplo n.º 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            LineItem       kurvaMagnitude = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
            IPointListEdit listMagnitude  = kurvaMagnitude.Points as IPointListEdit;

            dataMagnitude = new double[1000];

            try
            {
                for (int i = 0; i < 1000; i++)
                {
                    dataMagnitude[i] = double.Parse(uno.ReadLine(), CultureInfo.InvariantCulture.NumberFormat);
                }
            }
            catch (Exception)
            {
                //uno.Close();
                return;
            }


            OnlineFilter bandpass = OnlineFilter.CreateBandpass(MathNet.Filtering.ImpulseResponse.Finite, 1000, 20, 500);
            OnlineFilter bandstop = OnlineFilter.CreateBandstop(MathNet.Filtering.ImpulseResponse.Finite, 1000, 48.5, 51.5);
            OnlineFilter denoise  = OnlineFilter.CreateDenoise();

            dataFilter = new double[1000];
            dataFilter = bandpass.ProcessSamples(dataMagnitude);
            dataFilter = bandstop.ProcessSamples(dataFilter);
            dataFilter = denoise.ProcessSamples(dataFilter);
            var N = Enumerable.Range(1, dataMagnitude.Length).ToArray();

            waktu = Array.ConvertAll <int, double>(N, Convert.ToDouble);



            // double waktu = (Environment.TickCount - waktustart) / 1000.0;
            listMagnitude.Clear();

            for (int i = 0; i < 1000; i++)
            {
                listMagnitude.Add(waktu[i], dataFilter[i]);
            }

            label1.Text = Convert.ToString(dataFilter[500]);
            //uno.Close();



            zedGraphControl1.AxisChange();
            zedGraphControl1.Refresh();
        }
Ejemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            dataFilter = new double[dataMagnitude.Length];
            OnlineFilter bandpass = OnlineFilter.CreateBandpass(ImpulseResponse.Finite, 1000, 20, 500);
            OnlineFilter bandstop = OnlineFilter.CreateBandstop(MathNet.Filtering.ImpulseResponse.Finite, 1000, 49, 51);
            OnlineFilter denoise  = OnlineFilter.CreateDenoise();

            dataFilter = bandpass.ProcessSamples(dataMagnitude);
            dataFilter = bandstop.ProcessSamples(dataFilter);
            dataFilter = denoise.ProcessSamples(dataFilter);

            LineItem       kurvaMagnitude = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            IPointListEdit listFilter     = kurvaMagnitude.Points as IPointListEdit;

            listFilter.Clear();
            for (int i = 1; i < dataFilter.Length; i++)
            {
                listFilter.Add(dataN[i], dataFilter[i]);
            }
            zedGraphControl1.AxisChange();
            zedGraphControl1.Invalidate();
            button2.Enabled = false;
            button3.Enabled = true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Applies a de-noising filter (using MathNet.Filtering) over the input stream. Implemented as an unweighted median filter.
        /// </summary>
        /// <param name="input">The input source of doubles.</param>
        /// <param name="order">Window Size, should be odd. A larger number results in a smoother response but also in a longer delay.</param>
        /// <param name="deliveryPolicy">An optional delivery policy for the input stream.</param>
        /// <returns>A high-pass filtered version of the input.</returns>
        public static IProducer <double> DenoiseFilter(this IProducer <double> input, int order, DeliveryPolicy <double> deliveryPolicy = null)
        {
            var filter = OnlineFilter.CreateDenoise(order);

            return(input.Select(s => filter.ProcessSample(s), deliveryPolicy));
        }