Main Content

EtherCAT® Protocol Motor Position Control with Accelnet™ Drive

This example shows how to control the position of a motor by using EtherCAT communication. The example motor drive is from Copley Instruments. This drive uses the CIA-402 (Can In Automation 402) device profile common to many drives. The example can work with other CIA-402 EtherCAT drives if you generate an appropriate ENI file.

Requirements

This example is preconfigured to use an EtherCAT network that consists of the target computer as EtherCAT Master device and an Accelnet™ AEP 180-18 drive from Copley Controls as EtherCAT Slave device. Connect a supported brushless or brush motor to the drive. An example motor that works with this example is the SM231BE-NFLN from PARKER.

EtherCAT in Simulink Real-Time requires a dedicated network port on the target computer that is reserved for EtherCAT use by using the Ethernet configuration tool. Configure the dedicated port for EtherCAT communication, not with an IP address. The dedicated port must be distinct from the port used for the Ethernet link between the development and target computers.

To test this model:

  1. Connect the port that is reserved for EtherCAT in the target computer to the EtherCAT IN port of the Accelnet™ drive.

  2. Connect a motor to the Accelnet™ Drive.

  3. Make sure the Accelnet™ drive is supplied with a 24-volt power source.

  4. Build and download the model onto the target.

For a complete example that configures the EtherCAT network, configures the EtherCAT master node model, and builds then runs the real-time application, see Modeling EtherCAT Networks.

Open the Model

This model creates a sine wave, and modulates it by multiplying by the value of the slider control. The modulated signal is sent as motor position command to the drive.

The EtherCAT initialization block requires that the configuration ENI file is present in the current folder. Copy the example configuration file from the example folder to the current folder. To open the model, in the MATLAB Command Window, type:

open_system(fullfile(matlabroot,'toolbox','slrealtime','examples','slrt_ex_ethercatPositionControl'));

Figure 1: EtherCAT model for controlling the position of a motor.

Configure the Model

Open the parameter dialog for the EtherCAT Init block and observe the pre-configured values. The EtherCAT slave devices that are daisy chained together with Ethernet cable is a Device, also referred to as an EtherCAT network. The Device Index selects one such chained EtherCAT network. The Ethernet Port Number identifies which Ethernet port to use to access that Device. The EtherCAT Init block connects these two so that other EtherCAT blocks use the Device Index to communicate with the slave devices on that EtherCAT network.

If you only have one connected network of EtherCAT slaves, and you have only reserved one Ethernet port with the Ethernet configuration tool, use Device Index = 0 and Ethernet Port Number = 1.

Create an ENI File for a Different CIA-402 Drive

If you need to create a new ENI file, you need to use a third-party EtherCAT configurator such as TwinCAT 3 from Beckhoff that you install on a development computer. The EtherCAT configuration (ENI) file preconfigured for this model is CopleyMotorPositionConfig.xml.

Each ENI file is specific to the exact network setup from which it was created (for example, the network discovered in step 1 of the configuration file creation process). The configuration file provided for this example is valid if and only if the EtherCAT network consists of one Accelnet™ drive from Copley Controls. If you have a different EtherCAT drive that uses the CIA-402 CanOpen profile, this example still works, but you need to create a new ENI file that uses your drive. Refer to Can In Automation web site at www.can-cia.org for details. EtherCAT CoE embeds CanOpen addressing for process variables using EtherCAT as the transport layer instead of CAN.

An overview of the process for creating an ENI file is at Configure EtherCAT Network by Using TwinCAT 3

For this example, four receive PDO variables are defined in the configuration file and three are used in the three EtherCAT PDO Transmit blocks: Control Word, Modes of Operation, and Profile Target Position. The fourth variable: Target Velocity is used in example EtherCAT® Protocol Motor Velocity Control with Accelnet™ Drive.

  • The Control Word PDO variable serves to control the state of the drive. The constant value 15 is given as input to the block to set the first 4 bits to 1 to enable the drive. For details on the bit mapping of this variable, refer to the Can In Automation web site. This variable and bit mapping is in the CIA-402 device profile.

  • The Modes of Operation PDO variable serves to set the operating mode of the drive. The constant value 8 is given as input to the block to set the mode of the drive to Cyclic Synchronous Position mode. For detailed documentation, refer to the Can In Automation web site. This variable is in the CIA-402 device profile.

  • The Profile Target Position PDO variable serves to set the desired position. In this example, the position command given as input to the block is a sine wave modulated by the constant Amplitude value linked to the slider control in the model.

Transmit PDO variables (transmitted by the slave) are also defined in the configuration file and one is used in the EtherCAT PDO Receive block: Actual Motor Position for the drive. The Actual Motor Position PDO variable indicates the current value of the motor position as read in the drive. Make sure the required transmit and receive PDO variables are selected in the blocks before running the example. You could need to refresh these variables. Note that EtherCAT refers to variables that the slave sets as transmit variables which are received by the target model.

Make sure that the required transmit and receive PDO variables are selected in the blocks as illustrated in Figure 1 before running the example. You could need to refresh these variables by opening the dialogs and selecting the current variable again.

Build, Download, and Run the Model

To build, download, and run the model:

  1. In the Simulink Editor, from the targets list on the Real-Time tab, select the target computer on which to run the real-time application.

  2. Click Run on Target.

If you open the two host side scopes by double clicking each, data is relayed from the target back to the development computer and displayed.

Included in the model is the ability to control the amplitude of the cycling motion. With the Run on Target button, the slider is active and connected to the Amplitude constant block.

The model is preconfigured to run for 10 seconds. If you want to run the model longer, pull down the Run on Target menu and change the number on the bottom line. Press the green arrow to configure, build and run.

Display the Target Computer data

If you run the model using the Run on Target button, external mode is connected and you can double click the scope blocks and see the data on the host. Also, the slider is active in external mode.

Scope shows the Distributed Clocks timing difference between the master stack running on the target computer and the timing on the drive. This ENI file is configured to use Master Shift mode for DC. The clock on the target computer is adjusted to match the timing on the EtherCAT reference clock on the first DC enabled slave.

Scope1 shows the state progression from Idle to Init (=1) to PreOp (=2) to SafeOp (=4) for a very short time visible if you zoom in, to Op (=8) at around 4.3 seconds.

Scope2 shows both the sine wave being sent to the drive (blue) and the actual position (yellow). This is zoomed into the few seconds right when the drive went to Op state and external control starts. Since the motor hardware cannot respond instantaneously, and the commanded position is not 0, you see the actual position ramp up and overshoot slightly before settling down to follow the commanded position. The time delay between command and actual is roughly 18 sample time steps with this drive. The controller inside the drive and motor inertia are responsible for this longer time delay. Other drives may have different delay characteristics.

After running the model, you can use the Simulation Data Inspector to view any signal that has been marked for signal logging. Signals marked for signal logging have a dot with two arcs above it in the model editor.

Observations to notice

This is a simple motor control example. The numerous tunable parameters inside the drive are not adjusted in this model. Adjusting those needs a more advanced model using the CoE/SDO blocks.

Close the Model

When the example completes its run, stop and close the model.

close_system('slrt_ex_ethercatPositionControl');

See Also