External setpoint generation

External setpoint generation can be used to implement a custom setpoint profile that is not available by default in TwinCAT MC3. This profile can be mathematically very simple or as complex as necessary. In external setpoint generation, the setpoints are generated in function blocks or TcCOM modules that implement the ITcMcExternalSetpointGenerator interface. This is called from the MC context.

The main input is ExternalSetpointGenerator of type ITcMcExternalSetpointGenerator. This interface defines methods that must be implemented (e.g., by a PLC FB). These methods are called by the MC task context (MET-Task) via a Callback mechanism. This mechanism forms the basis for decoupling the MC task and the PLC task during external setpoint generation. This basic operating principle is represented in the figure below.

External setpoint generation 1:

With the MC3, it is possible to execute PLC and MC3 axes with different cycle times in different contexts when using external setpoint generation. Be aware of the update rate of the data used in the Callback methods when AllowOtherContext is enabled.

MC3 can check the calculated setpoints for consistency (from the previous cycle to the current cycle, taking into account the maximum dynamic parameters of the axis). To do so, set EnableDynamicChecks := TRUE.

The interpretation of the input variable InvokeId, which is of type XWORD, is customer-specific. For example, any numeric value or the address (pointer) to a customer-specific data structure can be passed. This InvokeId is passed as an input to every method included in the interface.

The Callback methods contained in the ITcMcExternalSetpointGenerator interface are called by the MC task context (MET task) in the order listed:

  1. OnPreparation (invokeId : XWORD)
  2. OnStartPointInitialization (invokeId : XWORD, startDcTime : LINT, position : LREAL, velocity : LREAL, acceleration : LREAL)
  3. ABSTRACT OnCyclicSetpointGeneration (invokeId : XWORD,
    timeInGeneration : LREAL, position : REFERENCE TO LREAL,
    velocity : REFERENCE TO LREAL, acceleration : REFERENCE TO LREAL)
  4. OnDeactivation (invokeId : XWORD)

The FB MC_ExternalSetpointGenerator provides the API for the implementation of external setpoint generation from the PLC environment. The component diagram below represents the relationships between the modules. The generator itself is a TcCOM object that is created at runtime and registered in the TwinCAT system (TcBaseModuleRegistered). This Generator FB already implements methods for handling online change processes. As a core feature, it implements the ITcMcExternalSetpointGenerator (an extension of ITcUnknown).

External setpoint generation 2: