Today, Zheng Motion Assistant will share with you how to use C# to implement applications such as electronic cam tracking shears and flying shears using the EtherCAT motion control card ECI2828.
I. ECI2828 Hardware Introduction
The ECI2828 series motion control card supports up to 16-axis linear interpolation, arbitrary circular interpolation, spatial circular interpolation, helical interpolation, electronic cams, electronic gears, synchronous following, virtual axes, and robot commands; it uses an optimized network communication protocol to achieve real-time motion control.
The ECI2828 series motion control card supports Ethernet and a RS-232 communication interface to connect to a computer, receive commands from the computer, and can connect to various expansion modules via EtherCAT and CAN buses to expand the number of input/output points or motion axes.
Applications for the ECI2828 series motion control card can be developed using software such as VC, VB, VS, C++, and C#. The program requires the dynamic library zmotion.dll to run. During debugging, the ZDevelop software can be connected to the controller simultaneously for easier debugging and observation.
Typical connection configuration diagram of ECI2828 series
II. Motion Control Development using C#
I. View the PC function manual to create a new WinForm
1. In VS2015, go to "File" → "New" → "Project" to start the Project Creation Wizard.
2. Select "Visual C#" as the development language and .NET Framework 4 as the Windows Forms application.
3. Locate the C# function library in the CD-ROM provided by the manufacturer. The path is as follows (for a 64-bit library):
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 C# compressed file, which contains the corresponding C# function library.
F. The specific path to the function library is as follows.
4. Copy the C# library files and related files provided by the vendor into the newly created project.
A. Copy the zmcaux.cs file into the newly created project.
B. Place the zaux.dll and zmotion.dll files into the bin\debug folder.
5. Open the newly created project file in Visual Studio. In the Solution Explorer on the right, click "Show All". Then, right-click the zmcaux.cs file and click "Include in Project".
6. Double-click Form1 in Form1.cs to open the code editing interface. At the beginning of the file, write using cszmcaux and declare the controller handle g_handle.
The project is now complete and ready for C# development.
II. Refer to the PC function manual
1. The PC function manual is also included in the CD-ROM materials. The specific path is as follows: "CD-ROM materials\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.
ZAux_OpenEth() Interface Description:
Command 7ZAux_OpenEth
Project application screenshots:
3. Use the cam instruction to operate the link handle "g_handle" to perform electronic cam motion control on the controller. The instructions related to continuous interpolation motion are as follows.
ZAux_Direct_Cambox electronic cam instruction:
Command 6ZAux_Direct_Cam
III.C# electronic cam tracking and shearing motion development
1. The human-machine interface for the electronic cam tracking shear flying shear motion control is as follows.
2. Electronic Cam Function Description.
The function of a cam is to convert rotational motion into linear motion, including linear motion, oscillation, uniform motion, and non-uniform motion.
Electronic cams are software systems that use constructed cam curves to simulate mechanical cams, achieving the same relative motion between the camshaft and spindle as mechanical cam systems. They simulate the function of mechanical cams by controlling servo motors through controllers, without requiring additional mechanical structures.
●Working principle:
Electronic cams belong to multi-axis synchronous motion. This motion is based on a master shaft plus one or more slave shaft systems and is developed from mechanical cams. Electronic cams are mostly used in periodic curvilinear motion applications.
Electronic cams use software to control signals. Changing the relevant motion parameters in the program can change the motion curve. They are highly flexible in application, reliable in operation, and simple to operate. They do not require additional mechanical components and therefore do not experience wear.
3. Simplified flowchart of the routine.
4. Call the interface ZAux_OpenEth() in the constructor of Form1 to automatically link the controller during system initialization.
private void button1_Click(object sender, EventArgs e){ zmcaux.ZAux_OpenEth(IP_List.Text, out g_handle); if (g_handle != (IntPtr)0) { timer1.Enabled = true; // Set the connection status button status.BackColor = System.Drawing.Color.Green; status.Text = "Connected"; } else { MessageBox.Show("Controller connection failed, please check IP address!", "Warning"); // Set the connection status button status.BackColor = System.Drawing.Color.Red; status.Text = "Disconnected"; }}
5. Update parameter information using a timer.
//Timer private void timer1_Tick(object sender, EventArgs e){ if(g_handle != null) { float dpos = 0, speed = 0; zmcaux.ZAux_Direct_GetDpos(g_handle, Convert.ToInt32(textBox_axis.Text),ref dpos); label_dpos.Text = Convert.ToString(dpos); zmcaux.ZAux_Direct_GetSpeed(g_handle, Convert.ToInt32(textBox_axis.Text), ref speed); label_speed.Text = Convert.ToString(speed); } else { status.BackColor = System.Drawing.Color.Red; status.Text = "Disconnected"; }}
6. Using pre-loaded cam table data, perform cam motion using CAM commands.
//Cam table movement starts private void button3_Click(object sender, EventArgs e){ if (g_handle == null) return; zmcaux.ZAux_Direct_SetUnits(g_handle, Convert.ToInt32(textBox_axis.Text),Convert.ToSingle(textBox_unit.Text)); zmcaux.ZAux_Direct_SetSpeed(g_handle, Convert.ToInt32(textBox_axis.Text), Convert.ToSingle(textBox_speed.Text)); zmcaux.ZAux_Direct_SetAccel(g_handle, Convert.ToInt32(textBox_axis.Text), Convert.ToSingle(textBox_accel.Text)); zmcaux.ZAux_Direct_SetDecel(g_handle, Convert.ToInt32(textBox_axis.Text), Convert.ToSingle(textBox_decel.Text)); zmcaux.ZAux_Direct_SetAtype(g_handle, Convert.ToInt32(textBox_axis.Text), 1);
//Perform electronic cam motion//Set the total motion time to 5s zmcaux.ZAux_Direct_Cam(g_handle, Convert.ToInt32(textBox_axis.Text),0, CamNum, Convert.ToSingle(textBox_unit.Text), Convert.ToSingle(textBox_speed.Text)*5);}
7. Load externally imported cam table data.
private void button_data_Click(object sender, EventArgs e) { dataGridView_data.Columns.Clear(); DataGridViewTextBoxColumn ActPos = new DataGridViewTextBoxColumn(); ActPos.Name = "ActPos"; ActPos.DataPropertyName = "ActPos"; ActPos.HeaderText = "Position"; dataGridView_data.Columns.Add(ActPos); OpenFileDialog ZaoLangFile = new OpenFileDialog(); ZaoLangFile.Filter = "Text file(*.txt;)| *.txt;| All files| *.*; "; ZaoLangFile.ValidateNames = true; ZaoLangFile.CheckPathExists = true; ZaoLangFile.CheckFileExists = true; if (ZaoLangFile.ShowDialog() == DialogResult.OK) { string strFileName = ZaoLangFile.FileName; //Other code//FileStream FileRead = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.Read); string DataTest = File.ReadAllText(strFileName); string[] strArray = DataTest.Split(new string[] { "\r\n" }, StringSplitOptions.None); for (int i = 0; i < strArray.Length - 1; i++) { int index = dataGridView_data.Rows.Add(); dataGridView_data.Rows[index].Cells[0].Value = strArray[i]; } float[] Tablelist = new float[strArray.Length]; for (int i = 0; i < strArray.Length - 1; i++) { Tablelist[i] = Convert.ToSingle(strArray[i]); } zmcaux.ZAux_Direct_SetTable(g_handle,0,strArray.Length,Tablelist); //Record how much data is currently written to the cam table CamNum = strArray.Length - 2; } }
8. Load custom cam table data.
private void button6_Click(object sender, EventArgs e){ dataGridView_data.Columns.Clear(); DataGridViewTextBoxColumn ActPos = new DataGridViewTextBoxColumn(); ActPos.Name = "ActPos"; ActPos.DataPropertyName = "ActPos"; ActPos.HeaderText = "Position"; dataGridView_data.Columns.Add(ActPos); float[] CustomTable = new float[100]; for (int i = 0; i < 100; i++) { CustomTable[i] = (float )((Math.Sin(Math.PI*2*i/100) / (Math.PI*2)) + i / 100) * 500; int index = dataGridView_data.Rows.Add(); dataGridView_data.Rows[index].Cells[0].Value = CustomTable[i]; } zmcaux.ZAux_Direct_SetTable(g_handle, 0, 100, CustomTable); CamNum = 100;}
IV. Debugging and Monitoring
1. Compile and run the routine, and connect to ZDevelop software for debugging to monitor the axis parameters and motion status of motion control.
The motion is performed using electronic cam commands. The axis motion is set to move according to the data in the cam table. All motion data are offset relative to the position of the first data point by an absolute position offset.
(1) As shown in the figure above, the motion is a certain trajectory data of the wave-making device, which is loaded into the table of the controller. The actual trajectory of the motion is completed within the set time.
(2) As shown in the figure above, the running data is the motion data of the internally customized sin waveform. The waveform can be seen from the figure. The trajectory of the small moving line segment data is completed within a specified time.
2. Video demonstration.
That concludes our discussion of the electronic cam and other applications of the EtherCAT motion control card.
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.