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);
        }
        public static PartLocation UpCamera_Calibration(CameraView cv, double moveDistance)
        {
            var cnc = Global.Instance.cnc;

            cv.SetUpCameraFunctionSet("Needle");
            // move to upcamera position
            cnc.Zup();
            Global.GoTo("Up Camera");
            cnc.Zdown(Settings.Default.focus_height, true);
            // do calibration
            var ret = DoCameraCalibration(cv.upVideoProcessing, new PartLocation(moveDistance, moveDistance));

            cnc.Zup();
            cv.UpCameraReset();
            return(ret);
        }
        public static void UpCamera_MultiCalibration(CameraView cv, double moveDistance)
        {
            var cnc = Global.Instance.cnc;

            cv.SetUpCameraFunctionSet("Needle");
            // move to upcamera position

            for (int z = 0; z < 30; z += 5)
            {
                Global.GoTo("Up Camera");
                cnc.ZGuardOff();
                cnc.CNC_Z(z);
                var ret = DoCameraCalibration(cv.upVideoProcessing, new PartLocation(moveDistance, .1));
                Global.Instance.mainForm.ShowSimpleMessageBox(String.Format("z={0}  dx={1}  dy={2}", z, ret.X, ret.Y));
            }

            cnc.Zup();
            cv.UpCameraReset();
        }
        public static void DoNeedleErrorMeasurement(VideoProcessing vp)
        {
            var          cnc = Global.Instance.cnc;
            var          originalLocation = cnc.XYALocation;
            PartLocation testLocation     = Global.GoTo("Up Camera");

            cnc.Zdown(Properties.Settings.Default.focus_height, true);

            // setup camera
            vp.SetFunctionsList("Needle");
            vp.s.FindCircles = true;
            vp.s.Draw1mmGrid = true;
            var Needle = Global.Instance.needle;

            List <PartLocation> offsetError = new List <PartLocation>();

            for (int i = 0; i <= 360; i += 45)
            {
                testLocation.A = i;
                var pp = testLocation - Needle.NeedleOffset;

                Needle.Move_m(pp); // move to target
                // mark erro
                var circle = VideoDetection.GetClosestCircle(vp, 10);
                if (circle != null)
                {
                    vp.MarkA.Add(circle.ToScreenResolution().ToPartLocation().ToPointF());

                    circle.ToMMResolution();
                    offsetError.Add(circle.ToPartLocation());
                }
                Thread.Sleep(500); //wait 1 second
            }

            Global.Instance.mainForm.ShowSimpleMessageBox("Upcamera offset Error is " + PartLocation.Average(offsetError) + "\nMax Error is " + PartLocation.MaxValues(offsetError));

            cnc.Zup();
            cnc.CNC_XYA(originalLocation);

            //revert to previous state
            vp.Reset();
        }