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
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
The condition uses a simple JSON configuration file to specify the LM signal timing offset:
{
"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.
The Initialize method performs the following initialization steps:
Reads the LM offset value from the configuration JSON file
Creates or clears the output CSV file
Writes the CSV header: "Timestamp CommandedX CommandedY MeasuredX MeasuredY"
During acquisition, the Check method performs these steps on each timestamp:
Monitor the BuiltInSignal BisLm signal for rising edges (transition from 0 to > 0)
When a rising edge is detected, record the timestamp plus the configured offset
At the offset timestamp, interpolate position values between the last and current timestamps
Write interpolated commanded positions (Field0TxX, Field0TxY) to the CSV
Write interpolated measured positions (Field0RxX, Field0RxY) to the CSV
Store current signals for next interpolation cycle
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. |
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:
// 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.
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:
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
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.
To use the CustomCondition_SpotPosition with the Process Data Analyzer server:
Build the CustomCondition_SpotPosition.dll from the sample code
Create a Configuration.json file with your desired LM offset
Place both files in the same directory (or in the Process Data Analyzer server's plugin directory)
Configure the server to use the custom condition (see 4.2.3 Custom Trigger Streaming)
Ensure required signals are enabled: BisLm, BisField0TxX, BisField0TxY, BisField0RxX, BisField0RxY
Start acquisition - position data will be logged to SpotPosition.csv
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