Exemple #1
0
        // ========================================================================================
        // NeedleToNextPart_m(): Takes needle to exact location of the part, tape rotation taken in to account.
        // The position is measured using tape holes and knowledge about tape width and pitch (see EIA-481 standard).
        // Id tells the tape name.
        public bool NeedleToNextPart_m(TapeObj to)
        {
            var loc = GetNextComponentPartLocation(to);

            if (loc == null)
            {
                return(false);
            }
            if (!Needle.Move_m(loc))
            {
                return(false);
            }
            // Increment Part
            to.IncrementPartNumber();
            return(true);
        }
Exemple #2
0
        // ========================================================================================
        // GotoNextPartByMeasurement_m(): Takes needle to exact location of the part, tape and part rotation taken in to account.
        // The hole position is measured on each call using tape holes and knowledge about tape width and pitch (see EIA-481 standard).
        // Id tells the tape name.
        // The caller needs the hole coordinates and tape number later in the process, but they are measured and returned here.
        public bool GotoNextPartByMeasurement_m(int TapeNumber, out double HoleX, out double HoleY)
        {
            HoleX = 0;
            HoleY = 0;
            // Go to next hole approximate location:
            if (!SetCurrentTapeMeasurement_m(TapeNumber))              // having the measurement setup here helps with the automatic gain lag
            {
                return(false);
            }

            double NextX = 0;
            double NextY = 0;

            if (!double.TryParse(Grid.Rows[TapeNumber].Cells["NextX_Column"].Value.ToString(), out NextX))
            {
                MainForm.ShowMessageBox(
                    "Bad data at Tape " + Grid.Rows[TapeNumber].Cells["IdColumn"].Value.ToString() + ", Next X",
                    "Tape data error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }

            if (!double.TryParse(Grid.Rows[TapeNumber].Cells["NextY_Column"].Value.ToString(), out NextY))
            {
                MainForm.ShowMessageBox(
                    "Bad data at Tape " + Grid.Rows[TapeNumber].Cells["IdColumn"].Value.ToString() + ", Next Y",
                    "Tape data error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }
            // Go there:
            if (!MainForm.CNC_XY_m(NextX, NextY))
            {
                return(false);
            }
            ;

            // Get hole exact location:
            // We want to find the hole less than 2mm from where we think it should be. (Otherwise there is a risk
            // of picking a wrong hole.)
            if (!MainForm.GoToCircleLocation_m(1.8, 0.5, out HoleX, out HoleY))
            {
                MainForm.ShowMessageBox(
                    "Can't find tape hole",
                    "Tape error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }
            // The hole locations are:
            HoleX = Cnc.CurrentX + HoleX;
            HoleY = Cnc.CurrentY + HoleY;

            // ==================================================
            // find the part location and go there:
            double PartX = 0.0;
            double PartY = 0.0;
            double A     = 0.0;

            if (!GetPartLocationFromHolePosition_m(TapeNumber, HoleX, HoleY, out PartX, out PartY, out A))
            {
                MainForm.ShowMessageBox(
                    "Can't find tape hole",
                    "Tape error",
                    MessageBoxButtons.OK
                    );
            }

            // Now, PartX, PartY, A tell the position of the part. Take needle there:
            if (!Needle.Move_m(PartX, PartY, A))
            {
                return(false);
            }

            return(true);
        }               // end GotoNextPartByMeasurement_m
Exemple #3
0
        // ========================================================================================
        // GotoNextPart_m(): Takes needle to exact location of the part, tape rotation taken in to account.
        // The position is measured using tape holes and knowledge about tape width and pitch (see EIA-481 standard).
        // Id tells the tape name.
        public bool GotoNextPart_m(string Id)
        {
            int Tape = 0;

            MainForm.DisplayText("GotoNextPart_m(), tape id: " + Id);
            if (!IdValidates_m(Id, out Tape))
            {
                return(false);
            }
            // goto next hole approximate location:
            if (!SetCurrentTapeMeasurement_m(Tape))              // having the measurement setup here helps with the automatic gain lag
            {
                return(false);
            }

            double X = 0;
            double Y = 0;

            if (!double.TryParse(Grid.Rows[Tape].Cells["NextX_Column"].Value.ToString(), out X))
            {
                MessageBox.Show(
                    "Bad data at Tape " + Tape.ToString() + ", Next X",
                    "Tape data error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }

            if (!double.TryParse(Grid.Rows[Tape].Cells["NextY_Column"].Value.ToString(), out Y))
            {
                MessageBox.Show(
                    "Bad data at Tape " + Tape.ToString() + ", Next Y",
                    "Tape data error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }
            // Go:
            if (!MainForm.CNC_XY_m(X, Y))
            {
                return(false);
            }
            ;

            // goto hole exact location:
            // We want to find the hole less than 2mm from where we think it should be. (Otherwise there is a risk
            // of picking a wrong hole.)
            if (!MainForm.GoToCircleLocation_m(1.8, 0.5, out X, out Y))
            {
                MessageBox.Show(
                    "Can't find tape hole",
                    "Tape error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }

            // Get the hole location, we'll need it later:
            X = Cnc.CurrentX + X;
            Y = Cnc.CurrentY + Y;

            //MessageBox.Show(
            //    "exactly over the hole",
            //    "test",
            //    MessageBoxButtons.OK
            //);

            // ==================================================
            // find the part location and go there:

            string Width = Grid.Rows[Tape].Cells["WidthColumn"].Value.ToString();
            // Tape measurements:
            double dL = 2.0;        // Part center pos from hole, tape lenght direction; 2.0mm in all tape types,
            // except when 2mm part pitch. See below.
            double dW;              // Part center pos from hole, tape width direction. Varies.
            int    Pitch;           // Distance from one part to another

            switch (Width)
            {
            case "8/2mm":
                dW    = 3.50;
                Pitch = 2;
                break;

            case "8/4mm":
                dW    = 3.50;
                Pitch = 4;
                break;

            case "12/4mm":
                dW    = 5.50;
                Pitch = 4;
                break;

            case "12/8mm":
                dW    = 5.50;
                Pitch = 8;
                break;

            case "16/4mm":
                dW    = 7.50;
                Pitch = 4;
                break;

            case "16/8mm":
                dW    = 7.50;
                Pitch = 8;
                break;

            case "16/12mm":
                dW    = 7.50;
                Pitch = 12;
                break;

            case "24/4mm":
                dW    = 11.50;
                Pitch = 4;
                break;

            case "24/8mm":
                dW    = 11.50;
                Pitch = 8;
                break;

            case "24/12mm":
                dW    = 11.50;
                Pitch = 12;
                break;

            case "24/16mm":
                dW    = 11.50;
                Pitch = 16;
                break;

            case "24/20mm":
                dW    = 11.50;
                Pitch = 20;
                break;

            default:
                MessageBox.Show(
                    "Bad data at Tape #" + Tape.ToString() + ", Width",
                    "Tape data error",
                    MessageBoxButtons.OK
                    );
                return(false);
                // break;
            }
            // Tape orientation:
            // +Y: Holeside of tape is right, part is dW(mm) to left, dL(mm) down from hole, A= 0
            // +X: Holeside of tape is down, part is dW(mm) up, dL(mm) to left from hole, A= -90
            // -Y: Holeside of tape is left, part is dW(mm) to right, dL(mm) up from hole, A= -180
            // -X: Holeside of tape is up, part is dW(mm) down, dL(mm) to right from hole, A=-270
            double A   = 0.0;
            int    pos = 0;

            if (!int.TryParse(Grid.Rows[Tape].Cells["Next_Column"].Value.ToString(), out pos))
            {
                MessageBox.Show(
                    "Bad data at Tape " + Tape.ToString() + ", Next",
                    "Tape data error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }
            if ((Pitch == 2) && ((pos % 2) == 0))
            {
                dL = 0.0;
            }
            ;

            double partX = 0;
            double partY = 0;

            switch (Grid.Rows[Tape].Cells["OrientationColumn"].Value.ToString())
            {
            case "+Y":
                partX = X - dW;
                partY = Y - dL;
                A     = 0.0;
                break;

            case "+X":
                partX = X - dL;
                partY = Y + dW;
                A     = -90.0;
                break;

            case "-Y":
                partX = X + dW;
                partY = Y + dL;
                A     = -180.0;
                break;

            case "-X":
                partX = X + dL;
                partY = Y - dW;
                A     = -270.0;
                break;

            default:
                MessageBox.Show(
                    "Bad data at Tape #" + Tape.ToString() + ", Orientation",
                    "Tape data error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }
            // rotation:
            if (Grid.Rows[Tape].Cells["RotationColumn"].Value == null)
            {
                MessageBox.Show(
                    "Bad data at tape " + Id + " rotation",
                    "Assertion error",
                    MessageBoxButtons.OK
                    );
                return(false);
            }
            switch (Grid.Rows[Tape].Cells["RotationColumn"].Value.ToString())
            {
            case "0deg.":
                break;

            case "90deg.":
                A += 90.0;
                break;

            case "180deg.":
                A += 180.0;
                break;

            case "270deg.":
                A += 270.0;
                break;

            default:
                MessageBox.Show(
                    "Bad data at Tape " + Id + " rotation",
                    "Tape data error",
                    MessageBoxButtons.OK
                    );
                return(false);
                // break;
            }
            ;
            while (A > 360.1)
            {
                A -= 360.0;
            }
            while (A < 0.0)
            {
                A += 360.0;
            }
            ;

            // Now, partX, partY, A tell the position of the part. Take needle there:
            if (!Needle.Move_m(partX, partY, A))
            {
                return(false);
            }

            // ==================================================
            // X, Y still are the current hole location, Pitch is the part size increment and pos the current part count
            // Set next hole approximate location. On 2mm part pitch, increment only at even part count.
            if (Pitch == 2)
            {
                if ((pos % 2) != 0)
                {
                    Pitch = 0;
                }
                else
                {
                    Pitch = 4;
                }
            }
            ;
            switch (Grid.Rows[Tape].Cells["OrientationColumn"].Value.ToString())
            {
            case "+Y":
                Y = Y + Pitch;
                break;

            case "+X":
                X = X + Pitch;
                break;

            case "-Y": Y = Y - Pitch;
                break;

            case "-X":
                X = X - Pitch;
                break;
            }
            ;
            Grid.Rows[Tape].Cells["NextX_Column"].Value = X.ToString();
            Grid.Rows[Tape].Cells["NextY_Column"].Value = Y.ToString();
            // increment next count
            pos++;
            Grid.Rows[Tape].Cells["Next_Column"].Value = pos.ToString();
            return(true);
        }               // end GotoNextPart_m