Ubuntu is a free and open-source operating system based on the powerful Linux kernel. It supports multi-user, multi-tasking, and multi-threaded operation, has a multi-CPU architecture, simplifies the development process, and has excellent portability.
Today, ZhengMotion Assistant will share with you how to calibrate a laser galvanometer based on QT under Ubuntu. Before we begin, let's learn about the ZhengMotion ZMC408SCAN-V22 motion controller. The ZMC408SCAN-V22 supports development and use in a Linux environment.
01. ZMC408SCAN-V22 Hardware Introduction
The ZMC408SCAN-V22 is a high-performance dual-galvanometer motion controller from Zheng Motion Technology. It integrates two 100Mbps Ethernet ports, supporting EtherCAT, EtherNET, CAN, RS232, RS485, 24 general-purpose digital inputs, 20 general-purpose digital outputs, 2 general-purpose analog outputs, 2 general-purpose analog inputs, 4 local differential pulse axis interfaces, 1 MPG handwheel encoder interface, 2 galvanometer interfaces with feedback, 1 LASER interface, and 1 FIBER interface. The open system block diagram is shown below:
The ZMC408SCAN-V22 bus controller supports EtherCAT bus connection, a refresh cycle of up to 500μs, and motion control of up to 16 axes. It supports linear interpolation, arbitrary circular interpolation, spatial circular interpolation, helical interpolation, electronic cam, electronic gear, synchronous following, virtual axis setting, etc.; and can achieve real-time motion control by using an optimized network communication protocol.
The ZMC408SCAN-V22 can connect to various expansion modules via CAN and EtherCAT buses, thereby expanding digital, analog, or motion axes. It can be developed for various operating systems including Windows, Linux, Mac, Android, and WinCE, and provides DLL libraries for various environments such as VC, C#, VB.NET, and LabVIEW. For upper-computer software programming, refer to the "ZMotion PC Function Library Programming Manual".
02. Development of galvanometer calibration software using Ubuntu + Qt under Linux
(I) Purpose of galvanometer calibration
Galvanometers themselves may develop some distortions during the manufacturing process or after prolonged use. A primary purpose of galvanometer calibration is to detect and correct these distortions to ensure the accuracy of the laser.
Regular calibration and adjustment can effectively manage and correct galvanometer distortion, thereby improving the overall performance and stability of the laser system.
Rectangular markings without galvanometer calibration
The rectangle marked after galvanometer calibration
(II) Create a new Qt project and add function libraries
1. In Qt Creator, select "File" → "New File or Project..." to open the project creation wizard. Select the Application project set to create a Qt Widgets Application project, and set the project name and save location.
2. Import the relevant function libraries and header files provided by the manufacturer.
(1) Copy the header files zmotion.h and ZScancorrect.h, zmcaux.cpp and zmcaux.h, and the libraries libzmotion.so and libZScanCorrect.so to the newly created project folder.
(2) In Qt Creator, right-click on the newly created Qt project and select “Add Library…” → “External library”. Click next to import the libzmotion.so and libZScanCorrect.so library files that you just copied to the project folder into the project.
(3) In Qt Creator, right-click the newly created Qt project, select "Add Existing Files...", and add the header files zmotion.h, ZScancorrect.h, zmcaux.cpp and zmcaux.h that were previously copied to the project file to the project.
(4) After the function library is successfully added, you can open the .pro file to see the relevant function library and header file information.
03. Introduction to Galvanometer Correction Routine and Related Functions
1. Galvanometer calibration flowchart
2. Introduction to Main Functions
(1) Cancel calibration
(2) Download the file three times
(3) Multi-point iterative correction
(4) Save the calibration data to a file
(5) Read the calibration file
(6) Use the calibration file for calibration.
(7) Correction after error compensation
(8) Related error codes
04. Implementation and Principle of Galvanometer Correction Routine
1. Pre-calibration and marking
Principle: Pre-calibration obtains the actual size of the mark through the mark pattern, and calculates the scaling ratio with the target mark size based on the actual size. When the actual size of the pre-calibration matches the size of the target mark, point sampling can be performed.
·
void MainWindow::on_beforeCheck_mark_clicked(){ if( 0 == g_handle) { QMessageBox::warning(this,"Prompt","Controller not connected!"); return; } dataRenew(); // Update the page data ZScan_CancelCorrect(g_handle, ui->scan_list->currentIndex(), ui->Units->text().toDouble(), 1.0, tableStartNum); // Cancel the correction first int RowNum = sqrt(countRow());// Get the number of currently selected correction points QString strFile3 = CreateMakingString(RealCorrectSizeX, RealCorrectSizeY, RowNum, XLineLenght, YLineLenght); // Generate the three file strings Down3File(strFile3); // Download the three files to the controller // Refresh the list and insert the list data as standard point coordinates model->removeRows(0, model->rowCount()); ZPoint *tmp = pointData(RowNum,dScanSize); for (int i = 0; i < RowNum * RowNum; i++) { QList
2. Galvanometer calibration using a multi-point iterative calibration method.
Principle: Multi-point iterative correction. By obtaining the marked point data through actual measurement and comparing it with the standard point data, the error can be seen intuitively. The galvanometer correction function corrects the galvanometer through the actual point data. After multiple iterative corrections, the error between the actual point data and the standard point data can be clearly seen to be reduced.
·
bool MainWindow::ScanCorrection(int MakingRowNum){ // Perform galvanometer correction using point data memset(PointDataX, 0, MakingRowNum); memset(PointDataY, 0, MakingRowNum); int cur_item = model->rowCount(); // Check if the current data item count is correct if (cur_item != MakingRowNum) { QMessageBox::critical(this, "Error", "Data Error"); return false; } for (int row = 0; row < MakingRowNum; ++row)// Retrieve all point data and perform multi-point correction { QStandardItem *item = model->item(row, 2); PointDataX[row] = item ? item->text().toDouble() : 0.0; item = model->item(row, 3); PointDataY[row] = item ? item->text().toDouble() : 0.0; } // Check if the data is correct: if (!CheckCorrectData(MakingRowNum,PointDataX,PointDataY)) { if (QMessageBox::question(this, "Warning", "Data may be incorrect, please check the data\r\nyes means exit correction\r\nno means continue correction", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { return false; } } double x1 = -RealCorrectSizeX / 2; double y1 = -RealCorrectSizeY / 2; double x2 = RealCorrectSizeX / 2; double y2 = RealCorrectSizeY / 2; // Call the ZScan_CorrectMorePtIter function, passing the appropriate parameters int ret = ZScan_CorrectMorePtIter(g_handle, ui->scan_list->currentIndex(), PointDataX, PointDataY, ui->checkBox->isChecked(), sqrt(countRow()), ui->Units->text().toDouble(),x1, y1, x2, y2, ui->mark_Size->text().toDouble(), 1.0, tableStartNum, PreCorrectFlag); if (CheckError(ret, "ZScan_CorrectMorePtIter")) return false; PreCorrectFlag = 1; return true;}
3. Perform galvanometer calibration according to the calibration document.
Principle: The calibration file is essentially generated through multi-point iterative calibration. The calibration point data is stored in the file. By reading the calibration file, the data is read out and the galvanometer is calibrated. If there are slight errors after the file is calibrated, the calibration accuracy can be improved by file compensation iterative calibration.
·
void MainWindow::on_but_Check_clicked(){ if( 0 == g_handle) { QMessageBox::warning(this,"Prompt","Controller not connected!"); return; } QString fileName = QString::fromStdString(ui->file_Route->text() .toLatin1().data()); if (fileName.isEmpty()) { QMessageBox::critical(this, "Error", "Please select the correction file first!"); return; } if (ChangeDirMode == 1) { // Set the step ratio in the X and Y directions int ret = 0; if (ui->x_Dir->text().toInt() == -1) { ret = ZAux_Direct_StepRatio(g_handle, markpara.AxisList[0], 1, -1); } else { ret = ZAux_Direct_StepRatio(g_handle, markpara.AxisList[0], 1, 1); } if (ret != 0) { QMessageBox::critical(this, "Error", QString("File correction failed X direction setting failed error code: %1").arg(ret)); return; } if (ui->y_Dir->text().toInt() == -1) { ret = ZAux_Direct_StepRatio(g_handle, markpara.AxisList[1], 1, -1); } else { ret = ZAux_Direct_StepRatio(g_handle, markpara.AxisList[1], 1, 1); } if (ret != 0) { QMessageBox::critical(this, "Error", QString("File correction failed Y direction setting failed error code: %1").arg(ret)); return; } } int rest = ZScan_CorrectFromFile(g_handle, fileName.toLatin1().data(), scanNum, tableStartNum);//Use the correction file for galvanometer correction if (rest != 0) { QMessageBox::critical(this, "Error", QString("File correction error code: %1").arg(rest)); } else { QMessageBox::information(this, "Information", "File correction complete"); }}
05. Calibrate the laser galvanometer using the galvanometer calibration routine.
1. Galvanometer calibration using a multi-point iterative calibration method
(1) Connect to the controller and set the process parameters according to the actual laser type, IO parameters and marking parameters.
(2) Input the actual size to be calibrated, perform pre-calibration calibration, use the actual XY measurement value of the pre-calibration calibration to calculate the scaling ratio, and perform multiple pre-calibration calibrations and measurements to calculate a more accurate ratio. The smaller the error here, the fewer the number of subsequent calibrations will be.
(3) By importing point data or manually entering point data, marking and correcting can be performed. The error can be seen intuitively by comparing it with the standard point coordinate data.
(4) Continue measuring the data of the calibration points, import the point data or manually add it to the program, and repeat steps two and three to improve the calibration accuracy. If the accuracy still does not meet the requirements, you can continue to add points for iterative calibration to improve the accuracy. If the accuracy has been achieved, you can save the calibration data to the calibration file for easy use of the file for subsequent calibration.
2. Galvanometer calibration using document calibration method.
(1) Select the calibration file for galvanometer calibration.
(2) Perform actual measurements. If the measurement data is correct, the calibration is complete. If there is a positional error, coordinate compensation can be used for correction. Fill in the compensation value, perform the calibration and mark it, and remeasure the data. The compensation operation can be performed multiple times. If the error is too large or there are problems at many points, multi-point superposition iterative correction is required for galvanometer calibration.
Full code download address
▼
That concludes our sharing of laser galvanometer calibration using the open-source laser galvanometer motion controller in Ubuntu + 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.