Beispiel #1
0
        // will only work with downcamera
        public Shapes.Thing GoToClosestThing(Shapes.ShapeTypes type, double FindTolerance, double MoveTolerance, VideoProcessing vp = null, string template = null, double threshold = -1) {
            DisplayText("GoToThing(" + type + "), FindTolerance: " + FindTolerance + ", MoveTolerance: " + MoveTolerance, Color.Orange);
            vp = vp ?? cameraView.downVideoProcessing;
            Shapes.Thing thing = null;
            double dir = (vp.IsUpCamera()) ? -1 : 1;
            
            for (int i = 0; i < 8; i++) { //move up to 8 times
                Global.DoBackgroundWork();
                thing = VideoDetection.FindClosest(vp, type, FindTolerance, 2, template, threshold);

                if (thing == null) break; //couldn't find

                thing.ToMMResolution();
                DisplayText("--> round " + i + ", offset= " + thing.ToPartLocation() + " dist/tol = " + thing.ToPartLocation().VectorLength().ToString("F2") + " of " + FindTolerance);

                // If we are further than move tolerance, go there, else end loop
                if (thing.ToPartLocation().VectorLength() > MoveTolerance) {
                    Console.WriteLine("\tmoving by " + thing.ToPartLocation());
                    Cnc.CNC_XY(Cnc.XYLocation + (dir * thing.ToPartLocation()));
                } else break;
            }

            //if (thing == null)  ShowSimpleMessageBox("Optical positioning: Process is unstable, result is unreliable!");
            if (thing != null) thing.AddOffset(Cnc.XYLocation);

            return thing;
        }