XScript Manual · Chapter 65

ALIGN — align

ALIGN["align name"] refers to one align. An align uses a camera and the X · Y motors to find the references of a part again — 1 to 3 marks, or two board edges when there are no marks — and computes the X · Y shift and rotation angle compared with teaching (plus the scale with uniform scale). Use it on machines where parts arrive at slightly different positions and angles, to apply that difference to dispense patterns or motor move coordinates. The script object came in QMachineStudio 4.0.11 as FIDUCIAL and was renamed ALIGN in 4.0.28.

Caution The keyword changed in 4.0.28. FIDUCIAL["name"] became ALIGN["name"], and FIDUCIAL can no longer be used (there is no alias). Left as it is, the build reports 'FIDUCIAL' was renamed to 'ALIGN' - write ALIGN["name"] instead ( FIDUCIAL is no longer supported ) (diagnostic code RENAMED) in the compile error list, and nothing is changed automatically. Function names and arguments are the same, so only the keyword has to change. Projects deployed as .xmc only, without sources, must be rebuilt with the new QMS and deployed again — otherwise the line stops with an error when it runs.

Access

  • Aligns are created in the studio under [Tools → Align Setup...] (toolbar button). In that window choose the method, calibrate the camera and teach the references (marks or board edges); the [Device settings...] button at the top opens the window where you choose the X · Y motors, camera, lights (0 ~ 3 — a controller · channel for each light, 4.0.28~) and the limits.
  • On machine screens, aligns are taught on the FiducialTeach page (Align Teach).
  • Machine screen controls (toolbox Vision) — teach screen AlignTeach · result display AlignResult (4.0.28~), result trend · cell result map · mark images · limit editor · setup check list · align button (4.0.30~ — the align button does Measure · MeasureCell · move to mark without a script). → GUI manual — UI controls
  • Mark shapes are circle · rectangle · cross · diamond · free mark.
  • Settings are saved in the project Fiducial\Aligns.json, the method and teaching in the JobFile Fiducial\<align>.json. Each JobFile (model) has its own method and teaching, so each model can use a different method.
  • Align names are checked at build time. An unknown name in ALIGN["name"] is a warning, in DISPENSE[…].SetAlign("name") a build error (not checked in a project with no align).

Device settings, camera calibration, teaching and checking on screen are described in the Align Manual in the QMachineStudio [Help] menu and in Dispenser Toolkit — align.

Methods

MethodGetMethod()MeasuresCorrection and checks
Mark align, 1 mark (4.0.27~)"Mark1"mark 1Shift only (angle 0 — no rotation correction). Only the X · Y limits are checked. Use it only when a jig or pins keep the part from rotating.
Mark align, 2 marks"Mark2"marks 1 · 2Rotation + shift (the same calculation as up to 4.0.26). Checked in the order mark distance error → X · Y · angle limits.
Mark align, 3 marks (4.0.27~)"Mark3"marks 1 · 2 · 3Rotation + shift (least squares). Checked in the order mirrored (flipped part) → distance error (largest of the three pairs) → residual → X · Y · angle.
Edge align — corner (4.0.28~)"EdgeCorner"edges A · B (one shot position)Rotation + shift from the corner (intersection of the two edges) and the angle of edge A. Checked in the order valid sample ratio → squareness → X · Y · angle. Available only with the QVision vision driver, whose angle direction has been verified.
  • The 1-mark and 3-mark calculation and the per-method script functions came first in 4.0.27, but choosing the method on the screen is available from 4.0.28 (scripts cannot set the method).
  • The method is saved in the teach file of each JobFile, so GetMethod() can change when the JobFile changes.

Correction (4.0.28~) — with 2 or 3 marks each JobFile chooses [Rigid] (default — rotation + shift; the scale is only measured and shown) or [Uniform scale] (rotation + shift + even stretch — a similarity transform). Uniform scale applies the measured scale k to coordinates (Apply · DISPENSE.SetAlign — current = C + k·R(θ)·(taught − C) + D) and checks the scale limit (%) instead of the distance error limit (2 marks: scale → X · Y · angle, 3 marks: mirrored → scale → residual → X · Y · angle). 2-mark uniform scale has no spare check — a slightly wrong mark is absorbed into the scale — so use 3 marks where possible. Which dispense pattern values are multiplied by the scale and which stay is listed under 'Correction' in Dispenser Toolkit — align.

Basic example

xscript
FUNCTION AlignAndDispense()
{
   // Grab and find the references ( marks or edges ) of this JobFile's method and compare with teaching ( waits until done )
   if( ALIGN["Tray"].Measure() == false )
   {
      LogError("Align failed ({0}) : {1}", ALIGN["Tray"].GetMethod(), ALIGN["Tray"].GetLastError());
      return false;
   }
   Log("Align dx={0} dy={1} deg={2}", ALIGN["Tray"].GetDX(), ALIGN["Tray"].GetDY(), ALIGN["Tray"].GetDeg());
 
   // Quality values per method — log them to watch the trend
   if( ALIGN["Tray"].GetMethod() == "Mark3" )
   {
      Log("residual max={0} mm", ALIGN["Tray"].GetResidual());
   }
   else if( ALIGN["Tray"].GetMethod() == "EdgeCorner" )
   {
      Log("squareness={0} deg", ALIGN["Tray"].GetSquareness());
   }
 
   // Put the result into the dispense head and run ( the same for every method — an array pattern applies it to all cells at once )
   if( DISPENSE["Head1"].SetAlign("Tray") == false )
   {
      LogError("SetAlign failed : {0}", DISPENSE["Head1"].GetLastError());
      return false;
   }
   return DISPENSE["Head1"].Run("Lid_A");
}
 
FUNCTION MoveToAlignedPoint()
{
   // Where the taught point (150, 60) is on the current part
   double x = 0;
   double y = 0;
   if( ALIGN["Tray"].Apply(150.0, 60.0, /*ref*/x, /*ref*/y) == false )
   {
      return false;
   }
   MOTOR["M_X"].MoveAbs(x, false);
   MOTOR["M_Y"].MoveAbs(y, true);
   return true;
}

Functions · properties

SignatureDescription
string NameAlign name
bool Measure()Moves to the teach positions of this method's references (marks 1 ~ 3 or edges A · B), grabs, finds them and compares with teaching. true when all are found and within the limits. When a reference is not found, the following ones are not measured. If the machine goes into the Error state while measuring, the remaining moves and grabs are skipped and it returns false (4.0.24~). If the correction does not fit the method (uniform scale on 1 mark or the edge corner) or is unknown to this QMS, it returns false without moving (4.0.28~)
string GetMethod() (4.0.27~)Method of the current JobFile: "Mark1" · "Mark2" · "Mark3" · "EdgeCorner" ("Unknown" for a method this QMS does not know)
int GetFeatureCount() (4.0.27~)Number of references the method measures (marks for mark methods, 2 for edge corner, 0 for an unknown method)
bool MeasureFeature(int index) (4.0.27~)Grabs and finds one reference only (1 ~ GetFeatureCount()). For mark methods the same as MeasureMark; for edge corner 1 = edge A · 2 = edge B (at the shot position). The align result is not changed
bool MeasureMark(int mark)Finds one mark only (1 ~ 3, only marks the method uses). Read the result with GetMarkX · GetMarkY; the align result is not changed
bool MeasureCell(string pattern, int cell, string jig = "") (4.0.28~)Measures at the place of cell cell of a dispense array pattern — moves the teach by the array shift of that cell, and with jig predicts the shot position from the last result of that align (the jig marks). The X · Y · angle limits are checked from the position predicted by the jig. false without moving for a pattern without an array · a cell out of range · an unknown jig · an NG jig result. Put the result into that cell with DISPENSE[…].SetCellAlign ('Cell · position measurement' below)
bool MeasureAt(double dx, double dy, string jig = "") (4.0.28~)Measures with the teach moved by (dx, dy) mm (without a pattern — trays · laser marking etc., cell number 0). Otherwise the same as MeasureCell. MeasureAt(0, 0) without a jig is the same as Measure
bool IsValid()Whether the last Measure succeeded
double GetDX() · double GetDY()X · Y shift of the last Measure (mm, about the rotation center)
double GetDeg()Rotation of the last Measure (deg, counter-clockwise + — 0 for 1 mark)
int GetCell() (4.0.28~)Cell number when the last result is a cell measurement (0 for Measure · MeasureAt — a failed cell measurement keeps its cell number)
double GetDXFromJig() · double GetDYFromJig() · double GetDegFromJig() (4.0.28~)Shift · rotation from the position predicted by the jig (how far it moved in the pocket — mm · deg, the values checked by the limits. The same as GetDX · GetDY · GetDeg when measured without a jig, 0 if the values could not be computed)
double GetCenterX() · double GetCenterY() (4.0.27~)Rotation center (teach coordinates, mm — 1 mark = mark 1, 2 marks = middle of the two marks, 3 marks = centroid of the three marks, edge = taught corner)
double GetDistError()Mark distance difference (measured − taught, mm — for 3 marks the difference of the three pairs that is largest in size, 0 for 1 mark and edge)
double GetResidual() (4.0.27~)Largest residual of 3 marks (mm — distance between a measured mark and its taught mark moved by the fitted rotation and shift (and scale, with uniform scale). 0 for other methods)
double GetMarkResidual(int mark) (4.0.27~)Residual of one mark for 3 marks (mm)
double GetScale() (4.0.27~)Measured scale (2 marks = measured distance / taught distance, 3 marks = least squares uniform scale, 1 mark and edge = 1, 0 when not computed). Diagnostic only with the rigid correction; with uniform scale it equals the value applied to coordinates (4.0.28~)
bool IsScaleApplied() (4.0.28~)Whether the last Measure applied the scale to coordinates (uniform scale — Apply · DISPENSE.SetAlign use the scale too). false for rigid, for a failed result (scale limit exceeded etc.) or when the values could not be computed
double GetScaleX() · double GetScaleY() · double GetSkew() (4.0.27~)Affine diagnostics of 3 marks — scale along machine X · Y and skew (deg). 0 when the three marks are almost in a line. Only the mirror test is used for the check
double GetSquareness() (4.0.28~)Squareness of the edge corner (deg, 0 = square — the meaning of the sign depends on the corner, so look at the size. 0 for mark methods)
double GetMarkX(int mark) · double GetMarkY(int mark)Last found position of the mark (1 ~ 3, 0 if not found)
bool IsMarkFound(int mark)Whether the mark was found in the last measurement
double GetTeachX(int mark) · double GetTeachY(int mark)Mark teach position in the current JobFile (0 before teaching)
bool IsTaught()Whether all references the method uses are taught in the current JobFile
bool IsBusy() (4.1.32~)Whether this align is running an action (measure · cell measure · move to a mark or shot position · teach · camera calibration · grab) — started from a script, an align action button or the teach screen. It checks this align only, so when several aligns share the camera or motors, check them all. Manual actions (RunManual) and the actions of the action buttons and the teach screen do not block each other, so check it before a manual action that uses the same camera or motors
bool Apply(double x, double y, ref double ox, ref double oy)Converts a taught-time position to the position on the current part (including the scale with uniform scale). false when the last Measure failed; ox · oy then equal the input. If the last measurement was MeasureCell · MeasureAt, pass the moved coordinates (point at teaching + shift, 4.0.28~)
string GetLastError()Last error (English, "" if none)

For DISPENSE["head"].SetAlign(name) · ClearAlign() · GetAlign() · GetAlignScale(), which put the result into a dispense head and take it out, see DISPENSE — applying an align.

Coordinate · value · failure rules

  • Coordinates — mark positions, teach positions and the corner are 'the X · Y motor position at which the point is in the image center' (mm). The camera must be calibrated to get positions. Apply also takes and returns these camera coordinates — the camera offset of the device settings is used only by dispense SetAlign and needle XY calibration (4.0.28~).
  • Methods and results — every method gives the result as 'rotation center · shift · angle' (plus the scale with uniform scale), so Apply and DISPENSE.SetAlign do not care about the method.
  • Values — GetDX · GetDY · GetDeg and the like are 0 when not all references were found. When all were found but a limit was exceeded, Measure is false but the measured values are still returned, so they can be logged. When a reference is not found, the following ones are not measured.
  • Failure — when a measurement fails (including another action in progress or a link failure), the last result and the mark · edge results also become 'failed', so the previous part's result is never used by SetAlign · Apply. If any configured light controller is missing, nothing is measured and the result is false (GetLastError() names the light, such as not linked : light 2 '…' channel 3).
  • One at a time — an align does only one of measuring · teaching · calibrating · moving at a time. A call during another action is refused.

Cell · position measurement (4.0.28~)

To measure the same PCB at several places, such as single PCBs on a jig, teach place 1 (cell 1) only and measure with the teach moved by the cell shift.

xscript
ALIGN["Jig"].Measure();                       // jig marks — jig position
DISPENSE["Head1"].ClearCellAligns();
int count = DISPENSE["Head1"].GetCellCount("PCB");
int i     = 0;
for( /*var*/i, /*start*/1, /*end*/count )
{
   int cell = DISPENSE["Head1"].GetCellInOrder("PCB", i);
   if( ALIGN["Pcb"].MeasureCell("PCB", cell, "Jig") )
   {
      DISPENSE["Head1"].SetCellAlign(cell, "Pcb");
   }
   else
   {
      DISPENSE["Head1"].SetCellSkip("PCB", cell, true);   // do not dispense on a PCB that could not be measured
   }
}
DISPENSE["Head1"].Run("PCB");
  • Jig prediction — with jig, the camera goes where the last result of that jig align (valid · same JobFile · same X · Y motors, measured with Measure) predicts. Marks stay inside the search area even when the jig has shifted a lot. If the jig result cannot be used, it returns false without moving. When the two aligns have different camera offsets, the jig rotation center is moved into the coordinates of this align.
  • Checks — the X · Y · angle limits are checked from the position predicted by the jig (GetDXFromJig etc.); distance error · residual · scale · squareness as usual. 1 mark cannot measure rotation, so it takes over the jig rotation.
  • Result — GetDX · GetDY · GetDeg · GetCenterX and the like are relative to the teach (before moving), so SetCellAlign uses them as they are. Give Apply the moved coordinates (x + dx, y + dy). On failure (including wrong pattern · cell · jig names and an NG jig result) the last result becomes a 'failure' of that cell.
  • DISPENSE[…].SetAlign does not accept cell · position measurement results (measure the whole board with Measure). The rules for putting them into cells are in DISPENSE — cell aligns, and the whole flow in 'Cell align' of Dispenser Toolkit — align.

Cautions

  • Threads — Measure · MeasureMark · MeasureFeature · MeasureCell · MeasureAt wait until moving and grabbing are done. Call them from a sequence step or RunManualThread, not directly from a screen button event.
  • They move even while running — only the teach screen is locked while the machine runs; script measurements move the motors during operation. Simulation mode cannot be switched while an align is measuring or teaching.
  • Z is not handled — an align moves X · Y only. Raise axes that come down under the camera, such as a needle or gripper, to a safe height with the script before measuring.
  • Apply does not check the JobFile — after switching the JobFile, run Measure again first. (SetAlign refuses a result measured on another JobFile.)
  • Camera-based coordinates — the result and the rotation center are camera-based (the motor position at which the reference is in the image center). To get the position of a tool offset from the camera, such as a needle or gripper, pass camera-based coordinates to Apply and subtract the tool offset (XY with the camera center on a point − XY with the tool tip on the same point) from the result: that is the motor position that puts the tool on the point (the same rule as the dispenser's 'motor = needle position − needle offset'). Passing tool coordinates directly is off by rotation angle × camera-tool distance when the part is rotated (about 0.44 mm for 0.5° and 50 mm). With uniform scale it is off by a further |k − 1| × camera-tool distance even when the part is not rotated (0.05 mm for 0.1 % and 50 mm — its direction differs from the rotation error, so the two do not simply add up). Dispense SetAlign makes up this difference by itself with the camera offset of the device settings (4.0.28~, DISPENSE — applying an align). Apply does not use the camera offset.
  • Pattern coordinates — patterns and points to which the align is applied must be taught on the same part the references were taught on. Using it together with the dispenser's older two-point correction (SetFiducial2) applies the correction twice, so use only one.
  • Needle XY calibration — the align used for the needle XY calibration of a dispense head finds the dots on the calibration plate with the mark 1 teaching (dot shape · search area), so it must use a mark method. An edge corner align, or one without mark 1 taught, is refused before any dot is dispensed on the plate.
Subscribe