Share this

Domestic EtherCAT Motion Control Edge Controller (Part 6): RtBasic File Download and Python+Qt Development for Continuous Trajectory Processing

2026-04-06 04:29:30 · · #1

Today, Zhengdong Assistant will share with you how to use Python + QT to implement continuous trajectory processing with the domestically produced EtherCAT motion control edge controller ZMC432H.

01. Function Introduction

The ZMC432H, a fully domestically produced EtherCAT motion control edge controller, is a positive motion device with domestically produced and independently controllable hardware and software. Its motion control interface is compatible with EtherCAT bus and pulse-type standalone motion controllers, supporting up to 32-axis motion control. It also supports positive motion remote HMI functionality, providing network configuration display and real-time monitoring and adjustment of parameter settings.

The ZMC432H features a rich set of hardware interfaces and control function modules, enabling efficient and stable motion control and real-time data acquisition to meet the application needs of industrial control and the Industrial Internet. The ZMC432H has a built-in Linux system and can connect via a local LOCAL interface, allowing for faster command interaction; the interaction time for a single command or multiple commands is approximately 40µs.

02. Development of motion control using Python + QT

1. Configure the Python + Qt development environment and install the necessary tools.

1. Download the Python interpreter.

2. Choose between pyside2 or pyside6 depending on your Python interpreter version. Higher versions of the interpreter use pyside6.

There are two ways to install pyside2:

Method 1: Use Win+R to open the Run dialog box, then type cmd (you need to configure the environment variables according to the installation wizard when installing the Python interpreter, otherwise the following commands will not execute successfully), then type pip install pyside2 -i https://pypi.douban.com/simple/;

Method 2: Install in PyCharm.

3. After installing PyCharm Community Edition, click the "+" sign on the following screen to install the necessary tools, such as pyside2.

4. Configure custom tools in PyCharm (for editing the Qt interface).

(1) Open the Tool's editing box according to the steps shown in the figure.

(2) Custom Pyside2-uic:

a. Program should be entered as: Python installation directory\Scripts\pyside2-uic.exe;

b.Arguments fill in: $FileName$ -o $FileNameWithoutExtension$.py;

c. In the Working directory field, enter: $FileDir$.

(3) Custom QtDesigner:

a. Program should be entered as: Python installation directory\Scripts\pyside2-designer.exe;

b.Fill in Working directory: $ProjectFileDir$.

Once the custom tool is configured, it can be used directly from the PyCharm menu.

1. Click Tools → Qt → Qtdesigner to enter the UI design interface.

2. Right-click the ui file, click Qt → Pyside2-uic to generate the py file of the ui file.

II. Create a new Python project and add function libraries

1. Open a new folder using PyCharm Community Edition 2022, or create a new directory after entering PyCharm Community Edition 2022, and add Python files to the directory.

2. Locate the CD-ROM provided by the manufacturer. The path is as follows.

A. Locate the "04.PC Functions" folder on the CD provided by the manufacturer and click to enter.

B. Select the "PC Function Library V2.1.1" folder.

C. Select the "Windows Platform" folder.

D. Select the "Library Files and Examples" folder.

E. Select the "PYTHON Examples" folder.

F. Unzip the compressed file corresponding to the bit version.

G. The result after decompression is shown in the image below.

3. For Windows systems, simply add the zauxdll.dll, zmotion.dll, and zauxdllPython.Py files to the created folder.

3. Review the PC function manual and familiarize yourself with the relevant function interfaces.

1. The PC function manual is also included in the CD-ROM materials. The specific path is as follows: "CD-ROM materials\04.PC functions\ZMotionPC function library programming manual and its example source code\ZMotionPC function library programming manual V2.1.1.pdf".

2. Connect to the controller and obtain the connection handle.

(1) Description of the ZAux_OpenEth() interface.

(2) Download the “.bas” file to the controller to run the interface description.

(3) Interface description for pausing and resuming the controller's internal Basic program.

IV. Python+Qt development example for downloading RtBasic files and processing continuous trajectories.

1. The example interface is as follows.

2. Use the "ZmotionCadV1.0 Map Tool" in "CD-ROM Data" → "Tools & Software" to convert the graphics in the CAD drawing into ".bas" motion control code.

A. Open the software tool, click "File" → "Import". Select the CAD drawing in DXF format that you want to convert and open it.

B. The result after opening is as follows.

C. Click "File" → "Export" to export the ".bas" file. This file can then be downloaded to the control card for motion control of the above trajectory.

D. For specific instructions on using the CAD mapping software, please refer to previous articles on the use of CAD mapping software in conjunction with a controller in motion technology.

3. The program example is as follows.

(1) Loading Qt UI files in Python;

from PySide2.QtWidgets import QMessageBoxfrom PySide2.QtCore import QFile, QTimerfrom PySide2.QtUiTools import QUiLoaderq_state_file = QFile("mainweiget.ui")q_state_file.open(QFile.ReadOnly)self.ui = QUiLoader().load(q_state_file)q_state_file.close()

Note: Here, self.ui refers to the ui in Qt.

(2) In the event handling function of the link button, the interface function ZAux_OpenEth() of the link controller is called to link with the controller. After the link is successfully linked, timer 1 is started to monitor the status of the controller.

·

def on_btn_open_clicked(self): strtemp = self.ui.comboBox.currentText() print("Current IP is:", strtemp) if self.Zmc.handle.value is not None: self.Zmc.close() self.time1.stop() self.ui.setWindowTitle("Single axis returns to zero") iresult = self.Zmc.open_eth(strtemp) if 0 != iresult: QMessageBox.warning(self.ui, "Prompt", "Connection failed") else: QMessageBox.warning(self.ui, "Prompt", "Connection successful") str_title = self.ui.windowTitle() + strtemp self.ui.setWindowTitle(str_title) self.Up_State() self.time1.start(100)

(3) Monitor the controller status through a timer.

·

def Up_State(self): idlelist = [ctypes.c_int(-1) for i in range(0, 4)] fdposlist = [ctypes.c_float(0) for i in range(0, 4)] for i in range(0, 4): self.Zmc.get_target_pos(i, fdposlist[i]) # Get the current axis position self.Zmc.get_idle(i, idlelist[i]) # Determine the current axis state str1 = " {} {} ".format("Stopped" if idlelist[0].value else "Running", round(fdposlist[0].value, 2)) self.ui.lineEdit_X.setText(str1) str1 = " {} {} ".format("Stopped" if idlelist[1].value else "Running", round(fdposlist[1].value, 2)) self.ui.lineEdit_Y.setText(str1) str1 = " {} {} ".format("Stopped" if idlelist[2].value else "Running", round(fdposlist[2].value, 2)) self.ui.lineEdit_Z.setText(str1) str1 = " {} {} ".format("Stopped" if idlelist[3].value else "Running", round(fdposlist[3].value, 2)) self.ui.lineEdit_R.setText(str1)

(4) Select the corresponding BAS file through the event handler function of the “Select BAS file” button.

·

def on_btn_DownBas_clicked(self): if self.Zmc.handle.value is None: QMessageBox.warning(self.ui, "Prompt", "Controller not connected") return file_Date = QFileDialog.getOpenFileName(self.ui, "Select BAS file", "..", "Files(*.bas)") self.file_Name = file_Date[0].replace("/", "\\") print(self.file_Name) if self.file_Name == "": return self.ui.textEdit_FilePath.insertPlainText(self.file_Name + "\n")

(5) Download and start the selected .bas file using the event handler function of the “Start” button.

·

If self.Zmc.handle.value is None: QMessageBox.warning(self.ui, "Warning", "Controller Not Connected") return # Set axis 0 axis type str_tmp = self.ui.edit_Atype_0.text() float_tmp = int(str_tmp) self.Zmc.set_axis_type(0, float_tmp) # Set axis 0 axis type str_tmp = self.ui.edit_Atype_1.text() float_tmp = int(str_tmp) self.Zmc.set_axis_type(1, float_tmp) # Set pulse mode and logical direction (pulse + direction) self.Zmc.set_invert_step(self.axis_Num, 0) # Set equivalent str_tmp = self.ui.edit_Units_0.text() float_tmp = float(str_tmp) self.Zmc.set_units(0, float_tmp) str_tmp = self.ui.edit_Units_1.text()float_tmp = float(str_tmp)self.Zmc.set_units(1, float_tmp)# Set speed str_tmp = self.ui.edit_Speed_0.text()float_tmp = float(str_tmp)self.Zmc.set_speed(0, float_tmp)str_tmp = self.ui.edit_Speed_1.text()float_tmp = float(str_tmp)self.Zmc.set_speed(1, float_tmp)# Set acceleration str_tmp = self.ui.edit_Accel_0.text()float_tmp = float(str_tmp)self.Zmc.set_acceleration(0, float_tmp)str_tmp = self.ui.edit_Accel_1.text()float_tmp = float(str_tmp)self.Zmc.set_acceleration(1, float_tmp) # Set deceleration self.Zmc.set_deceleration(0, 0) self.Zmc.set_deceleration(1, 0) # Enable continuous interpolation str_tmp = self.ui.edit_Merge_0.text() float_tmp = int(str_tmp) self.Zmc.set_merge(0, float_tmp) str_tmp = self.ui.edit_Merge_1.text() float_tmp = int(str_tmp) self.Zmc.set_merge(1, float_tmp) if self.file_Name == "": return ret = self.Zmc.bas_down(self.file_Name, 1) # Download to ROM and run if ret != 0: QMessageBox.warning(self.ui, "Prompt", "File download failed!" + "Error code: {} ".format(ret)) return

Note: The ".bas" file can also be downloaded through our ZDevelop software. The ZAux_BasDown command will generate a ZAR from a single .bas file and download it to the controller for execution. (6) Implement the controller through the event handling functions of the stop, pause, and continue buttons.

·

def on_btn_stop_clicked(self): if self.Zmc.handle.value is None: QMessageBox.warning(self.ui, "Warning", "Controller not connected") return buffer = (ctypes.c_char * 1024)() ret = self.Zmc.execute("STOPTASK 0", buffer, 0) ret = self.Zmc.rapid_stop(2)def on_btn_Pause_clicked(self): ret = self.Zmc.bas_pause() if ret != 0: QMessageBox.warning(self.ui, "Prompt", "Sports pause failed!" + "Error code is: {} ".format(ret)) returndef on_btn_Resume_clicked(self): ret = self.Zmc.bas_resume() if ret != 0: QMessageBox.warning(self.ui, "Prompt", "Sports resume failed!" + "Error code is: {} ".format(ret)) return

03. Debugging and Monitoring

Compile and run the routines, and simultaneously monitor the controller status by connecting to the controller through the ZDevelop software.

By connecting the ZDevelop software to the controller and enabling debug mode, you can view the filenames of the ".bas" files within the controller.

The waveform of a continuous small line segment was captured using the oscilloscope function of ZDevelop software. Below is a comparison between the oscilloscope waveform and the CAD drawing.

The comparison is shown in the figure below.

Full code download address

This concludes our presentation on the development of the domestically produced EtherCAT motion control edge controller (Part 6): RtBasic file download and continuous trajectory processing using Python + QT.

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.

Read next

CATDOLL 123CM Olivia (TPE Body with Soft Silicone Head)

Height: 123cm Weight: 23kg Shoulder Width: 32cm Bust/Waist/Hip: 61/54/70cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22