Share this

Custom graphic marking of an open-source laser galvanometer motion controller under Ubuntu + Qt

2026-04-06 03:40:03 · · #1

In previous lessons, we explained how to perform galvanometer calibration using Ubuntu + Qt (click for details → Laser Galvanometer Calibration under Ubuntu + Qt with Open Laser Galvanometer Motion Controller). This section on custom graphic marking is implemented under the premise of galvanometer calibration.

Before we begin our formal learning, let's first understand the ZMC408SCAN-V22 motion controller. The ZMC408SCAN-V22 controller 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 a custom graphic marking project using Ubuntu + Qt

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 zmotion.h, zmcaux.h, zmcaux.cpp and libzmotion.so library 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 library file 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 file...", and add the header file zmotion.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. At this point, the function library and header file required by the routine have been added to the project. Next, we will start implementing the routine.

03. Introduction to Custom Graphic Marking Process and Related Functions

1. Custom graphic annotation flowchart

2. Introduction to relevant functions

(1) Connect the controller

(2) General command execution interface

(3) Three-stage file initialization

(4) Generate empty string

(5) Generate the consecration string

(6) Generate the off-light string

(7) Generate the mark string

(8) Download the file three times

(9) Set the output port status

(10) Set analog output

(11) Set the PWM duty cycle

(12) Set the PWM frequency

04. Implementation Example of Custom Graphic Marking

The custom graphic marking routine mainly generates a three-dimensional marking file by selecting a simple graphic. The controller runs the three-dimensional file to mark the corresponding graphic. The three-dimensional file in the routine is mainly generated by appending strings. After generating the three-dimensional file for the drawing process of all graphics, it can be downloaded to the controller.

1. Establish controller connection, set relevant galvanometer and process parameters. The laser can be turned on or off by setting the analog port, PWM and laser enable signal.

·

void MainWindow::on_ip_open_clicked(){ char * tmp_buff = new char[16]; QString str = ui->ip_Address->text(); QByteArray ba = str.toLatin1(); tmp_buff = ba.data(); if(0 != g_handle) { ZAux_Close(g_handle); } int32 iresult= ZMC_FastOpen(ZMC_CONNECTION_ETH,tmp_buff,1000,&g_handle); if( 0 != iresult) { QMessageBox::warning(this,"Prompt","Connection failed"); return; } ZAux_Direct_SetDA(g_handle,markPara.PowerDA,markPara.Power); //Set the analog quantity ZAux_Direct_SetPwmDuty(g_handle,markPara.PwmIo,0.5); // Set duty cycle ZAux_Direct_SetPwmFreq(g_handle,markPara.PwmIo,markPara.PwmFreq); // Set frequency ZAux_Direct_SetOp(g_handle,io_value.emit_io,0); // Turn off laser output port ZAux_Direct_SetOp(g_handle,io_value.enable_io,0); // Turn off laser enable}

2. Generate the initialization three-stage file string.

The initialization process during marking can be written into relevant functions, including setting initial laser parameters, marking start point, delay parameters, etc., making it convenient to use directly during the marking of custom patterns. The three-part file string is essentially a concatenation of basic instructions; after all instructions are concatenated, they can be directly written into the controller for execution.

·

void MainWindow::LaserScan_z3p_Init(){ strFile3.clear(); strFile3 += QString("BASE(%1,%2)\n").arg(4).arg(5); // Set axis number strFile3 += "ATYPE = 21,21\n"; // Set axis type strFile3 += "UNITS = 100,100\n"; // Set pulse equivalent strFile3 += "AXIS_ZSET = 3,3\n"; // Enable precise output strFile3 += "MERGE = 1,1\n"; // Enable continuous interpolation strFile3 += QString("OP(%1,ON)\n").arg(io_value.enable_io); strFile3+=QString("MOVE_AOUT(%1,%2)\n").arg(markPara.PowerDA).arg(static_cast(markPara.Power * 255 / 100)); strFile3+=QString("MOVE_PWM(%1,0.5,%2)\n").arg(markPara.PwmIo).arg(markPara.PwmFreq); strFile3 +=QString("DECEL_ANGLE= %1,%2\n").arg(15.0/180.0*M_PI).arg(15.0/180.0*M_PI); strFile3 += QString("STOP_ANGLE = %1,%2\n").arg(90.0/180.0*M_PI).arg(90.0/180.0*M_PI); strFile3 += QString("ZSMOOTH= %1,%2\n").arg(markPara.CorDelay).arg(markPara.CorDelay); //Corner delay time strFile3 += QString("FORCE_SPEED = %1\n").arg(markPara.JumpSpeed); // Jump speed strFile3 += "MOVESCANABS(0,0)\n"; // Move to position 0}

3. Generate a cubic file string for marking custom graphics.

Custom graphics can essentially be drawn as line segments. Laser marking also uses line segments. When generating custom graphics, you only need to control the start and end points of each line segment, and simultaneously control the delay parameters at the start and end points. Finally, turn off the laser and enable it when the drawing is complete. Below is part of the code for generating the three file strings and downloading them.

·

void MainWindow::on_create_File3_clicked(){ LaserScan_z3p_Init(strFile3); ListNode *ps = layers->next; do { Coordinate * pData = ps->data; if(ps->type == 1)//Marking point { LaserScan_z3p_EmptyMove(strFile3,pData->next->x,pData->next->y,markPara.JumpSpeed,markPara.JumpDelay); LaserScan_z3p_OpenLight(strFile3,io_value.emit_io,markPara.OpenDelay,markPara.MarkSpeed); LaserScan_z3p_MarkPoint(strFile3,pData->next->x,pData->next->y); LaserScan_z3p_CloseLight(strFile3,io_value.emit_io,markPara.CloseDelay,markPara.JumpDelay); } else if(ps->type == 2) //Mark straight line {LaserScan_z3p_EmptyMove(strFile3,pData->next->x,pData->next->y,markPara.JumpSpeed,markPara.JumpDelay); LaserScan_z3p_OpenLight(strFile3,io_value.emit_io,markPara.OpenDelay,markPara.MarkSpeed); LaserScan_z3p_MarkPoint(strFile3,pData->next->x2,pData->next->y2); LaserScan_z3p_CloseLight(strFile3,io_value.emit_io,markPara.CloseDelay,markPara.JumpDelay); } else if(ps->type == 3)//Marking arc { LaserScan_z3p_Arc(pData->next->x + ps->radius,pData->next->y - ps->radius, ps->radius, ps->angle, ps->radian, 0, 0); } else if(ps->type == 4)//Mark the whole circle{ LaserScan_z3p_Arc(pData->next->x + ps->radius, pData->next->y - ps->radius, ps->radius, 0, 360, 0, 0); } ...... //Mark other types ps = ps->next; }while(ps != layers);}

4. Set the task number and start the task to perform the marking.

The three-dimensional files have been downloaded to the controller. At this point, the generated three-dimensional files can be run using the ZMC_Execute function to complete the graphic marking. The following is the implementation code for starting the task and performing the marking.

·

void MainWindow::on_but_Mark_clicked(){ if( 0 == g_handle) { QMessageBox::warning(this,"Prompt","Controller not connected!"); return; } QString Cmd; char Response[1024]; //Set the startup task number and execute Zmc_polyline.z3p ZMC_Execute(g_handle,"FILE3_RUN \"Zmc_polyline.z3p\",7 ",500,Response,1024);}

5. Configure configuration file information and retain configuration parameters.

By generating an INI configuration file, the program reads the file when it loads and writes the configuration data back to the INI configuration file when it closes. This retains the last used parameters for easy reuse on subsequent loads. This is achieved using the internal function library QSettings; a portion of the implementation code is shown below.

·

void MainWindow::saveINI(){ //Save configuration data QSettings *iniWrite = new QSettings("config.ini",QSettings::IniFormat); iniWrite->setValue("laserType",ui->laser_List->currentIndex()); ..... delete iniWrite;} void MainWindow::readINI(){ //Read configuration file data QSettings *iniRead = new QSettings("config.ini",QSettings::IniFormat); int laserType = iniRead->value("laserType").toInt(); ui->laser_List->setCurrentIndex(laserType); ..... delete iniRead;}

05. Implementation effect of custom graphic markings

1. Open the basic graphical interface for Qt drawing and set the basic laser parameters and motion parameters.

2. Add the custom graphic you want to mark, set the graphic parameters, select Add Graphic. In the example, the added graphics are points, rectangles, circles, arcs, and lines. After clicking Generate Triple Files, view the contents of the triple files.

3. Click "Mark" to complete the marking of the selected custom graphic.

4. Analyze the generated three-dimensional file information. Below is part of the content of the generated three-dimensional file. The beginning of each three-dimensional file is the setting of the axis machining parameters. When moving to the starting point of the motion, the on-light parameters and delay parameters are set. When the trajectory is completed, the on-light delay and on-light operation are set.

·

BASE(4,5)ATYPE = 21,21UNITS = 100,100AXIS_ZSET = 3,3MERGE = 1,1OP(47,ON)MOVE_AOUT(3,127)MOVE_PWM(11,0.5,4000)DECEL_ANGLE = 0.261799,0.261799STOP_ANGLE = 1.5708,1.5708ZSMOOTH = 1000,1000FORCE_SPEED = 1000MOVESCANABS(0,0)FORCE_SPEED = 1000MOVESCANABS(0.00000,0.00000)MOVE_DELAY(0.2,1)FORCE_SPEED = 500MOVEOP_DELAY = -0.1MOVE_OP(44,ON)MOVESCANABS(0.00000,0.00000)MOVEOP_DELAY = 0MOVE_DELAY(1)MOVE_OP(44,OFF)FORCE_SPEED = 1000MOVESCANABS(-5.00000,5.00000)MOVE_DELAY(200,1)FORCE_SPEED = 500MOVEOP_DELAY = -0.1MOVE_OP(44,ON)MOVESCANABS(5.00000,5.00000)MOVESCANABS(5.00000,-5.00000)MOVESCANABS(-5.00000,-5.00000)MOVESCANABS(-5.00000,5.00000)MOVEOP_DELAY = 0MOVE_DELAY(1)MOVE_OP(44,OFF)

06. Laser marking process

The laser marking process, including initialization, idle movement, switching on, marking, and switching off, is encapsulated into function interfaces. During marking, calling the relevant function interfaces will generate the corresponding three file strings.

Full code download address

This concludes our sharing of the custom graphic marking of the open laser galvanometer motion controller under 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.

Read next

CATDOLL 131CM Amber Silicone Doll

Height: 131 Silicone Weight: 28kg Shoulder Width: 32cm Bust/Waist/Hip: 67/56/72cm Oral Depth: N/A Vaginal Depth: 3-15cm...

Articles 2026-02-22