Click or drag to resize

4.2.6 Custom Condition Spot Position

The C:\Program Files\RAYLASE\ProcessDataAnalyzer\API\SampleCode\SampleApplications\CustomCondition_SpotPosition is an implementation of the ICondition interface that demonstrates position logging based on laser mark (LM) signal events. This example focuses on interpolating and recording laser spot positions at the precise moment of marking, creating a CSV file with commanded and measured field positions.

This custom condition is particularly useful for:

  • Mark position verification: Recording exact positions where laser marking occurs

  • Position accuracy analysis: Comparing commanded vs. measured positions at mark time

  • Quality control: Creating position logs for later analysis and process validation

  • Timing calibration: Testing and adjusting LM signal offsets for accurate position capture

Position Logging Features

The CustomCondition_SpotPosition example implements the following capabilities:

  • Detects rising edges of the laser mark (LM) signal

  • Interpolates position values to account for timing offsets

  • Logs both commanded (TxX/TxY) and measured (RxX/RxY) field positions

  • Configurable LM signal offset for timing adjustments

  • Outputs data to a CSV file for external analysis

Configuration Structure

The condition uses a simple JSON configuration file to specify the LM signal timing offset:

Configuration.json
{
  "LmOffsetUs": 0.0
}

The LmOffsetUs parameter allows you to adjust the timing of position capture relative to the LM rising edge. This is useful when the LM signal has a known delay relative to the actual marking event.

Implementation Details

The Initialize method performs the following initialization steps:

  1. Reads the LM offset value from the configuration JSON file

  2. Creates or clears the output CSV file

  3. Writes the CSV header: "Timestamp CommandedX CommandedY MeasuredX MeasuredY"

During acquisition, the Check method performs these steps on each timestamp:

  1. Monitor the BuiltInSignal BisLm signal for rising edges (transition from 0 to > 0)

  2. When a rising edge is detected, record the timestamp plus the configured offset

  3. At the offset timestamp, interpolate position values between the last and current timestamps

  4. Write interpolated commanded positions (Field0TxX, Field0TxY) to the CSV

  5. Write interpolated measured positions (Field0RxX, Field0RxY) to the CSV

  6. Store current signals for next interpolation cycle

Note  Note

This condition always returns false, meaning it does not trigger trace file saves. Its purpose is purely to log position data to a CSV file for external analysis.

Position Interpolation

The key feature of this example is position interpolation. Since signals may not arrive exactly at the LM rising edge timestamp, the condition interpolates position values using linear interpolation:

Interpolation Logic
// Calculate interpolation factor
var dtActual = _lmOnTimestamp + _userLmOffsetUs - timestamp;
var dt = timestamp - _lastTimestamp;
var interpFactor = dtActual != 0 ? (dt + dtActual) / dt : 0.0;

// Interpolate position
var interpolatedX = interpFactor == 0 ? currentX : lastX + (currentX - lastX) * interpFactor;

This ensures accurate position values even when signal updates don't align perfectly with the LM event timing.

CSV Output Format

The condition writes a CSV file named SpotPosition.csv in the same directory as the DLL. Each line contains:

  • Timestamp: The interpolated timestamp (µs) when marking occurred

  • CommandedX: Interpolated Field0TxX value

  • CommandedY: Interpolated Field0TxY value

  • MeasuredX: Interpolated Field0RxX value (if available)

  • MeasuredY: Interpolated Field0RxY value (if available)

Example CSV output:

SpotPosition.csv
Timestamp CommandedX CommandedY MeasuredX MeasuredY
1234567 -5.2 3.1 -5.3 3.0
1345678 0.0 0.0 0.1 -0.1
1456789 5.2 -3.1 5.1 -3.2

Usage Scenarios

Scenario 1: Mark Position Verification

Use this condition to verify that marking occurs at intended positions. Compare commanded vs. measured positions to detect positioning errors or drift.

Scenario 2: Calibration and Timing Analysis

Adjust the LmOffsetUs parameter to find the optimal timing offset for your system. Analyze the CSV output to ensure positions are captured at the exact moment of marking.

Scenario 3: Quality Documentation

Generate position logs as part of quality assurance workflows. The CSV files can be archived with production data for traceability and compliance.

Integration with PDA Server

To use the CustomCondition_SpotPosition with the Process Data Analyzer server:

  1. Build the CustomCondition_SpotPosition.dll from the sample code

  2. Create a Configuration.json file with your desired LM offset

  3. Place both files in the same directory (or in the Process Data Analyzer server's plugin directory)

  4. Configure the server to use the custom condition (see 4.2.3 Custom Trigger Streaming)

  5. Ensure required signals are enabled: BisLm, BisField0TxX, BisField0TxY, BisField0RxX, BisField0RxY

  6. Start acquisition - position data will be logged to SpotPosition.csv

Extending the Example

This example can be extended with additional features:

  • Position deviation triggering: Return true when the difference between commanded and measured position exceeds a threshold, triggering a trace save

  • Statistical analysis: Calculate and log position statistics (mean deviation, max error)

  • Multiple LM signals: Support different LM sources with individual offsets

  • Binary output: Write position data in binary format for more efficient storage

  • Real-time filtering: Apply filters to detect anomalies and trigger saves only for problematic marks

See Also