当前位置:网站首页>Calling Laser Galvanometer control in the application and development tutorial of motion control card
Calling Laser Galvanometer control in the application and development tutorial of motion control card
2022-07-24 21:56:00 【Suzhou program white】
The application and development tutorial of motion control card calls Laser Galvanometer control
Blogger introduction
Personal home page : Suzhou program white Personal community :CSDN All over the country 🤟 The authors introduce : China DBA union (ACDU) member ,CSDN All over the country ( Yuan ) Gathering place Administrator . Currently engaged in industrial automation software development . Good at C#、Java、 Machine vision 、 Underlying algorithms and other languages .2019 Qiyue software studio was established in ,2021 Registered in Suzhou Kaijie Intelligent Technology Co., Ltd If you have any questions, please send a private letter , I will reply in time when I see it WeChat ID :stbsl6, WeChat official account : Suzhou program white If it helps you , Welcome to your attention 、 give the thumbs-up 、 Collection ( One key, three links ) Those who want to join the technical exchange group can add my friends , The group will share learning materials
Preface
today , Share the application with the motion control card C++ Develop a motion control routine of Laser Galvanometer .
We mainly start from New MFC project , Add a function library to talk about , Finally, through the actual combat of the project —— Explanation of laser galvanometer marking routine , To make everyone familiar with its project development .
Galvanometer shaft :
ZMC420SCAN Support XY2-100 Galvanometer agreement , Support motion control and galvanometer joint interpolation motion .
The upper computer is connected with the controller through the network port , Get the handle of the corresponding controller , adopt XY2-100 Protocol control galvanometer axis , Control servo or stepping axis through bus protocol or pulse mode .

Local axis number 4/5 Sure ATYPE=21 It is configured as 1 A galvanometer , Local axis number 6/7 Sure ATYPE=21 It is configured as 2 A galvanometer , It can be done by AXIS_ADDRESS Configure the shaft number .
Development process of Laser Galvanometer control
1、 newly build MFC project Add function library (net Latest 4.0 Above version )
stay VS2017 menu “ file ”→“ newly build ”→“ project ”, Start the create project wizard .
2、 Select the development language as “Visual C++” And program type “MFC/ATL” Medium “MFC Applications ”.

3、 Select type as “ Based on dialog ”, Next step or finish . The next step is to continue to configure , Just finish it directly . Choose the type , Others can be edited in the project :
4、 Find the CD data provided by the manufacturer , Path as follows (64 Take the location library as an example ):
A、 Go to the CD-ROM and find PC Function folder .
B、 Select function library 2.1.
C、Windows platform .

D、 Select the corresponding function library as needed, and select 64 Location base .
E、 decompression C++ The package , There are C++ Corresponding function library .

F、 The specific path of the function library is as follows :
5、 Will be provided by the manufacturer C++ Copy the library file and related header file to the new project .

6、 Add static libraries and related header files to the project .
Static library :zauxdll.lib, zmotion.lib
Related header file :zauxdll2.h, zmotion.h
A、 Right click the header file first , Then choose :“ add to ”→“ Existing items ”.

B、 In the pop-up window, add the static library and related header files in turn .

7、 Declare the header file used and define the controller connection handle .
Reference the project until the new project is completed .
see PC Function manual Know how to use it
1、 The function manual is also on the CD , The specific path is as follows :
2、PC Programming , Generally, select the corresponding connection function to connect the controller according to the connection mode of the controller , Returns the controller handle . Then use the returned controller handle , Realize the control of the controller .
3、 For example, connect the controller through the network port , First use ZAux_OpenEth() Link controller , Get controller handle handle.

4、 Through the obtained controller handle handle, Set the type of Laser Galvanometer axis for the controller .
The value of the third parameter has the following mode choices , When using galvanometer shaft, select shaft type 21 The pattern of , Set the shaft to galvo shaft type , The system cycle and refresh cycle of galvanometer shaft type are much faster than ordinary shafts .
5、 Through the obtained controller handle handle, Control the galvanometer axis of the controller for multi axis motion control , It can be combined with galvanometer axis and ordinary axis for mixed interpolation movement .
Laser galvanometer marking routine for project practice
1、 Routine to establish the connection of the board , And set the corner deceleration and speed parameters of the galvanometer axis , Process the motion track set internally to complete the marking of the circle .
2、 Simple flow chart of routine 
3、 Connect the controller through the network port , Get controller connection handle
//ip Connect
void CMarkDemoDlg::OnBnClickedButton2()
{
// TODO: Add control notification handler code here
char buffer[256];
char item[256] = {
0};
float ftemp = 0.0;
char atemp[256] = {
0}; // Storage controller model
uint32 uitemp = 0;
int32 iresult;
if(NULL != g_handle)
{
ZMC_Close(g_handle);
g_handle = NULL;
}
GetDlgItemText(IDC_IP_COMBO,buffer,255); // Get IP Address
buffer[255] = '\0';
iresult = ZMC_OpenEth(buffer, &g_handle); // Get the results of establishing a connection with the controller
if(ERR_SUCCESS != iresult)
{
g_handle = NULL;
MessageBox(_T("Connect Failed"));
SetWindowText(_T("ZControlTest-Connect Failed"));
return;
}
SetWindowText("succse");
//
CComboBox *m_pEthList;
m_pEthList = (CComboBox *)GetDlgItem(IDC_IP_COMBO); // obtain ip Address
if(NULL == m_pEthList)
{
return;
}
//
if(CB_ERR != m_pEthList->FindString(0, buffer))
{
return;
}
// Join in
m_pEthList->AddString(buffer); // take ip Add the address to the box
}
4、 Connect the controller through serial port , Get controller connection handle .
void CMarkDemoDlg::OnBnClickedButton4()
{
// TODO: Add control notification handler code here
int32 iresult;
uint8 icomid;
float ftemp = 0.0;
char atemp[256] = {
0}; // Storage controller model
uint32 uitemp = 0;
int m_icombaud;
if(NULL != g_handle)
{
ZMC_Close(g_handle);
g_handle = NULL;
}
CComboBox *m_pParityList;
m_pParityList = (CComboBox *)GetDlgItem(IDC_COMBO_PARITY);
m_icombaud = GetDlgItemInt(IDC_BAUD_COMBO);
ZMC_SetComDefaultBaud(m_icombaud, 8, m_pParityList->GetCurSel(), ONESTOPBIT);
icomid = GetDlgItemInt(IDC_PORT_COMBO);
iresult = ZMC_OpenCom(icomid, &g_handle);
if(ERR_SUCCESS != iresult)
{
g_handle = NULL;
MessageBox(_T("Connect Failed"));
return;
}
SetWindowText("success");
CString Comname;
CComboBox *m_pComList;
m_pComList = (CComboBox *)GetDlgItem(IDC_PORT_COMBO);
if(NULL == m_pComList)
{
return;
}
Comname.Format("%d",icomid);
//
if(CB_ERR != m_pComList->FindString(0, Comname))
{
return;
}
// Join in
m_pComList->AddString(Comname);
}
5、 Use the generated handle to configure axis parameters , Shaft type, etc
int axislist[2] = {
4,5};
char cbuf[32] = {
};
// Set the spindle
ZAux_Direct_Base(g_handle, 2, axislist);
// Get the parameters to be set in the edit box
int MachSpeed = GetDlgItemInt(IDC_EDIT_SPEED);
int MachAddSpeed = GetDlgItemInt(IDC_EDIT_ADDSPEED);
int MachDecSpeed = GetDlgItemInt(IDC_EDIT_DECSPEED);
float MachDecAngle = GetDlgItemInt(IDC_EDIT_DECANGLE) * 3.14 / 180;
float MachStopAngle = GetDlgItemInt(IDC_EDIT_STOPANGLE) * 3.14 / 180;
// Axis initialization
for (int i = 4; i <= 5; i++)
{
// Set the shaft type to galvo shaft type
ZAux_Direct_SetAtype(g_handle, i, 21);
// Set the number of pulses per cycle
ZAux_Direct_SetUnits(g_handle, i, 300);
// set speed
ZAux_Direct_SetSpeed(g_handle, i, MachSpeed);
// Set the acceleration
ZAux_Direct_SetAccel(g_handle, i, MachAddSpeed);
// Set the deceleration
ZAux_Direct_SetDecel(g_handle, i, MachDecSpeed);
// Open the galvanometer axis for continuous interpolation
ZAux_Direct_SetMerge(g_handle, i, 1);
// Set corner deceleration mode and automatic chamfer mode
ZAux_Direct_SetCornerMode(g_handle, i, 32+2);
// Set the corner radius
ZAux_Direct_SetZsmooth(g_handle, i, 0.1);
// Set the small circle speed limit radius
ZAux_Direct_SetFullSpRadius(g_handle, i, 20);
// Set the deceleration angle
ZAux_Direct_SetDecelAngle(g_handle, i, MachDecAngle);
// Set the stop angle
ZAux_Direct_SetStopAngle(g_handle, i, MachStopAngle);
// Set up SP Speed
ZAux_Direct_SetForceSpeed(g_handle, i, 5000);
}
// Turn on the precise output function
ZAux_DirectCommand(g_handle, "AXIS_ZSET(4)=2", cbuf, 32);
ZAux_Direct_SetOp(g_handle, 11, 1);
ZAux_Direct_Base(g_handle, 2, axislist);
ZAux_Direct_SetOp(g_handle, 1, 1);
6、 The trajectory movement data of this routine is input by itself in the mode of small line segments , In the process of running, the method of arc fitting with multiple small segments is used to speed up the processing operation .
Single circle CAD Trajectories :
The corresponding part of track data and use code are as follows :
// A single circle is opposite
double x1[] = {
-0.038000, -0.113000, -0.184000, -0.250000, -0.308000, -0.357000, -0.395000, -0.421000, -0.434000, -0.434000, -0.421000, -0.395000, -0.357000, -0.308000, -0.250000, -0.184000, -0.113000, -0.038000, 0.038000, 0.113000, 0.184000, 0.250000, 0.308000, 0.357000, 0.395000, 0.421000, 0.434000, 0.434000, 0.421000, 0.395000, 0.357000, 0.308000, 0.250000, 0.184000, 0.113000, 0.038000};
double yh1[] = {
0.434000, 0.421000, 0.395000, 0.357000, 0.308000, 0.250000, 0.184000, 0.113000, 0.038000, -0.038000, -0.113000, -0.184000, -0.250000, -0.308000, -0.357000, -0.395000, -0.421000, -0.434000, -0.434000, -0.421000, -0.395000, -0.357000, -0.308000, -0.250000, -0.184000, -0.113000, -0.038000, 0.038000, 0.113000, 0.184000, 0.250000, 0.308000, 0.357000, 0.395000, 0.421000, 0.434000};
Description of small segment to arc function :
/************************************************************* Description: // The small segment becomes an arc Input: //handle: Connected controller handle //pXPos: Line segment x Coordinate arrays //pYPos: Line segment y Coordinate arrays //nMaxNum: The maximum number of points //nMaxFitNum: Maximum number of fitting segments (100~1000) //nAbs:1= absolute ;0= relative ; Means the incoming x、y Is the coordinate data absolute or relative //refDistance: Reference accuracy Output: // Return: // Error code *************************************************************/
int __stdcall ZGraphProcess_SegFitArc(ZMC_HANDLE handle, double *pXPos, double *pYPos, int nMaxNum, int nMaxFitNum, int nAbs, double refDistance);
Use this function to fit multiple small segments into an arc to simplify the operation steps , There is no need to carry out the interpolation operation of each small segment separately .
The code uses a single circle fitting to mark the array circle horizontally and vertically .
int axislist[2] = {
4,5};
char cbuf[32] = {
};
// Set the spindle
ZAux_Direct_Base(g_handle, 2, axislist);
for (int k = 0; k < 1; k++)
{
for (int i = 0; i < 5; i++)
{
// Move to a specified location
ZAux_DirectCommand(g_handle, "MOVE (0, -15)", cbuf, 32);
for (int j = 0; j < 5; j++)
{
ZAux_DirectCommand(g_handle, "MOVE (-15, 0)", cbuf, 32);
ZAux_Direct_MoveOp(g_handle, 0, 1);
// Turn small segments into arcs
int err_seg = ZGraphProcess_SegFitArc(g_handle, x1, yh1, sizeof(x1)/sizeof(double), 1000, 0, 0.01);
ZAux_Direct_MoveOp(g_handle, 0, 0);
}
ZAux_DirectCommand(g_handle, "MOVE (75, 0)", cbuf, 32);
}
ZAux_DirectCommand(g_handle, "MOVE (0, 75)", cbuf, 32);
}
7、 Compile and run the demo :
1、 Compile and run the teaching routine :
2、 At the same time through ZDevelop The software connects to the same controller , Monitor the axis parameters of motion control .
Marking 25 The circular time and oscilloscope display graphics are as follows :
边栏推荐
- Sqlserver BCP parameter interpretation, character format selection and fault handling summary
- Practical skills!!
- Using skills and design scheme of redis cache (classic collection version)
- 腾讯+360+搜狗校招笔试题+知识点总结
- Discussion on solving the application ecological problems of domestic systems based on small programs
- "Iruntime": undeclared identifier
- It's the same type of question as just K above
- Understand MySQL index and b+tree in an easy to understand way (supreme Collection Edition)
- Huawei cloud data governance production line dataarts, let "data 'wisdom' speak"
- Circom 2.0: A Scalable Circuit Compiler
猜你喜欢

模板的使用

Mathpix formula extractor

How to gracefully realize regular backup of MySQL database (glory Collection Edition)

Shell introduction and variable definition

Brand new: the latest ranking of programming languages in July

91. (leaflet chapter) leaflet situation plotting - offensive direction drawing

RISC0:Towards a Unified Compilation Framework for Zero Knowledge

Composability and Recursion in snarkyJS

【考研英语词汇训练营】Day 11 —— offer ,form ,maintain ,critical

Easily make 2D tile map with unity tilemap - Basics
随机推荐
Documentary of the second senior brother
[SOC] the first project of SOC Hello World
Image processing notes (1) image enhancement
How about opening an account for CITIC Securities? Is it safe
Prefabricated financial voucher Bapi
OSI architecture and protocols at all levels
RISC0:Towards a Unified Compilation Framework for Zero Knowledge
《论文复现》BiDAF代码实现过程(4)模型训练+验证
Big country "grain" policy | wheat expert Liu Luxiang: China's rations are absolutely safe, and the key to increasing grain potential lies in science and technology
Metauniverse: technological evolution, industrial ecology and big country game
中移链(基于EOS)测试环境搭建
Binary search
Leetcode skimming -- bit by bit record 017
Today, there's a power failure for one day.... stop working for another day. Don't forget to study
巧妙使用sort(List&lt;T&gt;,Comparator&lt;? super T&gt;)比较器
Conditional judgment of Shell Foundation
[crawler knowledge] better than lxml and BS4? Use of parser
Unfair distribution
图像处理笔记(1)图像增强
MySQL - multi table query - seven join implementations, set operations, multi table query exercises