DEV Community

Cover image for EtherCAT Motion Control Card QT Development Tutorial (1)
Zmotion Controller
Zmotion Controller

Posted on

EtherCAT Motion Control Card QT Development Tutorial (1)

Today, Zmotion talks about how to develop EtherCAT motion control card by QT. And there is one complete tutorial series that composed by three aspects.

Here, the first part, we will show you how to configure development environment with one simple motion control application example, specifically, the linear interpolation motion control.

Let's begin.

1. Hardware Support

Before our development configuration, we need to know which hardware we could use. Here, ECI2828 motion control card is used.

--Brief Basic Introduction--

ECI2828 belongs to economical motion control card, and it supports rich motion control functions, such as, up to 16 axes linear interpolation, any circular interpolation, space arc, helical interpolation, electronic cam, synchronous follow, virtual axis, robot instructions, etc. And real-time motion control can be achieved through optimized network communication protocol.

--Hardware Configuration--

ECI2828 motion control card is linked with PC through ethernet and RS232, then card can receive the command from PC to run. When there is no enough motion axes, IO or analog resources, expansion modules can be connected through EtherCAT bus and CAN bus.

Image description

--Programming Method--

There are two programming methods, host computer programming languages or ZBasic, ZPLC, ZHMI that are developed by Zmotion. Here, upper computer programming platform QT is used for ECI2828, and VC, VB, VS, C++, C#, and others all can be used. It only needs to call dynamic library "zmotion.dl" when programming is running. While debugging, we could connect ECI2828 to ZDevelop that is one free programming software launched by Zmotion itself for debugging and observing.

Image description

2. How to Develop Motion Control by Qt

(1) New Build Qt Project

a. build one new Qt project

Image description

b. select project path

Image description

c. select Qt compile set (kits)

Image description

d. select basic type

Image description

(2) Copy Files Related to Function Library to New Created Project

Image description

(3) Add Static Library (zmotion.lib) of Function Library to New Created Project

a. add function library 1

Image description

b. add function library 2

Image description

c. add function library 3

Image description

d. add head file related to function library to project

Image description

e. state head file and define connection handle

Image description

3. Software Support

We talked about hardware support above, now let's see what we have and what we need to use in the software level.

For host computer development, Zmotion provides one uniform PC function library, there are PC programming manual and examples of each platform and each programming language.

Generally, ethernet is used to connect controller to IPC, the corresponding connection interface is ZAux_OpenEth(), if the connection is successful, the interface will return one link handle, then it can control the controller through this handle.

Next, let's see some basic operation PC commands.

(1) how to build the connection

Image description

(2) how to achieve multi-axis interpolation

Image description

(3) how to get axis position information

Image description

(4) how to get axis speed information

Image description

4. How to Develop Multi-Axis Interpolation Motion by Qt

(1) Multi-Axis Interpolation Motion in Qt Interface

Image description

(2) Development Steps

a. call controller link interface "ZAux_OpenEth()" in construct function to build the connection with controller, when connected successfully, open timer to monitor controller axis information.

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    int rint=0;
    ui->setupUi(this);
    //system ON, connect to controller automatically
    rint = ZAux_OpenEth("192.168.0.223", &g_handle);
    //if link successfully, open timer
    if(rint==0)
    {
       startTimer(50);
    }
}
Enter fullscreen mode Exit fullscreen mode

b. update each axis' position and speed information through the timer.

//timer event
void MainWindow::timerEvent(QTimerEvent *event)
{
    QString StrText;
    float AxisDpos[3]={0};
    float AxisMspeed[3]={0};
    if(NULL != g_handle)
    {
        for(int i=0;i<3;i++)
        {
            //obtain axis 0 position
            ZAux_Direct_GetDpos(g_handle,i,&AxisDpos[i]);
            //obtain axis 0 speed
            ZAux_Direct_GetMspeed(g_handle,i,&AxisMspeed[i]);
        }
        StrText = QString("#axis 0 position:(%1) #axis 1 position:(%2) #axis 2 position:(%3)").arg(AxisDpos[0]).arg(AxisDpos[1]).arg(AxisDpos[2]);
        ui->AxisDpos->setText(StrText);
        StrText = QString("#axis 0 speed:(%1) # axis 1 speed:(%2) # axis 2 speed:(%3)").arg(AxisMspeed[0]).arg(AxisMspeed[1]).arg(AxisMspeed[2]);
        ui->AxisMspeed->setText(StrText);
    }
}
Enter fullscreen mode Exit fullscreen mode

c. call multi-axis interpolation command to do multi-axis interpolation motion through open button.

//open button slot function: start linear interpolation motion
void MainWindow::on_RunButton_clicked()
{
    QString Text;
    int AxisList[3] = {0,1,2};
    float DisList[3]={0};
    //set axis parameters
    for(int i=0; i<3; i++)
    {
        //set axis type as pulse axis
        ZAux_Direct_SetAtype(g_handle,i,1);
        //set pulse amount, generally it is the number of required pulses for one 1mm
        ZAux_Direct_SetUnits(g_handle,i,1000);
        //set axis motion speed
        ZAux_Direct_SetSpeed(g_handle,i,200);
        //set axis acceleration
        ZAux_Direct_SetAccel(g_handle,i,2000);
        //set axis deceleration
        ZAux_Direct_SetDecel(g_handle,i,2000);
    }
    //update position data of first row
    Text = ui->DisX1->toPlainText();
    DisList[0] = Text.toFloat();
    Text = ui->DisY1->toPlainText();
    DisList[1] = Text.toFloat();
    Text = ui->DisZ1->toPlainText();
    DisList[2] = Text.toFloat();
    ZAux_Direct_MoveAbs(g_handle,3,AxisList,DisList);
    //update position data of second row
    Text = ui->DisX2->toPlainText();
    DisList[0] = Text.toFloat();
    Text = ui->DisY2->toPlainText();
    DisList[1] = Text.toFloat();
    Text = ui->DisZ2->toPlainText();
    DisList[2] = Text.toFloat();
    //update position data of third row
    ZAux_Direct_MoveAbs(g_handle,3,AxisList,DisList);
    Text = ui->DisX3->toPlainText();
    DisList[0] = Text.toFloat();
    Text = ui->DisY3->toPlainText();
    DisList[1] = Text.toFloat();
    Text = ui->DisZ3->toPlainText();
    DisList[2] = Text.toFloat();
    ZAux_Direct_MoveAbs(g_handle,3,AxisList,DisList);
}
Enter fullscreen mode Exit fullscreen mode

d. call axis stop command to stop motion through slot function of stop button.

//stop axis motion
void MainWindow::on_StopButton_clicked()
{
    ZAux_Direct_Rapidstop(g_handle,2);
}
Enter fullscreen mode Exit fullscreen mode

5. How to Transplant Routine to Linux Device

(1) Copy Corresponding Linux Library to Project Folder

Image description

(2) Add Function Library's Static Library (libzmotion.so) to New Created Project.

a. add function library 1

Image description

b. add function library 2

Image description

c. add function library 3

Image description

(3) Compile Again, Then Run Directly.

Image description

(4) Debug & Monitor

Compile and run the routine, at the same time connect to ZDevelop software to debug. In this way, axis parameters and motion situation all can be watched in real-time.

--multi-axis interpolation X-Y position waveform--

Image description

--multi-axis interpolation X-Y position waveform (continuous interpolation is OFF)--

Image description

ABOUT ZMOTION

That's all, thank you for your reading -- EtherCAT Motion Control Card QT Development Tutorial (1) | Development Environment Configuration & Simple Motion Control Example

This article is edited by ZMOTION, here, share with you, let's learn together.

ZMOTION: DO THE BEST TO USE MOTION CONTROL.

Note: Copyright belongs to Zmotion Technology, if there is reproduction, please indicate article source. Thank you.

Top comments (0)