Application example
EtherCAT XML Device Description The display matches that of the CoE objects from the EtherCAT XML Device Description. We recommend downloading the latest XML file from the download area of the Beckhoff website and installing it according to installation instructions. |
Motor control with visualization
Sample program (download)
Used Master: TwinCAT 2.11 (for older versions the control loop has to be programmed manually; in this case it is already implemented in the NC).
This application example demonstrates movement of a motor to any position or in continuous mode with the aid of visualization. The velocity, the starting acceleration and the deceleration can be specified.
The sample program consists of two files (PLC file and System Manager file).
First open the PLC file and compile it so that you have the *.tpy file available that is required for the System Manager.
Please note that you may have to adjust the target platform in the PLC program (default: PC or CX 8x86). If required, you can select the right target platform in the Resources -> Controller configuration tab.
Please note the following for the System Manager file:
- Start the System Manager in Config mode.
- Please ensure that the I/O configuration matches your actual configuration. In the sample program only one EL7041 is integrated. If further terminals are connected you have to add them or re-scan your configuration.
- You have to adjust the MAC address. To do this, click on your EtherCAT device, then select the Adapter tab and click on Search after the MAC address (see Fig. Selecting the MAC address). Select the right adapter.
- In the PLC configuration you have to adjust the path for the PLC program. Click on the appended PLC program and select the tab IEC1131 (see Fig. Changing the PLC path). Select Change and enter the correct path.
- Under NC configuration an EL7041 is already linked to the NC. To change the link or add additional devices proceed as described under "Integration into the NC configuration".
The PLC program is configured as follows. The libraries TcMC.lib and TcNC.lib must be integrated (see Fig. Required libraries).
Once this is done, certain global variables are declared (see Fig. Global variables). The data types PLCTONC_AXLESTRUCT and NCTOPLC_AXLESTRUCT deal with the communication between the PLC and the NC.
Once the global variables have been declared, programming can commence. Start with declaring local variables (see Fig. Local variables).
MC_Direction is an enumeration type that specifies the direction of movement for the MC_MoveVelocity function block, which in turn initiates continuous travel of the motor.
An axis reset is carried out with the MC_Reset function block. Absolute positioning is carried out with the MC_MoveAbsolute function block. The current axis position can be read with the MC_ActualPosition function block.
MC_Power enables the axis; MC_Stop is required for stopping the axis.
The program code is as follows (see Fig. Program code):
The motor can then be operated with the aid of the following visualization (see Fig. Visualization).
Press Enable to enable the axis. In "Free run mode" you can now use the Left or Right buttons, and the motor will run with a speed defined under fbMoveVelocity_Axis_1 in the selected direction. In "Absolute mode" you can specify a Velocity, Acceleration, Deceleration and the Setpoint Position and initiate the motion with Start Job. If no values are entered for acceleration and deceleration the default value of the NC is used.
Information on function blocks and data types Further information on the function blocks and data types used can be found in the Beckhoff Information System. |