Program example: motor controller with visualization
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. |
Download (example file)
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 example program consists of two files. On the one hand the PLC file and on the other 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 target platform under Resources -> Controller configuration.
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 EL7342 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. Selection of adapter). 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 path of the PLC program). 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 travel for the block MC_MoveVelocity, which in turn initiates continuous travel of the motor.
An axis reset is carried out with the function block MC_Reset. Absolute positioning is carried out with the function block MC_MoveAbsolute. The current axis position can be read with the function block MC_ActualPosition.
MC_Power enables the axis; MC_Stop is required for stopping the axis.
The program can then be programmed 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. You now have the choice. You can press the Left or Right button in free run mode and the motor will turn at the velocity defined in fbMoveVelocity_Axis_1 in the selected direction. Or you can specify in Absolute mode velocity, acceleration, deceleration and the position to be driven to and start the drive 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. |