Share this

MATLAB Development of EtherCAT Motion Controller

2026-04-06 04:15:04 · · #1

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 to a maximum of 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 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 supports 8-axis motion control, supporting either 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. It offers two analog AD/DA inputs and two EtherCAT outputs with a refresh rate as fast as 125µs. The ZMC408CE supports 8 channels of hardware compare output, hardware timers, and precise output during motion. It also supports 8 channels of PWM output, with corresponding output ports OUT0-7, allowing simultaneous triggering of the hardware compare output across all 8 channels.

ZMC408CE Video Introduction

01. Motion Control Development Using MATLAB

1. In MATLAB R2019a, go to "Home" → "New" → "Project" → "Blank Project" to start the project creation wizard.

2. Create a new GUI. Type "guide" in the command line to create a new GUI.

3. Locate the MATLAB function library in the CD-ROM provided by the manufacturer. The path is as follows (64-bit library as an example).

A. Locate the "8.PC Functions" folder in the CD-ROM provided by the manufacturer and click to enter.

B. Select the "Function Library 2.1" folder.

C. Select the "Windows Platform" folder.


D. Select the appropriate function library as needed; here, we choose the 64-bit library.


E. Unzip the MATLAB compressed package, which contains the corresponding function library.


4. Copy the library files and related files provided by the manufacturer to the MATLAB working directory. (1) Copy the four files "zauxdll.dll", "zmotion.dll", "zauxdll2.h", and "zmotion.h" to the MATLAB working directory. For example: C:\...\....\R2019a\bin

(2) Copy the two files “zauxdll2.h” and “zmotion.h” to the include directory.

For example: C:\...\....\R2019a\extern\include

(3) Copy the “zauxdll.dll” file to the newly created project directory.

5. Configure the MATLAB development environment.

(1) Enter “mbuild -setup” and “mex -setup” in the MATLAB command line and select the C language compiler to be installed.

(2) Load the function library using loadlibrary('zauxdll.dll','zauxdll2.h');

(3) libfunctions zauxdll -full; or libfunctionsview zauxdll; displays the signatures of shared library functions.


6. Use "calllib" to call functions in the zauxdll library. For details, please refer to the MATLAB help. Regarding parameter passing, see calllib help → Passing Parameters.

The function library has now been added, and you can now develop MATLAB projects.

02. Introduction to relevant PC functions

1. The PC function manual can be viewed on the CD-ROM. The specific path is as follows: "CD-ROM\8.PC Functions\Function Library 2.1\ZMotion Function Library Programming Manual V2.1.pdf".

2. PC programming typically involves connecting the controller and industrial PC via the network port. The network port connection function interface is ZAux_OpenEth(); if the connection is successful, this interface will return a connection handle. Controlling the controller can be achieved by manipulating this connection handle.

(1) ZAux_OpenEth() Interface Description

(2) Project application screenshots

(3) Command line application screenshot

3. Use the single-axis motion-related instructions to operate the link handle "g_handle" to perform single-axis motion control on the controller. The single-axis motion-related instructions are as follows.

(1) Single-axis relative motion command

(2) Single-axis absolute motion command

(3) Single-axis continuous motion

(4) Single-axis stop motion

03. MATLAB for Single-Axis Motion Development

1. The human-machine interface for single-axis motion control is as follows.

2. Simplified flowchart of the routine.

3. Create new controls in the MATLAB GUI interface to write programs.

A. Create a new "Normal Button" and editable text in the toolbar, and double-click to modify its properties.

B. Right-click the control, view the callback, and select "CallBack" to create a callback response function. A .m format file will be automatically created at this time, where you can write the interface response program.

C. Add the automatically created files to the project.

D. Load the function library and define global variables in the "XXX_OpeningFcn" function.

·

% --- Executes just before untitled is made visible. function untitled_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to untitled (see VARARGIN)% Choose default command line output for untitledhandles.output = hObject;% Update handles structure guidata(hObject, handles); if not(libisloaded('zauxdll'))% Load library loadlibrary('zauxdll.dll','zauxdll2.h'); end disp("Load library");% Command line printing global g_handleptr;% Define connection handle global g_nAxis;% Define axis number global g_Dir;% Define motion direction global g_Moveway; % Defines the motion method g_handleptr = libpointer('voidPtrPtr'); g_Dir = 1; g_Moveway = 0; g_nAxis = 0;

4. Write a program for the "Connect Controller" button, which calls the interface "ZAux_OpenEth()" to connect to the controller when the button is clicked.

·

% --- Executes on button press in pushbutton_openZmc.function pushbutton_openZmc_Callback(hObject, eventdata, handles)% hObject handle to pushbutton_openZmc (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) handles.timer = timer('Period',0.05,'ExecutionMode','FixedRate',... 'TimerFcn',{@UpdateSliderData, handles});%Timer global g_handleptr;%Define connection handle ip =get(handles.edit_Ip,'String'); disp("Connection controller:"+ip); zmc_ip = char(ip); [res,~] = calllib('zauxdll','ZAux_OpenEth',zmc_ip,g_handleptr); commandCheckHandler("ZAux_OpenEth",res); if res==0 fprintf('Connection to controller successful\n'); set(gcf,'NumberTitle', 'off', 'Name', 'Connection successful'); %msgbox('Connection successful'); start( handles.timer );%Start timer else fprintf('Connection to controller failed, error code %d\n',res); set(gcf,'NumberTitle', 'off', 'Name', 'Connection failed'); msgbox('Connection failure, Please check the IP!');%Connection to controller failed, please check the IP address return;end

5. Right-click on the main interface to add a destruction function, and call "ZAux_Close()" to close the connection.

·

% --- Executes during object deletion, before destroying properties. Close connection function figure1_DeleteFcn(hObject, eventdata, handles) global g_handleptr; % Define connection handle calllib('zauxdll','ZAux_Close',g_handleptr); disp("Closed connection with controller"); % Print

6. Update the controller axis status via timer: current coordinate, current speed, etc.

·

function UpdateSliderData(obj, events, handles) global g_handleptr;%Define connection handle global g_nAxis;%Define axis number [res,~,runstate]=calllib('zauxdll','ZAux_Direct_GetIfIdle',g_handleptr,g_nAxis, 0); commandCheckHandler("ZAux_Direct_GetIfIdle",res); [res,~,curpos]=calllib('zauxdll','ZAux_Direct_GetDpos',g_handleptr, g_nAxis, 0); commandCheckHandler("ZAux_Direct_GetDpos",res); [res,~,curspeed]=calllib('zauxdll','ZAux_Direct_GetVpSpeed',g_handleptr, g_nAxis, 0); commandCheckHandler("ZAux_Direct_GetVpSpeed",res); str_curpos=num2str(curpos); str_curspeed=num2str(curspeed); if (runstate==0) set(handles.edit_runstate,'String',"Current motion state: Running"); else set(handles.edit_runstate,'String',"Current motion state: Stopped"); end set(handles.edit_curpos,'String',"Current axis coordinate: " +str_curpos);set(handles.edit_curspeed,'String',"Current axis speed: " +str_curspeed);

7. Set the axis parameters and start the motion by using the event handler function of the start button.

·

% --- Executes on button press in pushbutton_runmove. `function pushbutton_runmove_Callback(hObject, eventdata, handles)` % `hObject`: handle to pushbutton_runmove (see GCBO) % `eventdata`: reserved - to be defined in a future version of MATLAB % `handles` structure with handles and user data (see GUIDATA) `global g_handleptr;` % Defines the connection handle `global g_nAxis;` % Defines the axis number `global g_Dir;` % Defines the direction of motion `global g_Moveway;` % Defines the motion mode `calllib('zauxdll','ZAux_Direct_SetAtype',g_handleptr, g_nAxis,0);` `calllib('zauxdll','ZAux_Direct_SetUnits',g_handleptr,g_nAxis,str2num(get(handles.edit_units,'String')));` calllib('zauxdll','ZAux_Direct_SetLspeed',g_handleptr, g_nAxis, str2num(get(handles.edit_lspeed,'String'))); calllib('zauxdll','ZAux_Direct_SetSpeed',g_handleptr, g_nAxis, str2num(get(handles.edit_speed,'String'))); calllib('zauxdll','ZAux_Direct_SetAccel',g_handleptr, g_nAxis, str2num(get(handles.edit_acc,'String'))); calllib('zauxdll','ZAux_Direct_SetDecel',g_handleptr, g_nAxis, str2num(get(handles.edit_dec,'String'))); calllib('zauxdll','ZAux_Direct_SetSramp',g_handleptr, g_nAxis, str2num(get(handles.edit_sramp,'String'))); if (g_Moveway) %//Continuous motion calllib('zauxdll','ZAux_Direct_Single_Vmove',g_handleptr, g_nAxis,g_Dir); else % //Inching calllib('zauxdll','ZAux_Direct_Single_Move',g_handleptr, g_nAxis, g_Dir * str2num(get(handles.edit_step,'String'))); end

8. Stop the interpolation motion by using the event handler function of the stop button.

·

% --- Executes on button press in pushbutton_stopMove. Single-axis stop function pushbutton_stopMove_Callback(hObject, eventdata, handles) global g_handleptr; % Defines the connection handle global g_nAxis; calllib('zauxdll','ZAux_Direct_Single_Cancel',g_handleptr,g_nAxis,2);

04. Debugging and Monitoring

Compile and run the routines, and connect to the ZDevelop software for debugging, monitoring the axis parameters and motion status of the motion control.

1. Connect the ZDevelop software and click "View" → "Oscilloscope" to open the oscilloscope and monitor the axis movement.

2. Run the host computer software for debugging and monitoring.

That concludes our sharing of the MATLAB development of the EtherCAT motion controller using positive motion technology.

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 Sasha 60cm – Soft TPE Petite Body

Height: 60cm Weight: 2.5kg Shoulder Width: 14cm Bust/Waist/Hip: 27/24/31cm Oral Depth: N/A Vaginal Depth: 5-8cm Anal De...

Articles 2026-02-22
CATDOLL Dora Hybrid Silicone Head

CATDOLL Dora Hybrid Silicone Head

Articles
2026-02-22
CATDOLL 128CM Hedi

CATDOLL 128CM Hedi

Articles
2026-02-22