# Alignment Sub Tasks

The following subtasks are used in alignment task.

## Feature And Command Subscribers Subtask

This subtask subscribes train time and run time features and their commands from feature finder tasks that compute features needed to align the part.

The input is current command of the task.

Input | Type | Description
--- | --- | ---
Command | CommandArgs | Current command for alignment task

The outputs are subscribed train time and run time features and their commands, and current alignment task command.

Output | Type | Description
--- | --- | ---
Command | CommandArgs | Current command for alignment task, the same with input command
Features0 | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of run time features from connected feature finder
Features0Command | CommandArgs | The last run time command to trigger connected feature finder to run image acquisition and feature extraction
MultiplePartFeatures | List<List<CogAlpsPointFeature>> | The list of run time parts' features from connected multiple part feature finder. Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
MultiplePartStatus | List<Integer> | The feature finding result status list for all sub regions on a tray from the connected multiple part feature finder. For each status: 1: success <=0: fail Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
TrainFeatures0CommandData | CommandArgs | The last train time command used for connected feature finder's image acquisition and feature extraction
TrainFeatures0Data | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of train time features from connected feature finder

## Offset Compensation Subtask

Offset compensation allows user to manually add offsets to run time features to compensate the final alignment or assembly result based on inspection result feedback.

The inputs are subscribed train time and run time features and their commands, and current alignment task command.

Input | Type | Description
--- | --- | ---
Command | CommandArgs | Current command for alignment task, the same with input command
Features0 | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of run time features from connected feature finder
Features0Command | CommandArgs | The last run time command to trigger connected feature finder to run image acquisition and feature extraction
MultiplePartFeatures | List<List<CogAlpsPointFeature>> | The list of run time parts' features from the connected multiple part feature finder. Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
MultiplePartStatus | List<Integer> | The feature finding result status list for all sub regions on a tray from the connected multiple part feature finder. For each status: 1: success <=0: fail Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
TrainFeatures0CommandData | CommandArgs | The last train time command used for connected feature finder's image acquisition and feature extraction
TrainFeatures0Data | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of train time features from connected feature finder

The outputs are the same with inputs except that run time features/multiple parts features may have been compensated with offsets.

Output | Type | Description
--- | --- | ---
Features0 | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The compensated run time features from the connected feature finder
MultiplePartFeatures | List<List<CogAlpsPointFeature>> | The list of run time parts' features from the connected multiple part feature finder. Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated

## Pose Computer Subtask

### Alignment or Assembly

For alignment or assembly applications, pose computer subtask computes transforms between target position and current position, and calculates alignment parameters that would result in the desired part alignment or assembly.

The inputs are the same with offset compensation subtask's.

Input | Type | Description
--- | --- | ---
Command | CommandArgs | Current command for alignment task, the same with input command
Features0 | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of run time features from connected feature finder
Features0Command | CommandArgs | The last run time command to trigger connected feature finder to run image acquisition and feature extraction
MultiplePartFeatures | List<List<CogAlpsPointFeature>> | The list of run time parts' features from the connected multiple part feature finder. Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
MultiplePartStatus | List<Integer> | The feature finding result status list for all sub regions on a tray from the connected multiple part feature finder. For each status: 1: success <=0: fail Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
TrainFeatures0CommandData | CommandArgs | The last train time command used for connected feature finder's image acquisition and feature extraction
TrainFeatures0Data | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of train time features from connected feature finder

The outputs are train time and run time features, relative and absolute stage positions.

Output | Type | Description
--- | --- | ---
AbsoluteStageMotionThetaDegrees | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Theta-value of absolute pose stage should move to from current pose or trained pose
AbsoluteStageMotionX | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Y-value of absolute pose stage should move to from current pose or trained pose
AbsoluteStageMotionY | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The X-theta value of absolute pose stage should move to from current pose or trained pose
Features0 | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of features from connected feature finder
MultiplePartFeatures | List<List<CogAlpsPointFeature>> | The list of run time parts' features from the connected multiple part feature finder. Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
MultiplePartStatus | List<Integer> | The feature finding result status list for all sub regions on a tray from the connected multiple part feature finder. For each status: 1: success <=0: fail Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
RelativeStageMotionThetaDegrees | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Theta-value of relative pose stage should move from current pose or trained pose
RelativeStageMotionX | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Y-value of relative pose stage should move from current pose or trained pose
RelativeStageMotionY | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The X-theta value of relative pose stage should move from current pose or trained pose
TrainFeatures0Data | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of trained features from connected feature finder

### Inspection

For inspection applications, pose computer measures distances between paired features and checks if they are within required ranges, and outputs a list of measurement items, their values, and their tolerance check results.

Although there are seven input pins for an inspection PoseComputer subtask as shown above, this subtask only uses four inputs internally: Command, Features0, Features0Graphics_Camera0Pos0, and Features0Graphics_Camera1Pos0.

Input | Type | Description
--- | --- | ---
Command | CommandArgs | Current command for alignment task, the same with input command
Features0 | List<CogAlpsGenericFeature> | The list of run time features from the connected feature finder
Features0Graphics_Camera0Pos0 | CogGraphicCollection | The feature finding graphics for Camera0 at position0
Features0Graphics_Camera1Pos0 | CogGraphicCollection | The feature finding graphics for Camera1 at position0

This subtask passes through the run time features without any change to them, at the same time outputs the overall OK/NG result and the measurement result list.

Output | Type | Description
--- | --- | ---
Features0 | List<CogAlpsGenericFeature> | The list of run time features from the connected feature finder
IsNG | Boolean | True: when all tolerance checks are passed False: when at least one of the of tolerance checks fails
Results | List<Tuple<String, Double, Boolean>> | The list of inspection result. Each result has three elements: name of the tolerance check (String type), the value of the tolerance check (Double type), and whether the check is passed (Boolean type)

## Limit Check Subtask

Limit check use pose computer's output x, y, theta as input, to check if they're within certain alignment limit specs defined by user.

The inputs are the same with Pose Computer subtask's outputs.

Input | Type | Description
--- | --- | ---
AbsoluteStageMotionThetaDegrees | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Theta-value of absolute pose stage should move to from current pose or trained pose
AbsoluteStageMotionX | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Y-value of absolute pose stage should move to from current pose or trained pose
AbsoluteStageMotionY | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The X-theta value of absolute pose stage should move to from current pose or trained pose
Features0 | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of features from connected feature finder
MultiplePartFeatures | List<List<CogAlpsPointFeature>> | The list of run time parts' features from the connected multiple part feature finder. Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
MultiplePartStatus | List<Integer> | The feature finding result status list for all sub regions on a tray from the connected multiple part feature finder. For each status: 1: success <=0: fail Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
RelativeStageMotionThetaDegrees | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Theta-value of relative pose stage should move from current pose or trained pose
RelativeStageMotionX | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Y-value of relative pose stage should move from current pose or trained pose
RelativeStageMotionY | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The X-theta value of relative pose stage should move from current pose or trained pose
TrainFeatures0Data | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of trained features from connected feature finder

Besides passing all the original inputs without any change down as ouputs, Limit Check subtask also outputs Limit Check OK/NG result, and ErrorCode.

Output | Type | Description
--- | --- | ---
ErrorCode | String for single part alignment or two parts assembly List<String> for multiple parts alignment | ErrorCode or a list of ErrorCode when Limit Check is NG
IsOK | Boolean | Whether current pose computation result(s) pass Limit Check

## GenerateResultsPublisherAndLogger Subtask

This subtask saves all alignment or assembly result data into a dictionary and publishes that dictionary in Task Results Block.

The inputs are train time and run time features, relative and absolute pose stage should move/move to, LCheck OK/NG result, LCheck ErrorCode, customized Error Message, and customized User Log Data.

Input | Type | Description
--- | --- | ---
AbsoluteStageMotionThetaDegrees | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Theta-value of absolute pose stage should move to from current pose or trained pose
AbsoluteStageMotionX | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The Y-value of absolute pose stage should move to from current pose or trained pose
AbsoluteStageMotionY | Double: for single part alignment or two parts assembly List<Double>: for multiple parts alignment | The X-theta value of absolute pose stage should move to from current pose or trained pose
ErrorCode | String: for single part alignment or two parts assembly List<String>: for multiple parts alignment | ErrorCode when LCheck is NG
ErrorMsg | String | Error message for user to customize
Features0 | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of features from connected feature finder
MultiplePartFeatures | List<List<CogAlpsPointFeature>> | The list of run time parts' features from the connected multiple part feature finder. Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
MultiplePartStatus | List<Integer> | The feature finding result status list for all sub regions on a tray from the connected multiple part feature finder. For each status: 1: success <=0: fail Only available when the connected alignment type was configured as "Multiple parts" in the Configuration Wizard before the application was generated
IsOK | Boolean | Whether LCheck is passed or not
RelativeStageMotionThetaDegrees | Double | The Theta-value of relative pose stage should move from current pose or trained pose
RelativeStageMotionX | String: for single part alignment or two parts assembly List<String>: for multiple parts alignment | The Y-value of relative pose stage should move from current pose or trained pose
RelativeStageMotionY | String: for single part alignment or two parts assembly List<String>: for multiple parts alignment | The X-theta value of relative pose stage should move from current pose or trained pose
TrainFeatures0Data | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of trained features from connected feature finder
UserLogData | OrderedDictionary | User data for user to customize data to be added at the end alignment log

### Inspection

Input | Type | Description
--- | --- | ---
ErrorCode | String: for single part alignment or two parts assembly List<String>: for multiple parts alignment | ErrorCode when LCheck is NG
ErrorMsg | String | Error message for user to customize
Features0 | List<CogAlpsPointFeature> / List<CogAlpsLineFeature>/ List<CogAlpsGenericFeature> | The list of features from the connected feature finder
IsNG | Boolean | True: when all tolerance checks are passed False: at least one of the of tolerance checks fails
Results | List<Tuple<String, Double, Boolean>> | The list of inspection result. Each result has three elements: name of the tolerance check (String type), the value of the tolerance check (Double type), and whether the check is passed (Boolean type)
UserLogData | OrderedDictionary | User data for user to customize data to be added at the end alignment log

## Image Subscriber Subtask

This subtask subscribes images captured by the corresponding feature finder tasks that compute features that are used by this alignment task.

The output pin names are related to specific feature finding task names. For the same of generality, feature finding task names are ignored in decription. The outputs are acquisition settings of the feature finding task, command and image collection, as well as accumulated commands and images collections from feature finding task.

Output | Type | Description
--- | --- | ---
AccumulatedCommands | List<CommandArgs> | Accumulated commands that have been sent to Acquisition subtask to acquire a whole set of images at all acquisition positions in connected feature finding task.
AccumulatedImageCollections | List<CogImageCollection> | Accumulated images acquired at different acquisition positions in connected feature finding task.
AcquisitionSettings | AcquisitonSettings | The acquisition settings for connected feature finding task, which includes camera indexes, camera enable/disable status, exposure time and position indexes.
Command | CommandArgs | Last run time command of connected feature finding task
ImageCollection | CogImageCollection | A collection of images acquired at last position index in connected feature finding task

## Image List Saver2 Subtask

Image List Saver2 subtask saves the images captured by corresponding feature finder task.

The inputs are acquisition settings of connected feature finding task, last run time command and accumulated commands and images collections from collected feature finding task, as well as UserData that could be used as metadata for CDB files.

Input | Type | Description
--- | --- | ---
AccumulatedCommands | List<CommandArgs> | Accumulated commands that have been sent to Acquisition subtask to acquire a whole set of images at all acquisition positions in connected feature finding task.
AccumulatedImageCollection | List<CogImageCollection> | Accumulated images acquired at different acquisition positions in connected feature finding task.
AcquisitionSettings | AcquisitonSettings | The acquisition settings for connected feature finding task, which includes camera indexes, camera enable/disable status, exposure time and position indexes.
Command | CommandArgs | Last run time command of connected feature finding task
UserData | IEnumerable<KeyValuePair<String,String>> | User defined Metadata for image saving in CDB format. Not used.