Beispiel #1
0
        static void CenterPart()
        {
            Tape t      = tapes[state.lastTape];
            var  retval = new Native.Vec2();

            if (t.xOffset == 0 && t.yOffset == 0)
            {
                int fx = (int)(settings.downCamera.xPixelPerMm * t.partRects[0].width * 1.2m);
                int fy = (int)(settings.downCamera.yPixelPerMm * t.partRects[0].height * 1.2m);
                Native.findrectangle(0, fx, fy, 20, 20, fx * 4, fy * 4, retval);
            }
            else
            {
                int fx = (int)(settings.downCamera.xPixelPerMm * 1.6m);
                int fy = (int)(settings.downCamera.yPixelPerMm * 1.6m);
                Native.findcircle(0, fx / 2, 12, fx * 2, fy * 2, settings.downCamera.threshold1, settings.downCamera.threshold2, retval);
            }
            decimal mx = Decimal.Round(retval.x / settings.downCamera.xPixelPerMm, 2);
            decimal my = Decimal.Round(retval.y / settings.downCamera.yPixelPerMm, 2);

            Native.DrawText(1200, 810, 1, 0, "Got: " + mx + "  " + my);
            if (Math.Abs(mx) > 1 || Math.Abs(my) > 1)
            {
                Error("Part alignment too big: " + mx + ", " + my);
                return;
            }
            channel.Move(x: mx, y: my, s: 1000);
            updateState();
        }
Beispiel #2
0
        static void CorrectUpCam()
        {
            int dx = (int)(settings.downCamera.xPixelPerMm * 1.0m);

            Native.Vec2 retval = new Native.Vec2();
            Native.findcheck(0, settings.markXOffset, settings.markYOffset, dx, dx, dx * 4, dx * 4, retval);
            decimal mx = Decimal.Round(retval.x / settings.downCamera.xPixelPerMm, 2);
            decimal my = Decimal.Round(retval.y / settings.downCamera.yPixelPerMm, 2);

            Native.DrawText(820, 560, 1, 0, "Camera Got: " + mx + "  " + my);
            if (Math.Abs(mx) > 0.8m || Math.Abs(my) > 0.8m)
            {
                Error("Camera correction too big: " + mx + ", " + my);
                return;
            }
            channel.Move(x: mx, y: my, s: 1000);
            channel.SetCoords(x: settings.upCamera.xOffset, y: settings.upCamera.yOffset);
            updateState();
        }
Beispiel #3
0
        static void AlignFid(int fi)
        {
            int fx     = (int)(settings.downCamera.xPixelPerMm / 2 * 1.0m);
            var retval = new Native.Vec2();

            Native.findcircle(0, fx / 2, 12, fx * 4, fx * 4, settings.downCamera.threshold1, settings.downCamera.threshold2, retval);
            decimal mx = Decimal.Round(retval.x / settings.downCamera.xPixelPerMm, 2);
            decimal my = Decimal.Round(retval.y / settings.downCamera.yPixelPerMm, 2);

            Native.DrawText(820, 500, 1, 0, "Got: " + mx + "  " + my);
            if (Math.Abs(mx) < 0.5m && Math.Abs(my) < 0.5m)
            {
                channel.Move(x: mx, y: my, s: 1000);
                updateState();
                state.fiducials[fi].realX = channel.posX;
                state.fiducials[fi].realY = channel.posY;
                board.fiducials[fi].realX = channel.posX;
                board.fiducials[fi].realY = channel.posY;
                return;
            }
            Error("Fiducial correction too big: " + mx + ", " + my);
        }
Beispiel #4
0
        static void BoardCallback(long data)
        {
            if (board == null || board.steps == null || board.steps.Count == 0 || board.fiducials == null || board.fiducials.Count == 0)
            {
                return;
            }
            switch (data & 255)
            {
            case 1:
                state.lastStep--;
                if (state.lastStep <= 0)
                {
                    state.lastStep = 0;
                }
                break;

            case 2:
                state.lastStep++;
                if (state.lastStep >= board.steps.Count - 1)
                {
                    state.lastStep = board.steps.Count - 1;
                }
                break;

            case 3:
                Placement pl = board.steps[state.lastStep];
                var       tp = boardPosToPnpPos(pl.posX, pl.posY);
                channel.MoveTo(x: tp.Item1, y: tp.Item2, s: settings.speed);
                updateState();
                break;

            case 4:
                state.lastFid--;
                if (state.lastFid <= 0)
                {
                    state.lastFid = 0;
                }
                break;

            case 5:
                state.lastFid++;
                if (state.lastFid >= board.fiducials.Count - 1)
                {
                    state.lastFid = board.fiducials.Count - 1;
                }
                break;

            case 6:
                Run(() => MoveToFid(state.lastFid));
                break;

            case 7:
                Run(() => AlignFid(state.lastFid));
                break;

            case 8:
                var xy = CalcPartRelative();
                channel.MoveTo(x: xy.Item1, y: xy.Item2, s: settings.speed);
                updateState();
                break;

            case 9:
                Fiducial f  = board.fiducials[state.lastFid];
                var      tf = boardPosToPnpPos(f.posX, f.posY);
                settings.boardZeroX += state.lastX - tf.Item1;
                settings.boardZeroY += state.lastY - tf.Item2;
                break;

            case 10:
                Run(() => MoveToFidReal(state.lastFid));
                break;

            case 11:
                Native.Vec2 retval = new Native.Vec2();
                Native.findsymmetry(0, 50, 50, 100, 100, retval);
                Native.findsymmetry(1, 50, 50, 100, 100, retval);
                Native.save_screen("test.bmp");
                break;

            case 20:
                Run(AlignUpCam);
                break;

            case 21:
                Run(CorrectUpCam);
                break;
            }
            updateBoard();
        }
Beispiel #5
0
        static void TapeCallback(long data)
        {
            if (tapes == null || tapes.Count == 0)
            {
                return;
            }
            Tape t = tapes[state.lastTape];

            switch (data & 255)
            {
            case 1:
                state.lastTape--;
                if (state.lastTape <= 0)
                {
                    state.lastTape = 0;
                }
                updateCameras();
                break;

            case 2:
                state.lastTape++;
                if (state.lastTape >= tapes.Count - 1)
                {
                    state.lastTape = tapes.Count - 1;
                }
                updateCameras();
                break;

            case 3:
                if (t.lastPartX == 0)
                {
                    if (t.x1 == 0)
                    {
                        return;
                    }
                    t.lastPartX = t.x1;
                    t.lastPartY = t.y1;
                }
                channel.MoveTo(x: t.lastPartX, y: t.lastPartY, s: settings.speed);
                updateState();
                break;

            case 4:
                t.x1 = state.lastX;
                t.y1 = state.lastY;
                break;

            case 5:
                t.x2 = state.lastX;
                t.y2 = state.lastY;
                break;

            case 6:
                t.lastPartX = state.lastX;
                t.lastPartY = state.lastY;
                break;

            case 7:
                t.lastDeltaX = state.lastX - t.x1;
                t.lastDeltaY = state.lastY - t.y1;
                break;

            case 8:
                t.zOffset = state.lastZ;
                break;

            case 9:
                CenterPart();
                break;

            case 10:
                if (t.x1 == 0)
                {
                    return;
                }
                channel.MoveTo(x: t.x1, y: t.y1, s: settings.speed);
                updateState();
                break;

            case 11:
                channel.Move(x: -t.lastDeltaX, y: -t.lastDeltaY, s: settings.speed);
                updateState();
                break;

            case 12:
                channel.Move(x: t.lastDeltaX, y: t.lastDeltaY, s: settings.speed);
                updateState();
                break;

            case 20:
                Native.Vec2 retval = new Native.Vec2();
                int         sx     = (int)(settings.downCamera.xPixelPerMm * 1.5m);
                int         sy     = (int)(settings.downCamera.yPixelPerMm * 1.5m);
                //Native.findrectangle(0, sx, sy, 10, 10, sx * 2, sy * 4, retval);
                Native.findcircle(0, sx / 2, 12, sx * 2, sy * 4, settings.downCamera.threshold1, settings.downCamera.threshold2, retval);
                decimal mx = Decimal.Round(retval.x / settings.downCamera.xPixelPerMm, 2);
                decimal my = Decimal.Round(retval.y / settings.downCamera.yPixelPerMm, 2);
                Native.DrawText(1200, 810, 1, 0, "Got: " + mx + "  " + my);
                if (Math.Abs(mx) < 1 && Math.Abs(my) < 4)
                {
                    channel.Move(x: mx, y: my, s: 1000);
                    updateState();
                }
                break;
            }
            updateTape();
        }