// ======================================================================================== // ======================================================================================== // GetPartHole_m(): Measures X,Y location of the hole corresponding to part number public bool GetPartHole_m(int TapeNum, int PartNum, out double ResultX, out double ResultY) { ResultX = 0.0; ResultY = 0.0; // Get start points double X = 0.0; double Y = 0.0; if (!double.TryParse(Grid.Rows[TapeNum].Cells["FirstX_Column"].Value.ToString().Replace(',', '.'), out X)) { MainForm.ShowMessageBox( "Bad data at Tape " + TapeNum.ToString() + ", X", "Tape data error", MessageBoxButtons.OK ); return(false); } if (!double.TryParse(Grid.Rows[TapeNum].Cells["FirstY_Column"].Value.ToString().Replace(',', '.'), out Y)) { MainForm.ShowMessageBox( "Bad data at Tape " + TapeNum.ToString() + ", Y", "Tape data error", MessageBoxButtons.OK ); return(false); } // Get the hole location guess double dW; double Pitch; double FromHole; if (!GetTapeParameters_m(TapeNum, out dW, out FromHole, out Pitch)) { return(false); } if (Math.Abs(Pitch - 2.0) < 0.01) // if pitch ==2 { PartNum = (PartNum + 1) / 2; Pitch = 4.0; } double dist = (double)(PartNum - 1) * Pitch; // This many mm's from start switch (Grid.Rows[TapeNum].Cells["Orientation_Column"].Value.ToString()) { case "+Y": Y = Y + dist; break; case "+X": X = X + dist; break; case "-Y": Y = Y - dist; break; case "-X": X = X - dist; break; default: MainForm.ShowMessageBox( "Bad data at Tape #" + TapeNum.ToString() + ", Orientation", "Tape data error", MessageBoxButtons.OK ); return(false); } // X, Y now hold the first guess // Measuring if (!SetCurrentTapeMeasurement_m(TapeNum)) // having the measurement setup here helps with the automatic gain lag { return(false); } // Go there: if (!MainForm.CNC_XY_m(X, Y)) { return(false); } ; // get hole exact location: if (!MainForm.GoToFeatureLocation_m(FormMain.FeatureType.Circle, 1.8, 0.1, out X, out Y)) { MainForm.ShowMessageBox( "Can't find tape hole", "Tape error", MessageBoxButtons.OK ); return(false); } ResultX = Cnc.CurrentX + X; ResultY = Cnc.CurrentY + Y; return(true); }
private bool CNC_XY_m(double X, double Y) { return(MainForm.CNC_XY_m(X, Y)); }
// ======================================================================================== // ======================================================================================== // GetPartHole_m(): Measures X,Y location of the hole corresponding to part number public bool GetPartHole_m(int TapeNum, int PartNum, out double ResultX, out double ResultY) { ResultX = 0.0; ResultY = 0.0; // Get start points double X = 0.0; double Y = 0.0; if (!double.TryParse(Grid.Rows[TapeNum].Cells["X_Column"].Value.ToString(), out X)) { MainForm.ShowMessageBox( "Bad data at Tape " + TapeNum.ToString() + ", X", "Tape data error", MessageBoxButtons.OK ); return(false); } if (!double.TryParse(Grid.Rows[TapeNum].Cells["Y_Column"].Value.ToString(), out Y)) { MainForm.ShowMessageBox( "Bad data at Tape " + TapeNum.ToString() + ", Y", "Tape data error", MessageBoxButtons.OK ); return(false); } // Get the hole location guess double dW; double Pitch; double FromHole; int CustomTapeNum = -1; if (!GetTapeParameters_m(TapeNum, out CustomTapeNum, out dW, out FromHole, out Pitch)) { return(false); } if (Math.Abs(Pitch - 2) < 0.000001) { Pitch = 4.0; PartNum = PartNum % 2; } int incr = (PartNum - 1); // this many holes from start double dist = (double)incr * 4.0; // This many mm's switch (Grid.Rows[TapeNum].Cells["OrientationColumn"].Value.ToString()) { case "+Y": Y = Y + dist; break; case "+X": X = X + dist; break; case "-Y": Y = Y - dist; break; case "-X": X = X - dist; break; default: MainForm.ShowMessageBox( "Bad data at Tape #" + TapeNum.ToString() + ", Orientation", "Tape data error", MessageBoxButtons.OK ); return(false); } // X, Y now hold the first guess // For custom tapes, we might not need to move at all: if (CustomTapeNum != -1) // tape is custom { if (!GetCustomPartHole_m(CustomTapeNum, PartNum, X, Y, out ResultX, out ResultY)) { return(false); } return(true); } // Measuring standard tapes if (!SetCurrentTapeMeasurement_m(TapeNum)) // having the measurement setup here helps with the automatic gain lag { return(false); } // Go there: if (!MainForm.CNC_XY_m(X, Y)) { return(false); } ; // get hole exact location: if (!MainForm.GoToCircleLocation_m(1.8, 0.1, out X, out Y)) { MainForm.ShowMessageBox( "Can't find tape hole", "Tape error", MessageBoxButtons.OK ); return(false); } ResultX = Cnc.CurrentX + X; ResultY = Cnc.CurrentY + Y; return(true); }
// ======================================================================================== // 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