Share this

Examples of Leisai's medium and large-scale PLC CNC applications

2026-04-06 02:06:21 · · #1

CNC (Computer Numerical Control) is a motion control function that achieves trajectory control. Its goal is not only to control the positions of the "starting point" and the "target point," but also to control the trajectory between the two points according to the desired motion path. By controlling the movement of multiple axes simultaneously, CNC enables the moving parts of the equipment to move along the required trajectory and perform the required machining operations.

CNC is widely used in many typical motion control applications, including graphic engraving, machine tool processing, robotic handling, and motion platform control.

Figure 1

Leadshine's medium and large-sized PLCs (MC series and LC series) all support the DIN66025-1 standard G-Code instruction set, allowing users to write CNC trajectory programs using G-Code instructions. They also support CNC motion control functions according to the PLCopen standard, enabling planar linear/circular interpolation in Cartesian coordinates, spatial linear/circular interpolation, helical interpolation, etc., and supporting the following motion of up to 8 auxiliary axes.

Figure 2

Leadsys Studio provides the SM3_CNC.library library, which provides CNC trajectory interpolation control functionality without requiring any special add-ons. The following simple example demonstrates how to use function blocks such as SMC_Interpolator within the library to perform CNC Cartesian coordinate system interpolation calculations.

02.

Programming

1. New construction project

After opening the LeadSys software, click "File" - "New Project" in the menu, select "Standard Project", choose the location on your local computer's hard drive where the PLC project is stored, enter the name of this project, such as: CNCdirect, and click "OK".

Figure 3

On the next screen, select the PLC type, such as LC2048, and then select the programming language for the main program PLC_PRG (the default is ST). After selecting according to your actual situation, click "Create" to enter the programming interface.

Figure 4

2. Create an NC program

Right-click "Application" in the directory tree, select "Add Object" - "CNC Program", enter the program name such as "Example", select the compilation mode, and click "Open" to enter the editing interface.

Figure 5

Note: In the CNC properties of "Application", there are three compilation modes (SMC_QutQueue; can be used directly by the interpolator, SMC_CNC_REF: needs to be recognized by SMC_NCDecoder and used in conjunction with other preprocessing functions, File: file format, needs to be processed by SMC_ReadNCFile). The final converted data type is SMC_OutQueue, which is then input into the path preprocessor and interpolator for execution.

In this example, after directly selecting the SMC_QutQueue compilation mode, enter the G-code program to be executed in the editing area, as shown in the following figure:

Figure 6

3. Adding devices

Right-click "SoftMotionGeneralAxisPool" in the directory tree, select "Add Device," and the interface shown in Figure 7 will open. Enter the device name, such as X_Drive, select "Virtual Drive," and click the "Add Device" button. Then, add another virtual axis, such as Y_Drive, using the same method.

The above steps are for example demonstration only. Please add equipment to the project according to the actual situation.

Figure 7

And set the axis speed, acceleration and other parameters.

Figure 8

4. Create a new program

4.1 Right-click “PLC_PRG” to add a new CFC program named “Ipo”, and configure an appropriate task cycle. In this example, the interval is set to 3 milliseconds.

4.2 Enable axis by calling MC_Power

Figure 9

4.3 Adding the SMC_Interpolator

After compilation and decoding, the G-code is recognized by the PLC, which then controls the movement of each axis according to the trajectory described by the G-code. A typical POU for interpolation operation performs this function, mainly consisting of interpolation calculation function blocks, coordinate transformation function blocks, and axis position control function blocks. It must be executed under an EtherCAT task.

The SMC_Interpolator function block converts the path defined by the GEOINFO object into discretized path points.

The commonly used variables are explained below:

Figure 10

4.4 Add reverse and forward transformation function blocks to implement coordinate transformation and path visualization.

When the coordinate axes of the user application system do not coincide with the coordinate system of the G-Code program trajectory, translation and rotation coordinate transformations are required.

Inverse transformation: SM_Trafo_Gantry2 calculates the target position of the relevant drive axis based on the position coordinates of the trajectory interpolation points, which is used for axis position control.

Figure 11

Forward Transformation: SM_Trafof_Gantry2 calculates the coordinates of the synthesized motion point based on the position of the relevant drive axis, which is used for displaying the current position. The forward transformation function block in this example is only used for visualization.

Figure 12

4.5 Add axis control function block SMC_ControlAxisByPos

To ensure that motion control commands are correctly sent to each axis, the SMC_ControlAxisByPos function block is used. This function block writes the coordinates of fSetPostion to the specified axis via PDO, causing the axis drive servo to move to the designated position.

Figure 13

4.6 The program is shown in the following figure:

Figure 14

Variable table:

Figure 15

03.

Create a visual interface

Right-click "Application" in the directory tree, then select "Add Object" - "View". Enter the program name, such as "Visualization1", and click "Open" to enter the editing interface. Select "SMC_CNC" in the visualization toolbox, filter the required visualization elements, and drag them into the editing area, as shown in the following figure: (This step is only used for simulation demonstration of the running trajectory in this example; you can choose whether to create it in actual programming).

Figure 16

04.

Compile, run, and simulate.

Figure 17

END

Read next

CATDOLL 131CM Kelsie (TPE Body with Hybrid Silicone Head)

Height: 131cm Weight: 25.5kg Shoulder Width: 32cm Bust/Waist/Hip: 67/56/72cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22