Exemplo n.º 1
0
 public MainForm()
 {
     InitializeComponent();
     controlLocker   = new object();
     isGLControlLoad = false;
     server          = new BluetoothServer(this);
     droneList       = new Dictionary <int, BebopDrone>();
     uwbManager      = new UWBManager(this);
 }
 public MoveCalibration(MainForm mainForm,
                        int power,
                        int[] times,
                        BebopDrone drone,
                        UWBManager uwbManager,
                        int tag_id)
 {
     this.mainForm   = mainForm;
     this.power      = power;
     this.times      = new List <int>(times);
     this.drone      = drone;
     this.uwbManager = uwbManager;
     this.tag_id     = tag_id;
     this.leftMeter  = null;
     this.rightMeter = null;
     this.backMeter  = null;
     this.frontMeter = null;
     this.downMeter  = null;
     this.upMeter    = null;
 }
Exemplo n.º 3
0
        public static CalibrationInfo Calibrate(MainForm mainForm,
                                                BebopDrone drone,
                                                UWBManager uwbManager,
                                                int tag_id,
                                                string droneName,
                                                int[] powers = null,
                                                int[] times  = null,
                                                bool overlap = true)
        {
            // Check if drone is already being calibrated.
            lock (memberLocker)
            {
                if (calibratedDrone != -1)
                {
                    return(null);
                }
            }

            // Check is there already calibration data, if there is, remove.
            string[]        keys = CalibrationList.GetAllCalibratedDroneNames(mainForm);
            CalibrationInfo cInfo;

            if (keys != null)
            {
                if (keys.Contains(droneName))
                {
                    if (!overlap)
                    {
                        return(null);
                    }
                    else
                    {
                        cInfo = CalibrationList.GetCalibrationData(mainForm, droneName);
                    }
                    //CalibrationList.RemoveCalibrationData(mainForm, droneName);
                }
                else
                {
                    cInfo = new CalibrationInfo();
                }
            }
            else
            {
                cInfo = new CalibrationInfo();
            }

            // x, y, z move calibration
            if (powers == null || powers.Length == 0)
            {
                powers = CalibrationStandard.POWERS;
            }
            foreach (int power in powers)
            {
                mainForm.UpdateCalibrationLog(power.ToString() + " power move calibration");
                //mainForm.UpdateCalibrationLog("Time values: " + CalibrationStandard.TIMES.ToString());
                if (times == null || times.Length == 0)
                {
                    times = CalibrationStandard.TIMES;
                }

                MoveCalibrationInfo mcInfo          = cInfo.GetMoveInfo(power);
                MoveCalibration     moveCalibration =
                    new MoveCalibration(mainForm,
                                        power,
                                        times,
                                        drone,
                                        uwbManager,
                                        tag_id);
                List <string[]> csvRows = new List <string[]>();
                moveCalibration.Calibrate(csvRows);
                CSVManager.CSVWrite(power.ToString() + "Log.csv",
                                    new string[] { "Type", "Time", "Meter" },
                                    csvRows);

                if (mcInfo == null)
                {
                    mcInfo = new MoveCalibrationInfo(power,
                                                     moveCalibration.GetTimes(),
                                                     moveCalibration.GetLeftMeters(),
                                                     moveCalibration.GetRightMeters(),
                                                     moveCalibration.GetBackMeters(),
                                                     moveCalibration.GetFrontMeters(),
                                                     moveCalibration.GetDownMeters(),
                                                     moveCalibration.GetUpMeters());
                }
                else
                {
                    int[] moveTimes = moveCalibration.GetTimes().ToArray();
                    mcInfo.NullCheck();
                    foreach (int time in moveTimes)
                    {
                        mcInfo.AddLeftMeter(time, moveCalibration.GetLeftMeters()[time]);
                        mcInfo.AddRightMeter(time, moveCalibration.GetRightMeters()[time]);
                        mcInfo.AddBackMeter(time, moveCalibration.GetBackMeters()[time]);
                        mcInfo.AddFrontMeter(time, moveCalibration.GetFrontMeters()[time]);
                        mcInfo.AddDownMeter(time, moveCalibration.GetDownMeters()[time / 2]);
                        mcInfo.AddUpMeter(time, moveCalibration.GetUpMeters()[time / 2]);
                    }
                }
                cInfo.AddMoveInfo(power, mcInfo);
            }
            // rotation calibration


            mainForm.UpdateCalibrationLog("---Calibration Finish---");

            lock (memberLocker)
                calibratedDrone = -1;

            return(cInfo);
        }