Esempio n. 1
0
        public static int GetRollTime(MainForm mainForm,
                                      string droneName,
                                      int power,
                                      double meter)
        {
            CalibrationInfo     cInfo  = CalibrationList.GetCalibrationData(mainForm, droneName);
            MoveCalibrationInfo mcInfo = cInfo.GetMoveInfo(power);

            if (mcInfo == null)
            {
                mainForm.ShowMessageBox("Power " + power + " data doesn't exist.");
                return(-1);
            }

            float[] times  = Array.ConvertAll(mcInfo.GetTimes(), x => (float)x); // x
            float[] meters = new float[times.Length];                            // y
            for (int i = 0; i < meters.Length; i++)
            {
                if (power > 0)
                {
                    meters[i] = (float)mcInfo.GetRightMeter((int)times[i]);
                }
                else
                {
                    meters[i] = (float)mcInfo.GetLeftMeter((int)times[i]);
                }
            }

            if (meters.Min() > meter || meters.Max() < meter)
            {
                mainForm.ShowMessageBox("Meter " + meter + " is out of data range.");
                return(-1);
            }

            float[] timeResult = CubicSpline.Compute(meters, times, new float[] { (float)meter });
            return((int)timeResult[0]);
        }