Пример #1
0
        static void AlignPart()
        {
            channel.SetCoords(e: 0);
            Native.MinRect mr       = new Native.MinRect();
            Native.MinRect mr2      = new Native.MinRect();
            Camera         u        = settings.upCamera;
            Tape           t        = tapes[state.lastTape];
            decimal        w        = Math.Max(t.partRects[0].width, t.partRects[0].height);
            int            partsize = (int)(t.partRects[0].width * t.partRects[0].height * u.xPixelPerMm * u.yPixelPerMm);
            int            ww       = (int)((w * 1.4m + 1) * u.xPixelPerMm);

            Native.get_minrect(1, ww, ww, t.threshold1, t.threshold2, t.gauss1, t.gauss2, 25, partsize, 5, mr);
            int angle = mr.angle < -45 ? (mr.angle + 90) : mr.angle;

            if (angle > 17 || angle < -17)
            {
                Error("Part angle too big: " + angle);
                return;
            }
            if ((w > 2 && angle != settings.zeroAngle) || angle > 3 || angle < -3)
            {
                channel.MoveTo(e: PartAngleToPnpAngle(-angle + settings.zeroAngle), s: 10000);
                channel.WaitForDone();
                Native.get_minrect(1, ww, ww, t.threshold1, t.threshold2, t.gauss1, t.gauss2, 25, partsize, 5, mr2);
            }
            else
            {
                mr2 = mr;
            }
            decimal sx = Decimal.Round((mr2.xc - u.resolutionX / 2) / u.xPixelPerMm, 2);
            decimal sy = -Decimal.Round((mr2.yc - u.resolutionY / 2) / u.yPixelPerMm, 2);

            Native.DrawText(420, 810, 1, 0, "Angle: " + angle + " (" + sx + "," + sy + ")  " + mr.size + "                  ");
            Native.DrawLine(mr.x1 / 2 + 200, mr.y1 / 2 + 150, mr.x2 / 2 + 200, mr.y2 / 2 + 150, 3);
            Native.DrawLine(mr.x3 / 2 + 200, mr.y3 / 2 + 150, mr.x2 / 2 + 200, mr.y2 / 2 + 150, 3);
            Native.DrawLine(mr.x3 / 2 + 200, mr.y3 / 2 + 150, mr.x4 / 2 + 200, mr.y4 / 2 + 150, 3);
            Native.DrawLine(mr.x1 / 2 + 200, mr.y1 / 2 + 150, mr.x4 / 2 + 200, mr.y4 / 2 + 150, 3);
            if (Math.Abs(sx) > 0.6m || Math.Abs(sy) > 0.6m)
            {
                Error("Part misalignment too big: " + sx + ", " + sy);
                return;
            }
            partOffsetX = sx + settings.fineOffsetX + t.visionXOffset;
            partOffsetY = sy + settings.fineOffsetY + t.visionYOffset;
        }
Пример #2
0
        static void FindPart()
        {
            Camera u = settings.upCamera;

            Native.MinRect mr       = new Native.MinRect();
            Tape           t        = tapes[state.lastTape];
            decimal        w        = Math.Max(t.partRects[0].width, t.partRects[0].height);
            int            partsize = (int)(t.partRects[0].width * t.partRects[0].height * u.xPixelPerMm * u.yPixelPerMm);
            int            ww       = (int)((w * 1.4m + 1) * u.xPixelPerMm);

            Native.get_minrect(1, ww, ww, t.threshold1, t.threshold2, t.gauss1, t.gauss2, 45, partsize, 5, mr);
            int     angle = mr.angle < -45 ? (mr.angle + 90) : mr.angle;
            decimal sx    = Decimal.Round((mr.xc - u.resolutionX / 2) / u.xPixelPerMm, 2);
            decimal sy    = -Decimal.Round((mr.yc - u.resolutionY / 2) / u.yPixelPerMm, 2);

            Native.DrawText(420, 810, 1, 0, "Angle: " + angle + " (" + sx + "," + sy + ")  " + mr.size + "                  ");
            Native.DrawLine(mr.x1 / 2 + 200, mr.y1 / 2 + 150, mr.x2 / 2 + 200, mr.y2 / 2 + 150, 3);
            Native.DrawLine(mr.x3 / 2 + 200, mr.y3 / 2 + 150, mr.x2 / 2 + 200, mr.y2 / 2 + 150, 3);
            Native.DrawLine(mr.x3 / 2 + 200, mr.y3 / 2 + 150, mr.x4 / 2 + 200, mr.y4 / 2 + 150, 3);
            Native.DrawLine(mr.x1 / 2 + 200, mr.y1 / 2 + 150, mr.x4 / 2 + 200, mr.y4 / 2 + 150, 3);
        }