This article mainly introduces the various PSO functions of the EtherCAT controller implemented in C++ on the VS platform. Positive Motion technology provides multiple PSO modes for users to use in different scenarios. The previous section explained two comparison output modes for multi-axis PSO: equidistant period and fixed time period. This section mainly explains the two-dimensional and three-dimensional comparison output modes.
01. Hardware Introduction
The ZMC408CE is a multi-axis, high-performance EtherCAT bus motion controller launched by Zheng Motion. It has communication interfaces such as EtherCAT, EtherNET, RS232, CAN and USB flash drive. The ZMC series motion controllers can be used in various occasions that require offline or online operation.
The ZMC408CE supports 8-axis motion control, expandable up to 32 axes, and supports linear interpolation, arbitrary circular interpolation, spatial circular interpolation, helical interpolation, electronic cams, electronic gears, synchronous following, and other functions. The ZMC408CE supports 8-axis motion control and can use pulse axes (with encoder feedback) or EtherCAT bus axes. Its general-purpose I/O includes 24 input ports and 16 output ports, some of which are high-speed I/O, with EtherCAT offering a refresh cycle as fast as 100µs. The ZMC408CE supports 8 channels of hardware comparison output, hardware timers, and precise output during motion. It also supports 8 channels of PWM output, corresponding to output ports OUT0-7, allowing simultaneous triggering of hardware comparison output across 8 channels for multi-channel vision-based imaging applications. The ZMC408CE supports three programming methods: PLC, Basic, and HMI configuration. PC API programming supports interfaces such as C#, C++, LabVIEW, Matlab, Qt, Linux, VB.Net, and Python.
The ZMC408CE features a built-in high-precision PSO (Position Synchronization Output) function, which allows for equal-spaced laser output even when adjusting for deceleration during the machining of fillets and curves, particularly in high-speed machining applications.
02. Introduction to PSO Technology
PSO (position synchronized output) essentially compares the real-time encoder feedback position (pulse position that can be output when there is no encoder) with the position set in the comparison mode to control the OP to output a high-speed synchronous signal. A schematic diagram of PSO is shown below.
PSO (Positioning Signal Controller) typically synchronizes its output signal with that of a laser (or dispensing valve, etc.). It triggers the output switch at constant spatial (or constant time) intervals throughout all stages of the motion trajectory, including acceleration, deceleration, and constant speed phases, ensuring that pulse energy is evenly distributed across the workpiece. A key feature of PSO is its high-speed and stable signal output. Because of its high output precision, it can trigger the output signal at fixed distances throughout the entire motion trajectory, regardless of overall speed. This means it can move at high speeds in straight sections while maintaining a constant output interval during deceleration in rounded corner sections. Since rounded corner machining typically occupies a relatively small portion of the overall machining process, it maximizes production capacity while ensuring optimal machining results.
The PSO function for positive motion is implemented by calling the ZAux_Direct_HwPswitch2 function interface. This function uses hardware to implement high-speed comparison output of I/O, with a response speed of microseconds, hence the name hardware comparison output.
03. Development of motion control projects using C++ and MFC
1. Create a new MFC project and add function libraries.
Note: This example program is an MFC form application created based on the .NET Framework 4.0 framework in the VS2010 compilation environment.
(1) Go to the toolbar menu “File” → “New” → “Project” to start the Project Creation Wizard.
(2) Select "Visual C++" as the development language and .NET Framework 4 and MFC application, fill in the program name and select the program storage path, and click OK.
(3) Click Next.
(4) Select "Dialog-based" as the type, and click Next or Finish.
2. Locate the C++ function library files provided by the manufacturer.
(1) Go to the CD-ROM provided by the manufacturer, find the "8.PC function" folder, and click to enter. Find the C++ function library, the path is as follows (64-bit library example).
(2) Select the "Function Library 2.1" folder.
(3) Select the "Windows Platform" folder.
(4) Select the corresponding function library as needed. Here, we select "64-bit library". (5) Unzip the C++ compressed package, which contains the corresponding C++ function library.
(6) The specific path to the function library is as follows.
(7) Copy the C++ library files and related files provided by the manufacturer to the newly created project.
3. Add static libraries and related header files to the project. Static libraries: zauxdll.lib, zmotion.lib Related header files: zauxdll2.h, zmotion.h
(1) First, right-click the header file, then select "Add" → "Existing Item".
(2) In the pop-up window, add the static library and related header files in sequence.
(3) Declare the header files used and define the controller connection handle.
With this, the project is now complete.
4. Refer to the PC function manual.
Users need to obtain the function interfaces used for motion control development from the PC function manual and use them in accordance with the manual instructions. The PC function manual can be viewed on the CD-ROM, and the specific path is as follows: "CD-ROM\8.PC Functions\Function Library 2.1\ZMotion Function Library Programming Manual V2.1.pdf".
5. Controller network port connection function interface
PC programming typically uses the network port to connect the controller and the industrial computer. `ZAux_FastOpen();` If the connection is successful, this interface returns a connection handle. Control of the controller can be achieved by manipulating this connection handle. `ZAux_OpenEth()` interface description:
Project application screenshots:
6. The hardware compare-output function interface uses the instruction operation link handle "g_handle" to manipulate the lower-level machine registers, retrieves the register contents of the controller, and provides real-time control instructions for the lower-level machine as follows: Real-time global variable instruction: ZAux_Direct_HwPswitch2. The hardware automatically triggers the op output signal after the hardware compare-output instruction is executed.
7. Hardware Timer Function Interface
The ZAux_Direct_HwTimer hardware timer restores its level after a period of time following hardware comparison output.
04. Development of MFC program execution and read/write control
1. The demo interface is as follows:
2. Two-dimensional comparison mode
(1) 2D comparison (Mode 25)
Syntax: HW_PSWITCH2(25, opnum, opstate, maxerr, num, tablepos) mode 25: Two-dimensional comparison mode; opnum: Corresponding output port;
opstate: The output state of the first comparison point;
maxerr: Compares the pulse deviation to the left and right of each axis. The comparison begins once the deviation falls within the specified range. This parameter cannot be set to 0.
num: The number of comparison point coordinates stored in the table;
tablepos: The table number where the coordinates of the first comparison point are located.
Note: Comparison points are written in the TABLE. Two consecutive TABLE data entries form a 2D coordinate system. The OP (operator) is reversed every time a comparison position is reached. The blue segment in the diagram indicates that the OP is enabled. Comparison is supported for various common interpolation motions. The coordinates of the comparison points must be accurate; otherwise, it will affect the comparison of subsequent points.
The main function of this mode is to reverse the output level after encountering a pre-set two-dimensional comparison point.
This mode requires specifying a high-speed output port. After setting the output status and comparison axis of the first comparison point, set the comparison point (i.e., set the table register, number of points, etc.), and set parameters such as the maximum pulse error of the comparison point before starting the comparison. Then, drive the axis to move. Pulse deviation explanation: In 2D mode, the XY coordinates must be set accurately; if the axis does not move to the accurate TABLE comparison point, it will not trigger. The same applies to 3D mode. Therefore, the multi-dimensional comparison mode introduces a special parameter, maxerr, for position range deviation. It is valid in both left and right ranges; that is, it is valid if the difference between the actual position coordinates and the comparison point of the TABLE is within the maxerr range. The trigger time is when the current position enters the trigger range of the comparison point. The comparison range diagram is shown below.
Note: The unit of maxerr is the deviation in the number of pulses, not the deviation in distance. As shown in the figure below, the high-speed comparator output port is set to 0, the output state of the first comparator point is 1, and the comparator axis is 0, 1; two comparator points are set, with coordinates of (100, 50) and (160, 80) respectively. That is, when the axis moves to points (100, 50) and (160, 80), and the error range is within ±50 pulses, a level change will be triggered.
The oscilloscope waveform is shown in the figure: the output is 1 at coordinates (100, 50) and returns to 0 at coordinates (160, 80).
(2) 2D comparison (Mode 26)
Syntax: HW_PSWITCH2(26, opnum, opstate, maxerr, num, tablepos, [ophwtimeus, ophwtimes, hwcyctimeus])
Mode 26: Two-dimensional comparison mode; opnum: corresponding output port; opstate: output state of the first comparison point; maxerr: pulse deviation to the left and right of each axis at the comparison position. Comparison begins after entering the deviation range. This parameter cannot be 0; num: number of comparison point coordinates stored in the table; tablepos: table number of the first comparison point coordinates; * The following parameters are optional from HW_TIMER. HW_TIMER can be written separately to dynamically adjust the parameters. * ophwtimeus: pulse time; ophwtimes: number of pulses; hwcyctimeus: pulse period. Explanation: Comparison points are written in the TABLE. Two consecutive TABLE data form a 2D coordinate. Each time a comparison position is reached, the OP is triggered. The number of times the OP reverses and the reversal period for each comparison point are set by HW_TIMER. When the next TABLE position is reached, the OP is triggered again. Similar to Mode 7 and Mode 36.
The main function of this mode is to output a set timed pulse upon encountering a pre-defined two-dimensional comparison point. To use this mode, you need to specify the high-speed output port, set the output state and comparison axis of the first comparison point, then set the comparison points (i.e., set the table register, number of points, etc.), followed by the pulse validity time, pulse period time, number of pulses (repetitions), and the maximum pulse error for the comparison point, before starting the comparison. Then, the axis will move. As shown in the diagram, the high-speed comparison output port is set to 0, the output state of the first comparison point is 1, and the comparison axis is 0, 1; two comparison points are set with coordinates (100, 100) and (200, 200). That is, when the axis moves to points (100, 100) and (200, 200), with an error range of approximately ±10 pulses, two pulses with a period of 60ms and a pulse validity time of 20ms will be triggered.
The oscilloscope waveform is shown in the figure: at coordinates (100, 100) and (200, 200), two pulses with a period of 60ms and a pulse effective time of 20ms are triggered.
3. Three-dimensional comparison mode
(1) 3D Comparison (Mode 35)
Syntax: HW_PSWITCH2(35, opnum, opstate, maxerr, num, tablepos)
Mode 35: 3D comparison mode; opnum: corresponding output port; opstate: output state of the first comparison point; maxerr: pulse deviation to the left and right of each axis at the comparison position. Comparison begins after entering the deviation range. This parameter cannot be 0; num: number of comparison point coordinates stored in the table; tablepos: table number of the first comparison point coordinates; Explanation: Comparison points are written in the TABLE. Three consecutive TABLE data form a 3D coordinate. Each comparison position triggers an OP. The number of OP reversals and the reversal period for each comparison point are set by HW_TIMER. Upon reaching the next TABLE position, the OP is triggered again. Similar to modes 26 and 7.
The main function of this mode is to reverse the output level after encountering a pre-set three-dimensional comparison point.
This mode requires specifying a high-speed output port. After setting the output state of the first comparison point and the comparison axis, set the comparison points (i.e., set the table register, number of points, etc.), and set parameters such as the maximum pulse error of the comparison points before starting the comparison. Then, drive the axis to move. As shown in the figure below, set the high-speed comparison output port to 0, the output state of the first comparison point to 1, and the comparison axes to 0, 1, and 2; set four comparison points with coordinates of (80, 40, 20), (160, 80, 40), (240, 120, 60), and (320, 160, 80). That is, when the axis moves to points (80, 40, 20), (160, 80, 40), (240, 120, 60), and (320, 160, 80), and the error range is approximately ±10 pulses, a level change will be triggered.
The oscilloscope waveform is shown in the figure: the level changes at coordinates (80, 40, 20), (160, 80, 40), (240, 120, 60), and (320, 160, 80).
Core program example:
·
/* Parameters: mode 25, 26, 35, 36. 2D/3D comparison mode Axisnum: axis array Opnum: corresponding output port Opstate: output state of the first comparison point. maxerr: pulse deviation of each axis to the left and right of the comparison position. Comparison starts after entering the deviation range. num: number of comparison points stored in TABLE. tablepos: TABLE number of the coordinates of the first comparison point. When used with hwtimer, the hwtimer parameter can be dynamically adjusted. ModePara1: pulse time ModePara2: number of pulses ModePara3: pulse period */ int32 CMyControlDlg:: ZAux_Direct_HwPswitch2_2D(ZMC_HANDLE handle, int *Axisnum,int Mode,int Opnum, int Opstate,int maxerr,int num, int tablepos, float ModePara1, float ModePara2,float ModePara3){ if(0 > Axisnum[0] || Axisnum[0] > MAX_AXIS_AUX) { return ERR_AUX_PARAERR; } char cmdbuff[2048]; char tempbuff[2048]; char cmdbuffAck[2048]; //Generate command sprintf(cmdbuff, "BASE(%d,%d)\n", Axisnum[0], Axisnum[1]); switch(Mode) { case 25: sprintf(tempbuff, "HW_PSWITCH2(%d,%d,%d,%d,%d,%d)", Mode, Opnum, Opstate, maxerr,num,tablepos); strcat(cmdbuff, tempbuff); break; case 26: sprintf(tempbuff, "HW_PSWITCH2(%d,%d,%d,%d,%d,%d,%f,%f,%f)", Mode,Opnum, Opstate, maxerr,num,tablepos,ModePara1,ModePara2,ModePara3); strcat(cmdbuff, tempbuff); break; case 35: sprintf(tempbuff, "HW_PSWITCH2(%d,%d,%d,%d,%d,%d)", Mode, Opnum, Opstate, maxerr,num,tablepos); strcat(cmdbuff, tempbuff); break; case 36: sprintf(tempbuff, "HW_PSWITCH2(%d,%d,%d,%d,%d,%d,%f,%f,%f)", Mode,Opnum, Opstate, maxerr,num,tablepos,ModePara1,ModePara2,ModePara3); strcat(cmdbuff, tempbuff); break; default: return ERR_AUX_PARAERR; break; } //Call the command execution function int ret=ZAux_Execute(handle, cmdbuff, cmdbuffAck,2048); if (strlen(cmdbuffAck)!=0) return ERR_ACKERROR; return ret;}
(2) 3D Comparison (Mode 36)
Syntax: HW_PSWITCH2(36, opnum, opstate, maxerr, num, tablepos, [ophwtimeus, ophwtimes, hwcyctimeus]) mode 36: 3D comparison mode; opnum: corresponding output port; opstate: output state of the first comparison point; maxerr: pulse deviation to the left and right of each axis of the comparison position; comparison begins after entering the deviation range. This parameter cannot be 0; num: number of comparison point coordinates stored in table; tablepos: table number of the first comparison point coordinates; * The following parameters are optional from HW_TIMER. HW_TIMER can be written separately to dynamically adjust the parameters. * ophwtimeus: pulse time; ophwtimes: number of pulses; hwcyctimeus: pulse period.
The main function of this mode is to output a set timed pulse after encountering a pre-defined 3D comparison point. When using this mode, you need to specify the high-speed output port, set the output state and comparison axis of the first comparison point, then set the comparison points (i.e., set the table register, number of points, etc.), then set the pulse validity time, pulse period time, and number of pulses (repetitions), and set the maximum pulse error of the comparison point, etc., before starting the comparison. The drive axis will then move. As shown in the figure below, the high-speed comparison output port is set to 0, the output state of the first comparison point is 1, and the comparison axis is 0, 1, 2; four comparison points are set with coordinates of (80, 40, 20), (160, 80, 40), (240, 120, 60), and (320, 160, 80). That is, when the axis moves to points (80, 40, 20), (160, 80, 40), (240, 120, 60), and (320, 160, 80), and the error range is within ±10 pulses, a level change will be triggered. Two pulses with a period of 40ms and an effective pulse time of 20ms will be triggered in each instance.
The oscilloscope waveform is shown in the figure: at coordinates (80, 40, 20), (160, 80, 40), (240, 120, 60), and (320, 160, 80), two pulses with a period of 40ms and an effective pulse time of 20ms will be triggered.
Core program example:
·
/* Parameters: mode 25, 26, 35, 36. 2D/3D comparison mode Axisnum: axis array Opnum: corresponding output port Opstate: output state of the first comparison point. maxerr: pulse deviation of each axis to the left and right of the comparison position. The comparison starts after entering the deviation range. num: number of comparison points stored in TABLE. tablepos: TABLE number of the coordinates of the first comparison point. When used with hwtimer, the hwtimer parameter can be dynamically adjusted. ModePara1: pulse time ModePara2: number of pulses ModePara3: pulse period */ int32 CMyControlDlg:: ZAux_Direct_HwPswitch2_2D(ZMC_HANDLE handle, int *Axisnum,int Mode,int Opnum, int Opstate,int maxerr,int num, int tablepos, float ModePara1, float ModePara2,float ModePara3){ if(0 > Axisnum[0] || Axisnum[0] > MAX_AXIS_AUX) { return ERR_AUX_PARAERR; } char cmdbuff[2048]; char tempbuff[2048]; char cmdbuffAck[2048]; //Generate command sprintf(cmdbuff, "BASE(%d,%d)\n", Axisnum[0], Axisnum[1]); switch(Mode) { case 25: sprintf(tempbuff, "HW_PSWITCH2(%d,%d,%d,%d,%d,%d)", Mode, Opnum, Opstate, maxerr,num,tablepos); strcat(cmdbuff, tempbuff); break; case 26: sprintf(tempbuff, "HW_PSWITCH2(%d,%d,%d,%d,%d,%d,%f,%f,%f)", Mode,Opnum, Opstate, maxerr,num,tablepos,ModePara1,ModePara2,ModePara3); strcat(cmdbuff, tempbuff); break; case 35: sprintf(tempbuff, "HW_PSWITCH2(%d,%d,%d,%d,%d,%d)", Mode, Opnum, Opstate, maxerr,num,tablepos); strcat(cmdbuff, tempbuff); break; case 36: sprintf(tempbuff, "HW_PSWITCH2(%d,%d,%d,%d,%d,%d,%f,%f,%f)", Mode,Opnum, Opstate, maxerr,num,tablepos,ModePara1,ModePara2,ModePara3); strcat(cmdbuff, tempbuff); break; default: return ERR_AUX_PARAERR; break; } //Call the command execution function int ret=ZAux_Execute(handle, cmdbuff, cmdbuffAck,2048); if (strlen(cmdbuffAck)!=0) return ERR_ACKERROR; return ret;}
Full code download link ▼
This concludes our presentation on the C++ development of PSO motion controller for visual aerial photography and precise output (Part 3): 2D/3D/multi-axis PSO output.
For more exciting content, please follow the "Zheng Motion Assistant" WeChat official account. For related development environment and example code, please contact Zheng Motion's technical sales engineer: 400-089-8936.
This article is original content from Zheng Motion Technology. We welcome everyone to reprint it for mutual learning and to jointly improve China's intelligent manufacturing level. Copyright belongs to Zheng Motion Technology. Please indicate the source if you reprint this article.