コード例 #1
0
        public void InitFromConfig(string filename)
        {
            configFilename = filename;

            if (!File.Exists(configFilename))
            {
                return;
            }

            configData = JsonConvert.DeserializeObject <FilterConfigData>(File.ReadAllText(configFilename), new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            foreach (List <FilterBase> filterList in filters)
            {
                if (filterList != null)
                {
                    filterList.Clear();
                }
            }

            for (int i = 0; i < filters.Length; ++i)
            {
                filters[i] = null;
            }

            for (int i = 0; i < configData.keys.Count; ++i)
            {
                if (configData.keys[i] == null)
                {
                    continue;
                }

                FilterDataKey key = configData.keys[i];

                List <FilterBase> filterList = filters[(int)key.key] = new List <FilterBase>();

                foreach (FilterData filterData in key.filters)
                {
                    if (filterData is SmoothFilterData)
                    {
                        SmoothFilterData   smoothFilterData = (SmoothFilterData)filterData;
                        NestedSmoothFilter newFilter        = new NestedSmoothFilter();
                        newFilter.SetParameters(smoothFilterData.nestCount, smoothFilterData.sampleCount, smoothFilterData.maxDelta);

                        filterList.Add(newFilter);
                    }
                    else
                    if (filterData is KalmanFilterData)
                    {
                        KalmanFilterData  kalmanFilterData = (KalmanFilterData)filterData;
                        KalmanNoiseFilter newFilter        = new KalmanNoiseFilter();
                        newFilter.SetParameters(kalmanFilterData.a, kalmanFilterData.h, kalmanFilterData.q, kalmanFilterData.r, kalmanFilterData.p, kalmanFilterData.x);

                        filterList.Add(newFilter);
                    }
                }
            }
        }
コード例 #2
0
        public FilterBase AddFilter(FilterType filterType, GenericProviderData.DataKey key, bool updateUI = false)
        {
            List <FilterBase> filterList = filters[(int)key];

            if (filterList == null)
            {
                filterList = filters[(int)key] = new List <FilterBase>();
            }

            FilterBase newFilter = null;

            switch (filterType)
            {
            case FilterType.Smooth:
            {
                NestedSmoothFilter newSmoothFilter = new NestedSmoothFilter();
                newSmoothFilter.SetParameters(0, 10, 1000.0f);

                filterList.Add(newSmoothFilter);
                newFilter = newSmoothFilter;

                break;
            }

            case FilterType.Kalman:
            {
                KalmanNoiseFilter newKalmanFilter = new KalmanNoiseFilter();
                newKalmanFilter.SetParameters(1, 1, 0.02f, 1, 0.02f, 0.0f);

                filterList.Add(newKalmanFilter);
                newFilter = newKalmanFilter;

                break;
            }

            case FilterType.SavitzkyGolay:
            {
                break;
            }

            case FilterType.FIR:
            {
                break;
            }
            }

            if (updateUI && FilterUI.Instance != null)
            {
//                FilterUI.Instance.InitChartForKey(key);
            }



            return(newFilter);
        }
コード例 #3
0
        private void A_TextChanged(object sender, EventArgs e)
        {
            if (ignoreChanges)
            {
                return;
            }

            filter.SetParameters(Utils.TextBoxSafeParseFloat(A, filter.GetA()),
                                 Utils.TextBoxSafeParseFloat(H, filter.GetH()),
                                 Utils.TextBoxSafeParseFloat(Q, filter.GetQ()),
                                 Utils.TextBoxSafeParseFloat(R, filter.GetR()),
                                 Utils.TextBoxSafeParseFloat(P, filter.GetP()),
                                 Utils.TextBoxSafeParseFloat(X, filter.GetX()));
        }
コード例 #4
0
        public FilterBase AddFilter(FilterType filterType, CMCustomUDPData.DataKey key, bool updateUI = false)
        {
            List <FilterBase> filterList = filters[(int)key];

            if (filterList == null)
            {
                filterList = filters[(int)key] = new List <FilterBase>();
            }

            FilterBase newFilter = null;

            switch (filterType)
            {
            case FilterType.Smooth:
            {
                NestedSmoothFilter newSmoothFilter = new NestedSmoothFilter();
                newSmoothFilter.SetParameters(1, 3, 0.5f);

                filterList.Add(newSmoothFilter);
                newFilter = newSmoothFilter;

                break;
            }

            case FilterType.Kalman:
            {
                KalmanNoiseFilter newKalmanFilter = new KalmanNoiseFilter();
                newKalmanFilter.SetParameters(1, 1, 0.02f, 1, 0.02f, 0.0f);

                filterList.Add(newKalmanFilter);
                newFilter = newKalmanFilter;

                break;
            }

            case FilterType.KalmanVelocity:
            {
                KalmanVelocityNoiseFilter newKalmanFilter = new KalmanVelocityNoiseFilter();
                newKalmanFilter.SetParameters(1, 1, 0.02f, 1, 0.02f, 0.0f);

                filterList.Add(newKalmanFilter);
                newFilter = newKalmanFilter;

                break;
            }

            case FilterType.SavitzkyGolay:
            {
                break;
            }

            case FilterType.FIR:
            {
                break;
            }

            case FilterType.Median:
            {
                MedianFilterWrapper newFilterW = new MedianFilterWrapper();
                newFilterW.SetParameters(9);

                filterList.Add(newFilterW);
                newFilter = newFilterW;

                break;
            }
            }

            if (updateUI && FilterUI.Instance != null)
            {
                FilterUI.Instance.InitChartForKey(key);
            }



            return(newFilter);
        }