Simulation of an EtherCAT based servo drive axis

TwinCAT 3 Technology Functions offers two types of EtherCAT-based servo drives: SoE and CoE devices. Both protocols can be used in real machines, but simulating the real behavior is an additional challenge. In CoE drives, a device reset command is triggered via a ControlWord/StatusWord mechanism, while SoE drives use acyclic ADS via EtherCAT communication. Since the simulation of the SoE mechanism is much more complicated, only a CoE-based simulation is provided.

Implementing a simulated servo axis

A simulation requires an implementation that can run in one of two places:

Instantiation in the same context:

Designation

Type

Description

{attribute 'TcContextName':='FastTask'}

Instructs TwinCAT to update the I/O of the FB_SimCoE402_Servo class in a specified task. The task should be identical to the call of the Cyclic() method of the simulation block.

fbNcAxisSim

FB_SimCoE402_Servo

Creates an instance of the simulation block.

bNcAxisSimGoError

BOOL

Creates a signal with which the simulation triggers an error state and requests a reset procedure.

fbNcAxisSimLimiter

FB_SimTorqueLimitingCoE402_Servo

Creates an instance of a FB that is needed to provide the simulation with the torque limitation capability. This FB will exchange data with the control functionality via an interface access.

Instantiation in a separate context:

Designation

Type

Description

{attribute 'TcContextName':='FastTask'}

Instructs TwinCAT to update the I/O of the FB_SimCoE402_Servo class in a specified task. The task should be identical to the call of the Cyclic() method of the simulation block.

fbNcAxisSim

FB_SimCoE402_Servo

Creates an instance of the simulation block.

bNcAxisSimGoError

BOOL

Creates a signal with which the simulation triggers an error state and requests a reset procedure.

{attribute 'TcContextName':='FastTask'}

Instructs the following instance to be updated in a specified task. The task should be identical to the call of the Cyclic() method of the simulation block.

fbNcAxisSimLimiter

FB_SimTorqueLimitingCoE402_Mapped

Creates an instance of a FB that is needed to provide the simulation with the torque limitation capability. This FB exchanges data with the control functionality via mapping.

Initialization of a simulated servo axis

Initialization is required during the start-up phase. The following list can be used as an example.

IF NOT bInitialised AND bSimulation THEN
    fbNcAxisSim.EncoderWeighting:=5.0;
    fbNcAxisSim.EncoderZeroShift:=100.0;
    fbNcAxisSim.EncoderNoiseLevel:=0.001;
    fbNcAxisSim.HighSideBlock:=700.0;
    fbNcAxisSim.HighSideSpringLength:=1.0;
    fbNcAxisSim.LowSideBlock:=100.0;
    fbNcAxisSim.LowSideSpringLength:=1.0;
    fbNcAxisSim.PositionLagKp:=1.0;
    fbNcAxisSim.HighSideEndswitch:=699.0;
    fbNcAxisSim.LowSideEndswitch:=101.0;
    fbNcAxisSim.AbsSwitchHighEnd:=679.0;
    fbNcAxisSim.AbsSwitchLowEnd:=21.0;
    // the next line must be used if the simulation
    // is implemented in a separate context
    fbNcAxisSimLimiterMapped.ConnectToSim(ipSim:=fbNcAxis2Sim);
    // the next two lines must be used if the simulation
    // is implemented in the same context
    fbNcAxisSimLimiter.ConnectToSim(ipSim:=fbNcAxis2Sim);
    iNcAxis.SetTorqueLimiting(fbNcAxisSimLimiter);
END_IF

The last line defines the class used by the axis for torque limitation when the simulation is performed in the same context. In this case the penultimate line is required to connect this class to the drive simulation.

Above these lines is an example of implementation in a separate context.

Mapping of a simulated servo axis

The simulation FB provides a local instance of a mapping interface defined as follows:

NcAdapt : FB_SimCoE402_ServoNcAdapt;

The supplied mapping structures for encoder and drive inputs and outputs are compatible with the TwinCAT NC interfaces and can thus be used.

Functionality of the CoE402 simulation

All mechanisms that use mapped interfaces are supported in a way that is expected by TwinCAT NC. This also includes torque limitation.

Since there is no way to emulate ADS communication, some mechanisms cannot be supported.