Exemple #1
0
        public bool Calibrate(double Tolerance)
        {
            //setup camera
            MainForm.cameraView.UpCameraReset();
            MainForm.cameraView.SetUpCameraFunctionSet("Needle");
            MainForm.cameraView.downSettings.FindCircles = true;

            // we are already @ upcamera position
            MainForm.Cnc.Zup();
            Global.GoTo("Up Camera");

            MainForm.Cnc.Zdown(Settings.Default.focus_height, true); //1 mm above PCB

            CalibrationPoints.Clear();                               // Presumably user changed the needle, and calibration is void no matter if we succeed here
            Calibrated = false;

            for (int i = 0; i <= 3600; i = i + 225)
            {
                NeedlePoint Point = new NeedlePoint();
                Point.A = i / 10.0;

                if (!MainForm.Cnc.CNC_A(Point.A))
                {
                    return(false);
                }
                //detect average of 3 measurements
                var circle = VideoDetection.GetClosestAverageCircle(MainForm.cameraView.upVideoProcessing, Tolerance, 3);

                if (circle == null)
                {
                    MainForm.ShowSimpleMessageBox("Needle Calibration: Can't see needle at angle " + Point.A + " - aborting");
                    return(false);
                }

                circle.ToMMResolution();
                Point.X = circle.X;
                Point.Y = circle.Y;

                // display point
                var pt = circle.Clone().ToScreenResolution().ToPartLocation().ToPointF();
                MainForm.DisplayText("circle @ " + circle + "\tx @ " + pt.X + "," + pt.Y);
                MainForm.cameraView.upVideoProcessing.MarkA.Add(pt);

                CalibrationPoints.Add(Point);
            }
            Calibrated = true;
            MainForm.Cnc.Zup();
            MainForm.cameraView.SetUpCameraDefaults();

            return(true);
        }
Exemple #2
0
        public bool Calibrate(double Tolerance)
        {
            //setup camera
            MainForm.cameraView.UpCameraReset();
            MainForm.cameraView.SetUpCameraFunctionSet("Needle");
            MainForm.cameraView.downSettings.FindCircles = true;

            // we are already @ upcamera position
            MainForm.Cnc.Zup();
            Global.GoTo("Up Camera");

            MainForm.Cnc.Zdown(Settings.Default.focus_height, true); //1 mm above PCB

            CalibrationPoints.Clear();   // Presumably user changed the needle, and calibration is void no matter if we succeed here
            Calibrated = false;

            for (int i = 0; i <= 3600; i = i + 225) {
                NeedlePoint Point = new NeedlePoint();
                Point.A = i / 10.0;

                if (!MainForm.Cnc.CNC_A(Point.A)) return false;
                //detect average of 3 measurements
                var circle = VideoDetection.GetClosestAverageCircle(MainForm.cameraView.upVideoProcessing, Tolerance, 3);

                if (circle == null) {
                    MainForm.ShowSimpleMessageBox("Needle Calibration: Can't see needle at angle " + Point.A + " - aborting");
                    return false;
                }

                circle.ToMMResolution();
                Point.X = circle.X;
                Point.Y = circle.Y;

                // display point
                var pt = circle.Clone().ToScreenResolution().ToPartLocation().ToPointF();
                MainForm.DisplayText("circle @ " + circle + "\tx @ " + pt.X + "," + pt.Y);
                MainForm.cameraView.upVideoProcessing.MarkA.Add(pt);

                CalibrationPoints.Add(Point);
            }
            Calibrated = true;
            MainForm.Cnc.Zup();
            MainForm.cameraView.SetUpCameraDefaults();

            return true;
        }
Exemple #3
0
        public bool Calibrate(double Tolerance)
        {
            CalibrationPoints.Clear();   // Presumably user changed the needle, and calibration is void no matter if we succeed here
            Calibrated = false;
            if (!Cam.IsRunning())
            {
                MainForm.ShowMessageBox(
                    "Attempt to calibrate needle, camera is not running.",
                    "Camera not running",
                    MessageBoxButtons.OK);
                return false;
            }

            double X = 0;
            double Y = 0;
            int res = 0; ;
            for (int i = 0; i <= 3600; i = i + 225)
            {
                NeedlePoint Point = new NeedlePoint();
                Point.Angle = Convert.ToDouble(i) / 10.0;
                if (!CNC_A_m(Point.Angle))
                {
                    return false;
                }
                for (int tries = 0; tries < 10; tries++)
                {
                    Thread.Sleep(100);
                    res = Cam.GetClosestCircle(out X, out Y, Tolerance);
                    if (res != 0)
                    {
                        break;
                    }

                    if (tries >= 9)
                    {
                        MainForm.ShowMessageBox(
                            "Needle calibration: Can't see Needle",
                            "No Circle found",
                            MessageBoxButtons.OK);
                        return false;
                    }
                }
                if (res == 0)
                {
                    MainForm.ShowMessageBox(
                        "Needle Calibration: Can't find needle",
                        "No Circle found",
                        MessageBoxButtons.OK);
                    return false;
                }
                //if (res > 1)
                //{
                //    MessageBox.Show(
                //        "Needle Calibration: Ambiguous regognition result",
                //        "Too macy circles in focus",
                //        MessageBoxButtons.OK);
                //    return false;
                //}

                Point.X = X * Properties.Settings.Default.UpCam_XmmPerPixel;
                Point.Y = Y * Properties.Settings.Default.UpCam_YmmPerPixel;
                // MainForm.DisplayText("A: " + Point.Angle.ToString("0.000") + ", X: " + Point.X.ToString("0.000") + ", Y: " + Point.Y.ToString("0.000"));
                CalibrationPoints.Add(Point);
            }
            Calibrated = true;
            return true;
        }
Exemple #4
0
        public bool Calibrate(double Tolerance)
        {
            CalibrationPoints.Clear();   // Presumably user changed the needle, and calibration is void no matter if we succeed here
            Calibrated = false;
            if (!Cam.IsRunning())
            {
                MainForm.ShowMessageBox(
                    "Attempt to calibrate needle, camera is not running.",
                    "Camera not running",
                    MessageBoxButtons.OK);
                return(false);
            }

            double X   = 0;
            double Y   = 0;
            int    res = 0;;

            for (int i = 0; i <= 3600; i = i + 225)
            {
                NeedlePoint Point = new NeedlePoint();
                Point.Angle = Convert.ToDouble(i) / 10.0;
                if (!CNC_A_m(Point.Angle))
                {
                    return(false);
                }
                for (int tries = 0; tries < 10; tries++)
                {
                    Thread.Sleep(100);
                    res = Cam.GetClosestCircle(out X, out Y, Tolerance);
                    if (res != 0)
                    {
                        break;
                    }

                    if (tries >= 9)
                    {
                        MainForm.ShowMessageBox(
                            "Needle calibration: Can't see Needle",
                            "No Circle found",
                            MessageBoxButtons.OK);
                        return(false);
                    }
                }
                if (res == 0)
                {
                    MainForm.ShowMessageBox(
                        "Needle Calibration: Can't find needle",
                        "No Circle found",
                        MessageBoxButtons.OK);
                    return(false);
                }
                //if (res > 1)
                //{
                //    MessageBox.Show(
                //        "Needle Calibration: Ambiguous regognition result",
                //        "Too macy circles in focus",
                //        MessageBoxButtons.OK);
                //    return false;
                //}

                Point.X = X * Properties.Settings.Default.UpCam_XmmPerPixel;
                Point.Y = Y * Properties.Settings.Default.UpCam_YmmPerPixel;
                // MainForm.DisplayText("A: " + Point.Angle.ToString("0.000") + ", X: " + Point.X.ToString("0.000") + ", Y: " + Point.Y.ToString("0.000"));
                CalibrationPoints.Add(Point);
            }
            Calibrated = true;
            return(true);
        }
Exemple #5
0
        public bool Calibrate(double Tolerance)
        {
            if (NeedleAlwaysCalibrated || MainForm.Cnc.Simulation)
            {
            /*                for (int i = 0; i <= 3600; i = i + 225)
                {
                    NeedlePoint Point = new NeedlePoint();
                    Point.A = i / 10.0;
                    Point.X = 0;
                    Point.Y = 0;
                    CalibrationPoints.Add(Point);
                }*/
                NeedlePoint Point = new NeedlePoint();
                Point.X = -0.22; Point.Y = 0.08; Point.A = 0;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = -0.07; Point.Y = 0.18; Point.A = 22.5;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = 0.05; Point.Y = 0.21; Point.A = 45;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = 0.1; Point.Y = 0.23; Point.A = 67.5;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = 0.18; Point.Y = 0.17; Point.A = 90;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = 0.22; Point.Y = 0.09; Point.A = 112.50;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = 0.23; Point.Y = -0.04; Point.A = 135;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = 0.22; Point.Y = -0.13; Point.A = 157.5;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = 0.23; Point.Y = -0.24; Point.A = 180;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = 0.14; Point.Y = -0.34; Point.A = 202.5;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = -0.02; Point.Y = -0.28; Point.A = 225;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = -0.12; Point.Y = -0.19; Point.A =247.50;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = -0.23; Point.Y = -0.07; Point.A = 270;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = -0.24; Point.Y = -0.01; Point.A = 292.5;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = -0.24; Point.Y = 0.05; Point.A = 315;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = -0.18; Point.Y = 0.10; Point.A = 337.5;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();
                Point.X = -0.09; Point.Y = 0.18; Point.A = 360;
                CalibrationPoints.Add(Point);
                Point = new NeedlePoint();

                Calibrated = true;
                return true;
            }

            //setup camera
            MainForm.cameraView.UpCameraReset();
            if (nozzleChanger.Enabled == false)
            {
                MainForm.cameraView.SetUpCameraFunctionSet("Needle");
            }
            else
            {
                Nozzle nozzle = nozzleChanger.GetLoadedNozzle();
                if (nozzle != null) { MainForm.cameraView.SetUpCameraFunctionSet(nozzle.NozzleFilter); }
            }
            MainForm.cameraView.downSettings.FindCircles = true;

            // we are already @ upcamera position
            MainForm.Cnc.Zup();
            Global.GoTo("Up Camera");

            MainForm.Cnc.ZGuardOn();

            MainForm.Cnc.Zdown(Settings.Default.focus_height, true); //1 mm above PCB

            CalibrationPoints.Clear();   // Presumably user changed the needle, and calibration is void no matter if we succeed here
            Calibrated = false;

            for (int i = 0; i <= 3600; i = i + 225) {
                NeedlePoint Point = new NeedlePoint();
                Point.A = i / 10.0;
                if (Point.A > 360) { Point.A -= 360;  }

                if (!MainForm.Cnc.CNC_A(Point.A)) return false;
                //detect average of 3 measurements
                var circle = VideoDetection.GetClosestAverageCircle(MainForm.cameraView.upVideoProcessing, Tolerance, 3);

                if (circle == null) {
                    MainForm.ShowSimpleMessageBox("Needle Calibration: Can't see needle at angle " + Point.A + " - aborting");
                    return false;
                }

                circle.ToMMResolution();
                Point.X = circle.X;
                Point.Y = circle.Y;

                // display point
                var pt = circle.Clone().ToScreenResolution().ToPartLocation().ToPointF();
                MainForm.DisplayText("circle @ " + circle + "\tx @ " + pt.X + "," + pt.Y);
                MainForm.cameraView.upVideoProcessing.MarkA.Add(pt);

                CalibrationPoints.Add(Point);
            }

            // Calculate average midpoint
            double AverageX = 0, AverageY = 0;
            for (int i = 0; i < CalibrationPoints.Count; i = i + 1)
            {
                AverageX += CalibrationPoints[i].X;
                AverageY += CalibrationPoints[i].Y;
            }
            AverageX = AverageX / (CalibrationPoints.Count);
            AverageY = AverageY / (CalibrationPoints.Count);

            // Subtract average midpoint from all calibrationpoints
            for (int i = 0; i < CalibrationPoints.Count; i = i + 1)
            {
                CalibrationPoints[i].X -= AverageX;
                CalibrationPoints[i].Y -= AverageY;
            }

            Calibrated = true;
            MainForm.Cnc.Zup();
            MainForm.cameraView.SetUpCameraDefaults();

            return true;
        }