### TimeSync synchronization example Source: https://stefanbesler.github.io/struckig/userguide/synchronized_trajectory.html Configures a Struckig.Otg with TimeSync synchronization so all axes start and finish together. Uses 3 DoFs with a cycle time of 0.001 seconds and sets current and target positions along with velocity, acceleration, and jerk limits. ```st otgTimeSync : Struckig.Otg(cycletime := 0.001, dofs := 3) := ( EnableAutoPropagate := TRUE, Synchronization := Struckig.SynchronizationType.TimeSync, CurrentPosition := [0.0, 0.0, 0.0], TargetPosition := [1.0, -1.0, 2.0], MaxVelocity := [1.0, 1.0, 1.0], MaxAcceleration := [1.0, 1.0, 1.0], MaxJerk := [1.0, 1.0, 1.0] ); ``` -------------------------------- ### Otg1 Usage Example Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg1.html A basic implementation example showing how to initialize the Otg1 block and assign the calculated setpoint to an axis. ```Structured Text otg1( CycleTime := 0.001, ControlInterface := ControlInterfaceType.Position, Synchronization := SynchronizationType.TimeSync ); Axis.Setpoint := otg1.NewPosition; ``` -------------------------------- ### Stop Trajectory Example Source: https://stefanbesler.github.io/struckig/userguide/example_stop_trajectory.html An example that initializes an OTG object with position trajectory parameters, then after an elapsed time switches the controller to velocity interface, sets target velocity and acceleration to zero, and increases MaxJerk to stop the motion. ```unknown PROGRAM Example03_StopTrajectory VAR otg : Struckig.Otg(cycletime := 0.01, dofs := 3) := ( EnableAutoPropagate := TRUE, CurrentPosition := [0.0, 0.0, 0.5], CurrentVelocity := [0.0, -2.2, -0.5], CurrentAcceleration := [0.0, 2.5, -0.5], TargetPosition := [5.0, -2.0, -3.5], TargetVelocity := [0.0, -0.5, -2.0], TargetAcceleration := [0.0, 0.0, 0.5], MaxVelocity := [3.0, 1.0, 3.0], MaxAcceleration := [3.0, 2.0, 1.0], MaxJerk := [4.0, 3.0, 2.0] ); elapsed : LREAL; onStopTrajectory : BOOL; END_VAR elapsed := elapsed + 0.01; IF elapsed >= 1.0 AND_THEN NOT onStopTrajectory THEN onStopTrajectory := TRUE; otg.ControlInterface := Struckig.ControlInterfaceType.Velocity; otg.Synchronization := Struckig.SynchronizationType.None; otg.TargetVelocity := [0.0, 0.0, 0.0]; otg.TargetAcceleration := [0.0, 0.0, 0.0]; otg.MaxJerk := [12.0, 10.0, 8.0]; END_IF otg(); ``` -------------------------------- ### Otg Cyclic Usage Example Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Example of calling the Otg function block cyclically and applying the resulting setpoints to axes. ```Structured Text otg( CycleTime := 0.001, Dofs := 2, ControlInterface := ControlInterfaceType.Position, Synchronization := SynchronizationType.TimeSync ); IF otg.State = TrajectoryState.Busy THEN Axis1.Setpoint := otg.NewPosition[0]; Axis2.Setpoint := otg.NewPosition[1]; END_IF ``` -------------------------------- ### Phase synchronization example Source: https://stefanbesler.github.io/struckig/userguide/synchronized_trajectory.html Configures a Struckig.Otg with Phase synchronization so axes maintain a shared phase relation, useful for coordinated Cartesian motion. Uses 3 DoFs with a cycle time of 0.001 seconds and sets current and target positions along with velocity, acceleration, and jerk limits. ```st otgPhaseSync : Struckig.Otg(cycletime := 0.001, dofs := 3) := ( EnableAutoPropagate := TRUE, Synchronization := Struckig.SynchronizationType.Phase, CurrentPosition := [0.0, 0.0, 0.0], TargetPosition := [1.0, -1.0, 2.0], MaxVelocity := [1.0, 1.0, 1.0], MaxAcceleration := [1.0, 1.0, 1.0], MaxJerk := [1.0, 1.0, 1.0] ); ``` -------------------------------- ### Run minimal 1-axis Struckig trajectory in MAIN Source: https://stefanbesler.github.io/struckig/userguide/installation.html Minimal 1-axis example for the MAIN program. Initializes Struckig.Otg with a 1 ms cycle time and one degree of freedom, sets limits and target values, then calls otg() and reads the new position. EnableAutoPropagate := TRUE is the standard online mode; Struckig automatically copies New* values back into Current* after each cycle. ```structured text PROGRAM MAIN VAR otg : Struckig.Otg(cycletime := 0.001, dofs := 1) := ( EnableAutoPropagate := TRUE, MaxVelocity := [2000.0], MaxAcceleration := [20000.0], MaxJerk := [800000.0], CurrentPosition := [0.0], CurrentVelocity := [0.0], CurrentAcceleration := [0.0], TargetPosition := [100.0], TargetVelocity := [0.0], TargetAcceleration := [0.0] ); axisTargetPosition : LREAL; END_VAR otg(); axisTargetPosition := otg.NewPosition[0]; ``` -------------------------------- ### Configure Struckig Otg with MinDuration Source: https://stefanbesler.github.io/struckig/userguide/example_minimum_duration.html Use this example when process timing requires a slower trajectory than the kinematic limits would naturally produce. The Otg function block is configured with a cycletime of 0.01 seconds, 3 degrees of freedom, and a MinDuration of 5.0 seconds. The example sets current and target states, as well as velocity, acceleration, and jerk limits. ```iecst PROGRAM Example04_MinimumDuration VAR otg : Struckig.Otg(cycletime := 0.01, dofs := 3) := ( EnableAutoPropagate := TRUE, Synchronization := Struckig.SynchronizationType.TimeSync, MinDuration := 5.0, CurrentPosition := [0.0, 0.0, 0.5], CurrentVelocity := [0.0, -2.2, -0.5], CurrentAcceleration := [0.0, 2.5, -0.5], TargetPosition := [-5.0, -2.0, -3.5], TargetVelocity := [ 0.0, -0.5, -2.0], TargetAcceleration := [ 0.0, 0.0, 0.5], MaxVelocity := [3.0, 1.0, 3.0], MaxAcceleration := [3.0, 2.0, 1.0], MaxJerk := [4.0, 3.0, 2.0] ); END_VAR otg(); ``` -------------------------------- ### Validate input before applying new targets Source: https://stefanbesler.github.io/struckig/userguide/cycle_integration.html Call ValidateInput before applying new targets from external logic to catch invalid values earlier and get better diagnostics. The example checks only the target state within limits, not the current state, and aborts with the error message if validation fails. ```ST IF NOT otg.ValidateInput( checkCurrentStateWithinLimits := FALSE, checkTargetStateWithinLimits := TRUE ) THEN Abort(otg.ErrorMessage()); END_IF ``` -------------------------------- ### Struckig Position Interface Configuration Source: https://stefanbesler.github.io/struckig/userguide/example_position_interface.html A standard setup for point-to-point motion defining the cycle time, degrees of freedom, and kinematic constraints for position, velocity, and acceleration. ```Structured Text PROGRAM Example01_Position VAR otg : Struckig.Otg(cycletime := 0.01, dofs := 3) := ( EnableAutoPropagate := TRUE, CurrentPosition := [0.0, 0.0, 0.5], CurrentVelocity := [0.0, -2.2, -0.5], CurrentAcceleration := [0.0, 2.5, -0.5], TargetPosition := [5.0, -2.0, -3.5], TargetVelocity := [0.0, -0.5, -2.0], TargetAcceleration := [0.0, 0.0, 0.5], MaxVelocity := [3.0, 1.0, 3.0], MaxAcceleration := [3.0, 2.0, 1.0], MaxJerk := [4.0, 3.0, 2.0] ); END_VAR otg(); ``` -------------------------------- ### Configure and call Struckig OTG with velocity interface Source: https://stefanbesler.github.io/struckig/userguide/example_velocity_interface.html Use this when the application is primarily velocity driven, such as controlled deceleration. The example sets up a 3-DOF OTG with a cycle time of 0.01 seconds, enables auto propagation, selects the velocity control interface, and defines current and target states along with maximum acceleration and jerk. The otg() call executes the trajectory generation. ```ST PROGRAM Example02_Velocity VAR otg : Struckig.Otg(cycletime := 0.01, dofs := 3) := ( EnableAutoPropagate := TRUE, ControlInterface := Struckig.ControlInterfaceType.Velocity, CurrentPosition := [0.0, 0.0, 0.5], CurrentVelocity := [3.0, -2.2, -0.5], CurrentAcceleration := [0.0, 2.5, -0.5], TargetVelocity := [0.0, -0.5, -1.5], TargetAcceleration := [0.0, 0.0, 0.5], MaxAcceleration := [3.0, 2.0, 1.0], MaxJerk := [6.0, 6.0, 4.0] ); END_VAR otg(); ``` -------------------------------- ### ValidateInput usage example Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Example call to ValidateInput with currentState: FALSE and targetState: TRUE, returning a boolean. The comment indicates the return value. ```iecst ruckig.ValidateInput(input, currentState: FALSE, targetState: TRUE); // returns boolean __ ``` -------------------------------- ### Method AtTime1 Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Gets the kinematic state at a given time for a single DoF (only for DoF = 1). ```APIDOC ## AtTime1 ### Description Get the kinematic state and current section at a given time without vectors for a single DoF. Using this method is only allowed for DoF = 1, for higher degrees of freedom use AtTime. Using this method for DoF > 0 will not yield any result. ### Method AtTime1 ### Signature ``` METHOD AtTime1 ( [input] t : LREAL, [input] new_position : REFERENCE TO LREAL, [input] new_velocity : REFERENCE TO LREAL, [input] new_acceleration : REFERENCE TO LREAL, [input] new_jerk : REFERENCE TO LREAL) ``` ### Parameters #### Inputs - **t** (LREAL) - Required - Time in seconds. - **new_position** (REFERENCE TO LREAL) - Required - Reference for position output. - **new_velocity** (REFERENCE TO LREAL) - Required - Reference for velocity output. - **new_acceleration** (REFERENCE TO LREAL) - Required - Reference for acceleration output. - **new_jerk** (REFERENCE TO LREAL) - Required - Reference for jerk output. ``` -------------------------------- ### Velocity preset for single-axis trajectory Source: https://stefanbesler.github.io/struckig/userguide/single_axis_trajectory.html A preset configuration for a move starting with initial velocity. ```ST PROGRAM ExampleSingleAxisVelocityPreset VAR otg : Struckig.Otg(cycletime := 0.001, dofs := 1) := ( EnableAutoPropagate := TRUE, CurrentPosition := [0.0], CurrentVelocity := [2.0], CurrentAcceleration := [0.0], TargetPosition := [8.0], TargetVelocity := [1.5], TargetAcceleration := [0.0], MaxVelocity := [3.0], MaxAcceleration := [2.0], MaxJerk := [5.0] ); END_VAR otg(); ``` -------------------------------- ### Method AtTime Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Gets the kinematic state at absolute trajectory time t for all DoFs. ```APIDOC ## AtTime ### Description Gets the kinematic state at absolute trajectory time `t`. This method evaluates the active profile sections and returns position, velocity, acceleration, and jerk for each configured DoF. For `t >= Duration`, the final state is extended with constant acceleration behavior. For single-axis access without vector pointers, see AtTime1. ### Method AtTime ### Signature ``` METHOD AtTime ( [input] t : LREAL, [input] new_position : POINTER TO LREAL, [input] new_velocity : POINTER TO LREAL, [input] new_acceleration : POINTER TO LREAL, [input] new_jerk : POINTER TO LREAL, [input] new_section : POINTER TO INT) ``` ### Parameters #### Inputs - **t** (LREAL) - Required - Absolute trajectory time in seconds. - **new_position** (POINTER TO LREAL) - Required - Pointer to array for position outputs. - **new_velocity** (POINTER TO LREAL) - Required - Pointer to array for velocity outputs. - **new_acceleration** (POINTER TO LREAL) - Required - Pointer to array for acceleration outputs. - **new_jerk** (POINTER TO LREAL) - Required - Pointer to array for jerk outputs. - **new_section** (POINTER TO INT) - Required - Pointer to integer for current section index. ``` -------------------------------- ### Recommended PLC cycle loop with otg() and output mapping Source: https://stefanbesler.github.io/struckig/userguide/cycle_integration.html Use this three-part structure in each PLC cycle: update targets at step boundaries, call otg() exactly once, then map outputs to axis setpoints and handle errors. The example shows error handling via otg.ErrorMessage() and setting interpolated positions and velocities for two axes. ```ST // 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 ``` -------------------------------- ### AtTime Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Gets the kinematic state at absolute trajectory time t. Evaluates active profile sections and returns position, velocity, acceleration, and jerk for each configured DoF. ```APIDOC ## AtTime ### Description Gets the kinematic state at absolute trajectory time `t`. This method evaluates the active profile sections and returns position, velocity, acceleration, and jerk for each configured DoF. For `t >= Duration`, the final state is extended with constant acceleration behavior. For single-axis access without vector pointers, see AtTime1. ### Method AtTime ### Parameters #### Inputs - **t** (LREAL) - Required - Absolute trajectory time. - **new_position** (POINTER TO LREAL) - Required - Output pointer for position. - **new_velocity** (POINTER TO LREAL) - Required - Output pointer for velocity. - **new_acceleration** (POINTER TO LREAL) - Required - Output pointer for acceleration. - **new_jerk** (POINTER TO LREAL) - Required - Output pointer for jerk. - **new_section** (POINTER TO INT) - Required - Output pointer for the current section index. ### Returns None ``` -------------------------------- ### AtTime1 Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Get the kinematic state and current section at a given time without vectors for a single DoF. Only allowed for DoF = 1. ```APIDOC ## AtTime1 ### Description Get the kinematic state and current section at a given time without vectors for a single DoF. Using this method is only allowed for DoF = 1, for higher degrees of freedom use AtTime. Using this method for DoF > 0 will not yield any result. ### Method AtTime1 ### Parameters #### Inputs - **t** (LREAL) - Required - Absolute trajectory time. - **new_position** (REFERENCE TO LREAL) - Required - Output reference for position. - **new_velocity** (REFERENCE TO LREAL) - Required - Output reference for velocity. - **new_acceleration** (REFERENCE TO LREAL) - Required - Output reference for acceleration. - **new_jerk** (REFERENCE TO LREAL) - Required - Output reference for jerk. ### Returns None ``` -------------------------------- ### Property Duration Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Gets the total planned trajectory duration in seconds. ```APIDOC ## PROPERTY Duration ### Description Total planned trajectory duration in seconds. The value is set after successful calculation and remains valid until inputs change or Reset is called. In synchronized operation this is the common duration for all participating DoFs. ### Property Value - **LREAL** - Duration in seconds. ``` -------------------------------- ### FB_init Constructor Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg1.html Initializes the Otg1 trajectory generator with cycle time parameters. ```Structured Text METHOD FB_init ( [input] bInitRetains : BOOL, [input] bInCopyCode : BOOL, [input] cycletime : LREAL) : BOOL __ ``` -------------------------------- ### Constructor FB_init Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Initializes the trajectory generator with cycle time and number of degrees of freedom. ```APIDOC ## FB_init ### Description Initializes the trajectory generator with the given cycle time and number of degrees of freedom. ### Method FB_init ### Signature ``` METHOD FB_init ( [input] bInitRetains : BOOL, [input] bInCopyCode : BOOL, [input] cycletime : LREAL, [input] dofs : SINT) : BOOL ``` ### Parameters #### Inputs - **bInitRetains** (BOOL) - Required - Initialization flag for retain variables. - **bInCopyCode** (BOOL) - Required - Copy code flag. - **cycletime** (LREAL) - Required - Cycle time in seconds. - **dofs** (SINT) - Required - Number of degrees of freedom. ### Returns - **BOOL** - Initialization success flag. ``` -------------------------------- ### FB_init Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg1.html Constructor for the Otg1 trajectory generator. Initializes the instance with the given cycle time and returns a boolean indicating success. ```APIDOC ## FB_init ### Description Constructor for the Otg1 trajectory generator. Initializes the instance with the given cycle time and returns a boolean indicating success. ### Method FB_init ### Parameters #### Inputs - **bInitRetains** (BOOL) - Required - Description not provided. - **bInCopyCode** (BOOL) - Required - Description not provided. - **cycletime** (LREAL) - Required - Description not provided. ### Returns BOOL ``` -------------------------------- ### Initialize Struckig with Runtime-Selected DoFs Source: https://stefanbesler.github.io/struckig/userguide/example_runtime_dofs.html Defines the ActiveDofs constant and initializes the Struckig.Otg function block with specific motion parameters for a 6-DoF system. ```Structured Text PROGRAM Example05_RuntimeDofs VAR CONSTANT ActiveDofs : UINT := 6; // runtime-selected size in this project variant END_VAR VAR otg : Struckig.Otg(cycletime := 0.01, dofs := ActiveDofs) := ( EnableAutoPropagate := TRUE, CurrentPosition := [0.0, -0.1, 0.12, 0.0, 0.3, 0.05], CurrentVelocity := [0.0, 0.0, 0.2, 0.0, 0.0, 0.0], CurrentAcceleration := [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], TargetPosition := [1.0, 0.5, 0.5, 0.0, -0.1, 0.2], TargetVelocity := [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], TargetAcceleration := [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], MaxVelocity := [1.2, 1.2, 1.2, 0.6, 0.6, 0.6], MaxAcceleration := [4.0, 4.0, 4.0, 1.5, 1.5, 1.5], MaxJerk := [10.0, 10.0, 10.0, 4.0, 4.0, 4.0] ); END_VAR otg(); ``` -------------------------------- ### FB_init Constructor Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Initializes the function block with cycle time and degrees of freedom. ```Structured Text METHOD FB_init ( [input] bInitRetains : BOOL, [input] bInCopyCode : BOOL, [input] cycletime : LREAL, [input] dofs : SINT) : BOOL __ ``` -------------------------------- ### Per-DoF control interface and synchronization mixing Source: https://stefanbesler.github.io/struckig/userguide/cycle_integration.html Shows how to mix control interfaces and synchronization modes per axis. Use carefully because mixed policies can change trajectory shape and duration in non-obvious ways. ```ST otg.ControlInterface := Struckig.ControlInterfaceType.Position; otg.PerDofControlInterface[1] := Struckig.ControlInterfaceType.Velocity; otg.Synchronization := Struckig.SynchronizationType.TimeSync; otg.PerDofSynchronization[2] := Struckig.SynchronizationType.None; ``` -------------------------------- ### VelocityAtTime Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Calculates velocity at a given time given initial velocity, acceleration, and jerk. ```APIDOC ## METHOD VelocityAtTime ### Description Calculates velocity at a given time given initial velocity, acceleration, and jerk. ### Inputs - **v0** (LREAL) - Required - Initial velocity. - **a0** (LREAL) - Required - Initial acceleration. - **j** (LREAL) - Required - Jerk. - **t** (LREAL) - Required - Time. ### Returns - **LREAL** - Velocity at time t. ``` -------------------------------- ### Configure a time-constrained single-axis move Source: https://stefanbesler.github.io/struckig/userguide/single_axis_trajectory.html Configures a single-axis trajectory with a specified minimum duration. MinDuration stretches the motion only if the unconstrained solution is faster. ```ST PROGRAM ExampleSingleAxis VAR otg : Struckig.Otg(cycletime := 0.001, dofs := 1) := ( EnableAutoPropagate := TRUE, Synchronization := Struckig.SynchronizationType.TimeSync, MinDuration := 10.0, // considered when synchronization is TimeSync MaxVelocity := [2000.0], MaxAcceleration := [20000.0], MaxJerk := [800000.0], CurrentPosition := [0.0], CurrentVelocity := [0.0], CurrentAcceleration := [0.0], TargetPosition := [100.0], TargetVelocity := [0.0], TargetAcceleration := [0.0] ); END_VAR otg(); ``` -------------------------------- ### AccelerationBrake Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Calculates an acceleration brake profile. ```APIDOC ## METHOD AccelerationBrake ### Description Calculates an acceleration brake profile. ### Inputs - **v0** (LREAL) - Required - Initial velocity. - **a0** (LREAL) - Required - Initial acceleration. - **vMax** (LREAL) - Required - Maximum velocity. - **vMin** (LREAL) - Required - Minimum velocity. - **aMax** (LREAL) - Required - Maximum acceleration. - **aMin** (LREAL) - Required - Minimum acceleration. - **jMax** (LREAL) - Required - Maximum jerk. ``` -------------------------------- ### Method PassOutputToInput Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Copies current cycle outputs to the corresponding current-state inputs. ```APIDOC ## PassOutputToInput ### Description Copies `NewPosition`, `NewVelocity`, and `NewAcceleration` to the corresponding current-state inputs. This helper connects one cycle output to the next cycle input and is useful in closed-loop PLC applications. ### Method PassOutputToInput ### Signature ``` METHOD PassOutputToInput () ``` ### Equivalent Manual Assignment ``` CurrentPosition := NewPosition; CurrentVelocity := NewVelocity; CurrentAcceleration := NewAcceleration; ``` ``` -------------------------------- ### Duration Property Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg1.html Retrieves the total planned trajectory duration in seconds, valid after successful calculation. ```Structured Text PROPERTY Duration : LREAL __ ``` -------------------------------- ### PassOutputToInput Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Copies NewPosition, NewVelocity, and NewAcceleration to the corresponding current-state inputs. Useful in closed-loop PLC applications. ```APIDOC ## PassOutputToInput ### Description Copies `NewPosition`, `NewVelocity`, and `NewAcceleration` to the corresponding current-state inputs. This helper connects one cycle output to the next cycle input and is useful in closed-loop PLC applications. ### Method PassOutputToInput ### Parameters None ### Returns None ``` -------------------------------- ### Recommended usage of ValidateInput before applying new targets Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Recommended pattern: call ValidateInput with both arguments TRUE, then either call the cyclic calculation or inspect ErrorCode and ErrorMessage. ```iecst IF otg.ValidateInput(TRUE, TRUE) THEN // inputs are valid, call cyclic calculation otg(); ELSE // inspect otg.ErrorCode() and otg.ErrorMessage() END_IF __ ``` -------------------------------- ### SmoothVelocityBrake Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Jerk-limited brake from (v0, a0) to (vTarget, a=0). Produces a 2- or 3-phase profile that ends with zero acceleration. ```APIDOC ## METHOD SmoothVelocityBrake ### Description Jerk-limited brake from (v0, a0) to (vTarget, a=0). Produces a 2- or 3-phase profile that ends with zero acceleration, so Step1 does not inherit a large residual deceleration. jMax > 0 means braking from above (v0 > vTarget), jMax < 0 means from below. If the profile cannot be computed (e.g. a0 opposes braking too strongly), t[0] remains 0 so the caller can fall back to legacy VelocityBrake. ### Inputs - **v0** (LREAL) - Required - Initial velocity. - **a0** (LREAL) - Required - Initial acceleration. - **vTarget** (LREAL) - Required - Target velocity. - **aMax** (LREAL) - Required - Maximum acceleration. - **jMax** (LREAL) - Required - Maximum jerk. ``` -------------------------------- ### Calculate Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Internal method for performing trajectory calculations. ```Structured Text METHOD PRIVATE Calculate () __ ``` -------------------------------- ### Reset Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Resets the instance (e.g. to force a new calculation on the next update). Use when external state jumps occur. ```APIDOC ## Reset ### Description Resets the instance (e.g. to force a new calculation on the next update). This method can be used to trigger a new trajectory even if inputs do not change. Use this when external state jumps occur (manual jog, homing, drive reset) and the generator must reinitialize from the new measured state. ### Method Reset ### Parameters None ### Returns None ``` -------------------------------- ### Method Reset Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Resets the instance to force a new calculation on the next update. ```APIDOC ## Reset ### Description Resets the instance (e.g. to force a new calculation on the next update). This method can be used to trigger a new trajectory even if inputs do not change. Use this when external state jumps occur (manual jog, homing, drive reset) and the generator must reinitialize from the new measured state. ### Method Reset ### Signature ``` METHOD Reset () ``` ``` -------------------------------- ### ValidateInput Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg1.html Validates input states against kinematic limits before trajectory calculation. ```Structured Text METHOD ValidateInput ( [input] checkCurrentStateWithinLimits : BOOL, [input] checkTargetStateWithinLimits : BOOL) : BOOL __ ``` ```Structured Text ruckig.ValidateInput(input, currentState: FALSE, targetState: TRUE); // returns boolean __ ``` ```Structured Text Abs(acceleration) <= Sqrt(2 * max_jerk * (max_velocity - Abs(velocity))). __ ``` ```Structured Text IF otg.ValidateInput(TRUE, TRUE) THEN // inputs are valid, call cyclic calculation otg(); ELSE // inspect otg.ErrorCode() and otg.ErrorMessage() END_IF __ ``` -------------------------------- ### Ruckig MIT License Source: https://stefanbesler.github.io/struckig/userguide/notices.html The MIT License notice for the ruckig project, which Struckig is a port of. It grants permission to use, copy, modify, merge, publish, distribute, sublicense, and sell copies of the software, subject to the conditions stated. ```text MIT License Copyright (c) 2021-2024 Lars Berscheid Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` -------------------------------- ### Constraint-limited preset for single-axis trajectory Source: https://stefanbesler.github.io/struckig/userguide/single_axis_trajectory.html A preset configuration with tighter constraints on velocity, acceleration, and jerk. ```ST PROGRAM ExampleSingleAxisConstraintPreset VAR otg : Struckig.Otg(cycletime := 0.001, dofs := 1) := ( EnableAutoPropagate := TRUE, CurrentPosition := [0.0], CurrentVelocity := [0.0], CurrentAcceleration := [0.0], TargetPosition := [10.0], TargetVelocity := [0.0], TargetAcceleration := [0.0], MaxVelocity := [1.5], MaxAcceleration := [0.8], MaxJerk := [1.0] ); END_VAR otg(); ``` -------------------------------- ### Finalize Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Finalizes third-order braking by integrating along kinematic state. ```APIDOC ## METHOD Finalize ### Description Finalizes third-order braking by integrating along kinematic state. ### InOuts - **ps** (LREAL) - InOut - Position state. - **vs** (LREAL) - InOut - Velocity state. - **as** (LREAL) - InOut - Acceleration state. ``` -------------------------------- ### Position preset for single-axis trajectory Source: https://stefanbesler.github.io/struckig/userguide/single_axis_trajectory.html A preset configuration for a standard position-based move. ```ST PROGRAM ExampleSingleAxisPositionPreset VAR otg : Struckig.Otg(cycletime := 0.001, dofs := 1) := ( EnableAutoPropagate := TRUE, CurrentPosition := [0.0], CurrentVelocity := [0.0], CurrentAcceleration := [0.0], TargetPosition := [10.0], TargetVelocity := [0.0], TargetAcceleration := [0.0], MaxVelocity := [3.0], MaxAcceleration := [2.0], MaxJerk := [5.0] ); END_VAR otg(); ``` -------------------------------- ### Cyclic Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html This method simply calls the body of the function block. ```APIDOC ## Cyclic ### Description This method simply calls the body of the function block. ### Method Cyclic ### Parameters None ### Returns None ``` -------------------------------- ### ValidateInput Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Checks that the Struckig OTG can generate a trajectory before the actual calculation step. Returns FALSE if an input is not valid. ```APIDOC ## ValidateInput ### Description To check that _Struckig_ is able to generate a trajectory before the actual calculation step, returns `FALSE` if an input is not valid. The two boolean arguments check that the current or target state are within the limits. The check includes a typical catch of jerk-limited trajectory generation: When the current state is at maximal velocity, any positive acceleration will inevitable lead to a velocity violation _at a future timestep_. In general, this condition is fulfilled when `Abs(acceleration) <= Sqrt(2 * max_jerk * (max_velocity - Abs(velocity)))`. If both arguments are set to true, the calculated trajectory is guaranteed to be _within the kinematic limits throughout_ its duration. Also, note that there are range constraints of the input due to numerical reasons. ### Method ValidateInput ### Parameters #### Inputs - **checkCurrentStateWithinLimits** (BOOL) - Required - Check if current state is within limits. - **checkTargetStateWithinLimits** (BOOL) - Required - Check if target state is within limits. ### Returns - **BOOL** - TRUE if inputs are valid, FALSE otherwise. ``` -------------------------------- ### SecondOrderPositionBrakeTrajectory Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Calculates brake trajectory for second-order position interface. ```APIDOC ## METHOD SecondOrderPositionBrakeTrajectory ### Description Calculates brake trajectory for second-order position interface. ### Inputs - **v0** (LREAL) - Required - Initial velocity. - **vMax** (LREAL) - Required - Maximum velocity. - **vMin** (LREAL) - Required - Minimum velocity. - **aMax** (LREAL) - Required - Maximum acceleration. - **aMin** (LREAL) - Required - Minimum acceleration. ``` -------------------------------- ### AtTime1 method declaration Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Declares the AtTime1 method that returns the kinematic state for a single DoF without vector pointers. Only allowed for DoF = 1; for higher degrees of freedom use AtTime. Using this method for DoF > 0 will not yield any result. ```iecst METHOD AtTime1 ( [input] t : LREAL, [input] new_position : REFERENCE TO LREAL, [input] new_velocity : REFERENCE TO LREAL, [input] new_acceleration : REFERENCE TO LREAL, [input] new_jerk : REFERENCE TO LREAL) __ ``` -------------------------------- ### PassOutputToInput method declaration and equivalent assignments Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Declares the PassOutputToInput method that copies NewPosition, NewVelocity, and NewAcceleration to the corresponding current-state inputs. The equivalent manual assignments are shown. ```iecst METHOD PassOutputToInput () __ ``` ```iecst CurrentPosition := NewPosition; CurrentVelocity := NewVelocity; CurrentAcceleration := NewAcceleration; __ ``` -------------------------------- ### SecondOrderVelocityBrakeTrajectory Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Calculates brake trajectory for second-order velocity interface. ```APIDOC ## METHOD SecondOrderVelocityBrakeTrajectory ### Description Calculates brake trajectory for second-order velocity interface. ### Parameters No parameters. ``` -------------------------------- ### VelocityBrake Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Calculates a velocity brake profile. ```APIDOC ## METHOD VelocityBrake ### Description Calculates a velocity brake profile. ### Inputs - **v0** (LREAL) - Required - Initial velocity. - **a0** (LREAL) - Required - Initial acceleration. - **vMax** (LREAL) - Required - Maximum velocity. - **vMin** (LREAL) - Required - Minimum velocity. - **aMax** (LREAL) - Required - Maximum acceleration. - **aMin** (LREAL) - Required - Minimum acceleration. - **jMax** (LREAL) - Required - Maximum jerk. ``` -------------------------------- ### VelocityAtZeroAcceleration Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Calculates velocity at the moment acceleration becomes zero. ```APIDOC ## METHOD VelocityAtZeroAcceleration ### Description Calculates velocity at the moment acceleration becomes zero. ### Inputs - **v0** (LREAL) - Required - Initial velocity. - **a0** (LREAL) - Required - Initial acceleration. - **j** (LREAL) - Required - Jerk. ### Returns - **LREAL** - Velocity at zero acceleration. ``` -------------------------------- ### FinalizeSecondOrder Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Finalizes second-order braking by integrating along kinematic state. ```APIDOC ## METHOD FinalizeSecondOrder ### Description Finalizes second-order braking by integrating along kinematic state. ### InOuts - **ps** (LREAL) - InOut - Position state. - **vs** (LREAL) - InOut - Velocity state. - **as** (LREAL) - InOut - Acceleration state. ``` -------------------------------- ### Clamp Source: https://stefanbesler.github.io/struckig/reference/Struckig/Clamp.html Clamps a value to the closed interval [minimum, maximum]. Returns the minimum if the value is below the lower bound, the maximum if above the upper bound, and the value itself otherwise. ```APIDOC ## Clamp ### Description Clamps `value` to the closed interval `[minimum, maximum]`. If `value` is below `minimum`, returns `minimum`. If `value` is above `maximum`, returns `maximum`. ### Namespace Struckig ### Function Signature FUNCTION Clamp ( [input] value : LREAL, [input] minimum : LREAL, [input] maximum : LREAL) : LREAL ### Parameters #### Inputs - **value** (LREAL) - Required - Input value to clamp. - **minimum** (LREAL) - Required - Lower bound. - **maximum** (LREAL) - Required - Upper bound. ### Returns - **LREAL** - The clamped value. ``` -------------------------------- ### HasChanged Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Checks if the internal state has changed. ```Structured Text METHOD PRIVATE HasChanged () : BOOL __ ``` -------------------------------- ### AtTime method declaration Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Declares the AtTime method that returns the kinematic state (position, velocity, acceleration, jerk) and section at absolute trajectory time t. For t >= Duration, the final state is extended with constant acceleration behavior. Use AtTime1 for single-axis access without vector pointers. ```iecst METHOD AtTime ( [input] t : LREAL, [input] new_position : POINTER TO LREAL, [input] new_velocity : POINTER TO LREAL, [input] new_acceleration : POINTER TO LREAL, [input] new_jerk : POINTER TO LREAL, [input] new_section : POINTER TO INT) __ ``` -------------------------------- ### Condition for valid input Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Mathematical condition that must be fulfilled for the input to be valid, related to jerk-limited trajectory generation. ```text Abs(acceleration) <= Sqrt(2 * max_jerk * (max_velocity - Abs(velocity))). ``` -------------------------------- ### SetBusy Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Sets the busy status of the function block. ```Structured Text METHOD PROTECTED SetBusy ( [input] on : BOOL) __ ``` -------------------------------- ### AccelerationBrake method declaration Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Declares the AccelerationBrake method with inputs v0, a0, vMax, vMin, aMax, aMin, jMax. ```iecst METHOD AccelerationBrake ( [input] v0 : LREAL, [input] a0 : LREAL, [input] vMax : LREAL, [input] vMin : LREAL, [input] aMax : LREAL, [input] aMin : LREAL, [input] jMax : LREAL) __ ``` -------------------------------- ### PositionBrakeTrajectory Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/BrakeProfile.html Calculates brake trajectory for third-order position interface. ```APIDOC ## METHOD PositionBrakeTrajectory ### Description Calculates brake trajectory for third-order position interface. ### Inputs - **v0** (LREAL) - Required - Initial velocity. - **a0** (LREAL) - Required - Initial acceleration. - **vMax** (LREAL) - Required - Maximum velocity. - **vMin** (LREAL) - Required - Minimum velocity. - **aMax** (LREAL) - Required - Maximum acceleration. - **aMin** (LREAL) - Required - Minimum acceleration. - **jMax** (LREAL) - Required - Maximum jerk. - **SmoothBrake** (BOOL) - Required - Indicates if smooth braking is used. ``` -------------------------------- ### ErrorMessage Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Returns a human-readable error description. If no custom error text exists, a default description is derived from ErrorCode. ```APIDOC ## ErrorMessage ### Description Returns a human-readable error description. If no custom error text exists, a default description is derived from ErrorCode. ### Method ErrorMessage ### Parameters None ### Returns - **STRING(255)** - The error message. ``` -------------------------------- ### Method ErrorCode Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Returns the current error code for diagnostics. ```APIDOC ## ErrorCode ### Description Returns the current error code. Use together with ErrorMessage for diagnostics. ### Method ErrorCode ### Signature ``` METHOD ErrorCode () : TrajectoryErrorCode ``` ### Returns - **TrajectoryErrorCode** - Current error code. ``` -------------------------------- ### ValidateInputOrAbort method declaration Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Declares the protected ValidateInputOrAbort method with the same parameters and return type as ValidateInput. ```st METHOD PROTECTED ValidateInputOrAbort ( [input] checkCurrentStateWithinLimits : BOOL, [input] checkTargetStateWithinLimits : BOOL) : BOOL __ ``` -------------------------------- ### Otg Function Block Definition Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html The interface definition for the Otg function block, detailing all input and output parameters for trajectory generation. ```Structured Text FUNCTION_BLOCK Otg IMPLEMENTS Struckig.IOtg ( [input] CycleTime : LREAL, [input] Dofs : INT, [input] Enabled : ARRAY[0..ParameterList.MaxDoFs] OF BOOL, [input] ControlInterface : ControlInterfaceType, [input] Synchronization : SynchronizationType, [input] PerDofControlInterface : ARRAY[0..ParameterList.MaxDoFs] OF ControlInterfaceType, [input] PerDofSynchronization : ARRAY[0..ParameterList.MaxDoFs] OF SynchronizationType, [input] Discretization : DiscretizationType, [input] CurrentPosition : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] CurrentVelocity : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] CurrentAcceleration : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] TargetPosition : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] TargetVelocity : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] TargetAcceleration : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] MaxVelocity : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] MaxAcceleration : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] MaxJerk : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] MinVelocity : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] MinAcceleration : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [input] MinDuration : LREAL, [input] EnableAutoPropagate : BOOL, [input] SmoothBrake : BOOL, [output] NewPosition : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [output] NewVelocity : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [output] NewAcceleration : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [output] NewJerk : ARRAY[0..ParameterList.MaxDoFs] OF LREAL, [output] NewCalculation : BOOL, [output] CurrentTime : LREAL) ``` -------------------------------- ### ValidateInput condition for jerk-limited trajectory generation Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Mathematical condition that must be fulfilled to avoid velocity violations at a future timestep when the current state is at maximal velocity. ```text Abs(acceleration) <= Sqrt(2 * max_jerk * (max_velocity - Abs(velocity))). __ ``` -------------------------------- ### Fmod Source: https://stefanbesler.github.io/struckig/reference/Struckig/Fmod.html Computes the floating-point remainder of x / y with truncation toward zero. ```APIDOC ## Fmod ### Description Computes the floating-point remainder of `x / y` with truncation toward zero: `x - TRUNC(x / y) * y`. ### Function Signature `FUNCTION Fmod (x : LREAL, y : LREAL) : LREAL` ### Parameters - **x** (LREAL) - Required - Dividend. - **y** (LREAL) - Required - Divisor. ### Returns - **LREAL** - The remainder of `x / y`. ``` -------------------------------- ### Reset method declaration Source: https://stefanbesler.github.io/struckig/reference/Struckig/IOtg.html Declares the Reset method that resets the instance to force a new calculation on the next update. Use when external state jumps occur (manual jog, homing, drive reset) and the generator must reinitialize from the new measured state. ```iecst METHOD Reset () __ ``` -------------------------------- ### AbortErrorId Method Source: https://stefanbesler.github.io/struckig/reference/Struckig/Otg.html Handles error aborting with an error ID and message. ```Structured Text METHOD PROTECTED AbortErrorId ( [input] errorId : INT, [inout] message : STRING) __ ```