Bring Values and Sucesses To Our Customers

Home / Support and services / Technical Support

Technical support

Technical Support

How to Develop Motion Controller by MATLAB

ZMOTION

--Hardware Controller ZMC408CE--

ZMC408CE is one multi-axis high-performance EtherCAT motion controller, there are EtherCAT, EtherNET, RS232, CAN, and U disk communication interfaces.

It supports 8-axis motion control, but it can be up to 32 axes. Functions of linear interpolation, circular interpolation, space arc, helical interpolation, electronic cam, electronic gear, synchronous follow are valid.

For development, there are 3 programming methods (PLC, Basic, HMI) and main PC languages (C# C++ LabVIEW MATLAB Qt Linux VB.Net Python) of Zmotion uniform API function library.

1.png

Except above functions, there are hardware comparison output, hardware timer, precision output in motion, PWM, etc., below video link can show you more.

2.png

ZMC408CE Video Description


01
Motion Control Development by MATLAB

(1) Create One Project

In MATLAB R2019a menu, click "Main" -- "New" -- "Project" -- "Empty Project".

3.png

3-1.png


(2) Create One GUI

In command line, enter "guide" to build one GUI.

4.png

5.png


(3) Refer to Zmotion MATLAB Function Library

Here, take 64-bit library as the example.

A. Get Zmotion MATLAB Function Library

Zmotion provides one uniform encapsulated function library, it supports all kinds of host computer programming languages. If you want corresponding function library, please contact us. When you get MATLAB compressed package, it shows like this:

6.png

B. How to Use Zmotion Library File

It only needs to copy library file and corresponding file into MATLAB working directory.

--copy these four files ("zauxdll.dll", "zmotion.dll", "zauxdll2.h", "zmotion.h") into "matlab" working directory--

For example: C:\...\....\R2019a\bin

--copy these two files ("zauxdll2.h", "zmotion.h") into "include" directory--

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

--copy "zauxdll.dll" into new built project directory--

7.png


(4) How to Configure MATLAB Development Environment

A. In MATLAB command line, enter "mbuild -- setup" and "mex -- setup", then select installed C language compiler.

8.png

B. Use "loadlibrary('zauxdll.dll','zauxdll2.h')" to load function library.

9.png

C. Show shared library function signature: libfunctions zauxdll -full; / libfunctionsview zauxdll;.

10.png


(5) Use "calllib" to call the function that is in "zauxdll" function library. For details, please check MATLAB help.

--for corresponding parameters transfer, please click "transfer parameter" in calllib help--

11.png

12.png

13.png

At this time, function library is added. It is time to do MATLAB project development.




02
PC Function Introduction

As it was mentioned above, Zmotion provides one uniform encapsulated function library. Specifically, there are many commands to achieve corresponding functions. They can be referred from Zmotion PC Function Library Programming Manual, which can be obtained from our Zmotion website or contact us directly.

A. Controller Connection Interface: ZAux_OpenEth()

Generally, for PC programming, the controller and IPC are connected through Ethernet. The Ethernet linking function interface is ZAux_OpenEth(). When the connection is built successfully, this interface will return one connection handle. Then, it can control the controller through this connection handle.

--command introduction--

14.png

--project application showing--

15.png

--command line application showing--

16.png


B. Single-Axis Motion Control

Use single-axis corresponding command to operate the connection handle "g_handle", then do single-axis motion control for the controller.

--how to control relative single-axis motion--

17.png

--how to control absolute single-axis motion--

18.png

--how to control continuous motion--

19.png

--how to stop single-axis motion--

20.png




03
Develop Single-Axis Motion by MATLAB

(1) Single-Axis Motion Control HMI Interface

21.png


(2) Routine Simple Process

22.png


(3) Program Editing

In MATLAB CUI Interface, build one new control to do programming.

A. Build one "normal button" and one "editable text" in Tool, then double click to modify the property.

23.png

B. Right click the control, and click the "Callback" to build one callback respond function. At this time, .m form file is created automatically. Then, edit the respond program.

24.png

C. Add the automatic built file into project.

25.png

D. In "XXX_OpeningFcn" function, load the function library , and define global variable.

26.png


(4) Edit "connect" (connect to controller) button program , call the interface "ZAux_OpenEth()", while clicking the button, now it connects to the controller.  

27.png


(5) In main interface, right click to add one "delete" function, call the interface "ZAux_Close()" to close the connection.

28.png

29.png


(6) Update controller axis states through timer : current coordinates, current speed, etc.

30.png


(7) Set axis parameters and start to move through the event processing function of "Run" button.

31.png


(8) Stop interpolation motion through the event processing function of "Stop" button.

32.png




04
Watch & Debug

When compiling and running the routine, it can debug it at the same time in ZDevelop software (ZDevelop is one free programming software made by Zmotion, it can be downloaded from here or contact us), including axis parameters, motion situation.

(1) Watch by "SCOPE" in ZDevelop

Connect the controller to ZDevelop, then click "View"--"Scope". Open the oscilloscope window, then, axis motion situation can be watched in real-time.

33.png

34.png


(2) Run PC Programming Software to Debug & Watch

35.png

36.png


Copyright © 2013-2024 Shenzhen Zmotion Technology Co.,Ltd Design by Zmotion    粤ICP备13037187号 Motion Controller-Motion Control Card

Contact Us-Youtube