Cycle Integration
This guide focuses on how to integrate Struckig into a PLC task loop safely and predictably.
Recommended loop structure
Use a stable three-part cycle:
- update targets and limits at well-defined step boundaries
- call
otg()exactly once per PLC cycle - map outputs to axis setpoints and handle state/errors
// 1) Update targets on sequence events (not shown here)
// 2) Cyclic update
otg();
// 3) Output mapping and safety checks
IF otg.State = Struckig.TrajectoryState.Error THEN
Abort(otg.ErrorMessage());
ELSE
axisX.SetInterpolatedPosition(THIS^, otg.CurrentPosition[0]);
axisY.SetInterpolatedPosition(THIS^, otg.CurrentPosition[1]);
axisX.SetInterpolatedVelocity(THIS^, otg.CurrentVelocity[0]);
axisY.SetInterpolatedVelocity(THIS^, otg.CurrentVelocity[1]);
END_IF
Task cycle time
- Set
cycletimeto the real PLC task period in seconds. - If task time changes dynamically, update
CycleTimebefore runningotg(). - Keep jitter low in motion tasks to avoid setpoint quality degradation.
State handling
Typical state flow:
Busy: trajectory is activeIdle: target reached within internal checksError: invalid input or infeasible constraints
Use transitions on Idle to trigger the next machine step.
Important nuance:
Idlemeans final target state is reached.- If target velocity or acceleration is non-zero, physical movement can still be expected in downstream drive behavior even when the trajectory state is complete for the requested target.
Target update timing
Do:
- write complete target vectors atomically at step entry
- reset current state only when starting a new independent segment
Avoid:
- partial per-element target updates across multiple cycles
- changing hard limits continuously unless this is a deliberate feature
Input validation flow
Before applying new targets from external logic, validate input:
IF NOT otg.ValidateInput(
checkCurrentStateWithinLimits := FALSE,
checkTargetStateWithinLimits := TRUE
) THEN
Abort(otg.ErrorMessage());
END_IF
This catches invalid values earlier and gives better diagnostics than handling errors only after otg().
Multi-axis notes
- Keep all axis constraints in realistic mechanical range.
- Use
Phasesynchronization for coordinated path execution. - Use
TimeSyncfor simultaneous arrivals with less strict geometric coupling. - Use
Nonewhen independent axis completion is preferred, for example emergency deceleration behavior.
Per-DoF runtime control
You can mix interfaces or synchronization modes per axis:
otg.ControlInterface := Struckig.ControlInterfaceType.Position;
otg.PerDofControlInterface[1] := Struckig.ControlInterfaceType.Velocity;
otg.Synchronization := Struckig.SynchronizationType.TimeSync;
otg.PerDofSynchronization[2] := Struckig.SynchronizationType.None;
Use this carefully, as mixed policies can change trajectory shape and duration in non-obvious ways.
Integration checklist
cycletimematches task period- consistent units across all vectors
- one
otg()call per cycle - explicit
Errorhandling path - axis outputs mapped every cycle
ValidateInputis used at setpoint handover boundaries