# AlignPlus Tasks

AlignPlus tasks are automatically generated by setup wizard based on configurations of calibration, feature finder, and alignment components. Here is an example of setup wizard and its generated tasks.

- Setup Wizard Configuration

- Tasks generated by configuration above

Each component in setup wizard will result in the generation of one or more tasks after setup wizard finishes running. The names of those tasks have certain relationships with their corresponding component names.

Component | Generated Task | Task Example | Task Function | Task Trigger Mode
--- | --- | --- | --- | ---
hand-eye calibration | <Calibration Name>_Loop | HECalib_Loop | The purpose of this task is to generate various motion device poses for the purpose of hand-eye calibration, and at each pose to call the <Calibration Name>_ComputeCalibResults task. This task is only generated when Vision System Guided option is checked on in the stage device in setup wizard | Manually or by external command
<Calibration Name>_ComptueCalibResults | HECalib_ComptueCalibResults | Move the motion device if necessary, capture images, extract features, accumulate features the of calibration target at each stage pose and finally run calibration calculation. | Manually, by external command, or by hand-eye calibration loop task.
General Calibration( Manual Calibration, Checkerboard Calibration , or Cross Calibration) | <Calibration Name> | CrossCalib | Capture images at each acquisition position, and then extract features and run calibration. | Manually, or by external command
Finder | <Finder Name>_<Connected Calibration Name> | Features0_CrossCalib | This task captures all the images needed to find the features on a part and locates all the features by running feature finders. This task can run during train time or run time. | Manually, or by external command
Alignment | <Alignment Name> | Alignment0 | Compute the alignment pose for the motion device to achieve the desired assembly characteristics. This task is executed after the tasks that locate the features on the part are executed. | Manually, or by external command
Hand-eye Calibration | <Calibration Name>_MotionAnalysisPoseGenerator | HECalib_MotionAnalysisPoseGenerator | Motion analysis tasks are used to conduct various tests of the motion device. The purpose of this task is to generate the various motion device poses for the purpose of testing, and at each pose to call the <Calibration Name>_MotionAnalysis task. | Manually
<Calibration Name>_MotionAnalysis | HECalib_MotionAnalysis | This task moves the motion devices, acquires images, extracts features, accumulates features and stage poses, and computes the results using the accumulated data. | Called by Motion Analysis Pose Generator task

Note: When an application that controls the motion device during calibration is generated by selecting the Vision System Guided option, during hand-eye calibration, the PLC has to send commands that execute the tasks that perform "looping". This task calls the <Calibration Name>_ComputeCalibResults task. If the Vision System Guided option is not selected, the PLC has to send commands that execute the <Calibration Name>_ComputeCalibResults task. This condition also applies to tasks that perform motion analysis.

## Task Execution Mode

The various vision tasks in the application serve various purposes. Vision tasks can be generated to perform hand-eye calibration, cross-calibration, extract features on parts, to compute alignment parameters, etc. Tasks can be executed in various modes. For example, in an application that employs a single camera to capture two images of non-overlapping image regions on a single part, the task can be executed to acquire images of a part at a first position, and then it can be executed to acquire images of the part at a second position and to use both of the images to locate features. Largely each vision task can be executed in three modes.

- Acquire Only
- Acquire and Process
- Process Image.

The execution mode is defined in the command string that the external device sends to the vision system.

For a typical hand-eye calibration task, If it is in the beginning or end of calibration, the task runs in Process Image mode only. If it's in the middle of the loop, the task should acquire images, extract features, and accumulate features at each stage pose so it runs in Acquire and Process mode.

Position | Execution Mode
--- | ---
Hand-eye Calibration start or end | Process Only
At each stage pose ( in the middle of the calibration loop) | Acquire and Process

General calibration and feature finder tasks share similar patterns in execution mode: when the task has shuttling camera or shuttling part, the task should be called with different actions at each acquisition position: acquire images at non-last positions(Acquire Only) , acquire images and run calibration or feature finding at last position(Acquire and Process). If the task has no shuttling camera or shuttling part, then it should be called only once in Acquire and Process mode.

Position | Execution Mode
--- | ---
First position, second position, ... | Image Acquire
Last position | Image Acquire and Process

An alignment task does not acquire any images, so it should always be called with Process Image mode.

## StepID

StepIDs are automatically defined when the application is generated by the setup wizard. They can be found at the top of CommandHandler script.

For the sample application above, the automatically generated StepIDs are as follow:

- Hand-eye calibration loop task's step ID is 0
- Hand-eye calibration ComputeCalibResult task's step ID is 1
- Cross calibration task has three StepIDs (2, 3, 4) since it has three different image acquisition positions. Accordingly, external devices should call this task three times with different StepIDs and different execution modes to finish the cross calibration process
- Features0 has two StepIDs (5, 6) since it acquires images at two different positions. It should be called two times with different StepIDs during both train-time and run-time
- Alignment0 has one StepID, 7
- Motion analysis tasks have stepIDs 8 and 9.

### EncodedID

EncodedID is part of the command string that an external device sends to the vision system to run a task. It contains the StepID of requested task, as well as the task execution mode:

1. Acquire Only

In this mode, EncodedID = StepID + 1000.

2. Acquire and Process

In this mode, EncodedID = StepID

3. Process Only

In this mode, EncodedID = StepID + 2000.

This table summarizes the various vision tasks that can be performed by the sample application:

Category | Task | StepID | Action | EncodedID
--- | --- | --- | --- | ---
Calibration | HECalib_Loop | 0 | Only one command with Process Image action to trigger hand-eye calibration loop, then the loop will take control the rest of process | 2000
CrossCalib | 2 | First command to Acquire Image at position 0 | 1002
3 | Second command to Acquire Image at position 1 | 1003
4 | Third command to Acquire Image and Process at position 2 | 4
Train Time | Features0_CrossCalib | 5 | First command to Acquire Image at position 0 | 1005
6 | Second command to Acquire Image and Process at position 1 | 6
Run Time | Features0_CrossCalib | 5 | First command to Acquire Image at position 0 | 1005
6 | Second command to Acquire Image and Process at position 1 | 6
Alignment0 | 7 | One command to Process Image | 2007