Beckhoff TwinCAT (Beckhoff) Application Tutorial 12.2 Preliminary Control of Panasonic Servo NC


In the previous section, we learned how to perform trial runs using Beckhoff's built-in debugging software. Now, let's achieve the same functionality using TWINCAT PLC. Right-click on PLC to add a new PLC project.










Right-click on VISUs to add a Human-Machine Interface (HMI) interface.











Currently, both the PLC program and the Human-Machine Interface (HMI) are empty. We aim to implement our custom point-to-point movement through these components. Start by right-clicking on "Reference" to add the TC2_MC2 library (this library pertains to the Motion Control) to the project.









Right-click on GLVs (Global Variables) and add two global variables, ensuring their type is AXIS_REF (a specialized type for interacting with NC axes). In TWINCAT 2, there's a slight difference – one AXIS_REF is equivalent to a pair of PlcToNC and NcToPlc variables (as the PLC needs to send data to the drive and retrieve specific data from the drive, essentially forming a pair of variables). However, TWINCAT 3 combines them into one.


Axis_1: AXIS_REF; PlcToNc AT %Q* : PLCTONC_AXLESTRUCT; NcToPlc AT %I* : NCTOPLC_AXLESTRUCT;
















Select Axis_1, then in "Link To PLC," choose the recently created AXIS_REF type variable. If it doesn't appear, click on "Activate Configuration" in the upper left corner, then proceed with the binding.


    









When writing the specific program (I won't go through every line, but referencing the code along with basic training videos should be sufficient), pay attention to the fact that we added a variable of a special type. By adding AT%Q to the variable, it indicates that it can be bound to a specific parameter in the drive (for writing values from the PLC to the drive). As mentioned earlier, before actual execution, set the "Modes of operation" to 8. This needs to be done in the MAIN program first, then activate the configuration, and proceed to bind it manually.


AxisControlWord AT %Q* : SINT := 8; // Normally will be 8













Note: Since this is just a preliminary verification, the program structure will be simplified as much as possible. However, obtaining position, velocity, and error is essential in any project, and it should be placed at the very beginning of the program. Once an error occurs, subsequent actions should be halted.










Note: The main program switches between different functionalities using an INT-type variable (this is a custom choice, where, for example, the value 1 could represent error clearance, 2 for enabling upwards motion, 3 for enabling downwards motion, and so forth). It is recommended that when the variable is in state 0, all blocks associated with the intended functionality should be set to FALSE and executed. This way, the next time a button is clicked, a rising edge is generated, triggering the motion (it's essential to fully understand the principle of the TWINCAT scan cycle – for many function blocks to execute, they need to have a FALSE state in the current cycle and a TRUE state in the next cycle to generate a rising edge).




























































Explanation: During the execution of each functional block, try to incorporate a condition that, if the execution is successful, assigns the string "done"; otherwise, set it to "doing". This helps differentiate whether the execution was successful, and this string status can be viewed on the Human-Machine Interface (HMI). Of course, you could also check if a specific variable in the functional block is TRUE every time, but the former approach is more efficient – you only need to check the HMI once.

Explanation: Most of the demonstrated function blocks here are not practical for actual projects (or at least rarely used). For instance, an absolute motion module can achieve functionalities like relative motion and constant velocity motion, making the corresponding function blocks redundant. The function block for marking the zero point doesn't write the values into a file or the drive parameters, so each time the project restarts, you need to mark the zero point again, making it less robust. These aspects will be improved in subsequent programs. Here, the emphasis is on understanding the typical function blocks provided by TWINCAT