Abstract:
In this paper,a soft PLC is used to control at third-party servo supporting EtherCAT , realizing servo point-to-point control,such as jogging,relative motion and absolute position motion.The PLC program uses the Tc2_MC2 motion control library.This is Eric.Zhou’s WeChat Official Account ”Changzhou Electrical Engineer”.
1. Software and Hardware Versions
1.1. Computer
1.1.1. Controller Hardware
An ordinary computer with Windows operating system
Intel network card with PCIE interface
1.1.2. Control Software
The ordinary computer is based on TwinCAT V3.1 Build 4024.35.
1.2. Third-part servo
1.1.3. Servo System Hardware
Servo system with EtherCAT interface,including servo drive、servo motor、limit sensor
2. Preparations
2.1. Communication Wiring and Power Supply
The servo system is supplied by AC220V, and the DIO port of the servo drive is supplied by 24V.The servo drive and the Intel network card are connected via an Ethernet cable.
Figure 2-1 Ethernet cable connection
Figure2-2 Power Connection
2.2 Description File
Copy the ESI(EtherCAT Slave Information) file for EtherCAT provided by the third-part servo,i.e.,the xxx.xmld slave device description file,to the path C:\TwinCAT\3.1\Config\Io\EtherCAT on the programming PC, then restart TwinCAT 3.
2.3. Upload I/O Configuration
Open TwinCAT XAE(TcXaeShell)
Create new project。
Right-click I/O in the Solution Explorer and select Scan from the shortcut menu.can.
A pop-up window will ask whether to connect to NC-Configuration. Select OK.
It’ll automatically create a servo axis named Axis1 and associate it with the physical servo device.
2.4. <b>Configure Servo Parameters
Navigate MOTION-->Axes-->Axis 1-->Parameter-->Monitoring-->Position Lag Monitoring,and change the value from the default TRUE to FALSE.
Set Manual Velocity(Fast) in Manual Motion and Homing to 2, and Manual Velocity(Slow) to 1.
Navigate to MOTION-->Axes-->Axis1-->Enc-->Parameter-->Scaling Factor Numerator, and change the value from the default 0.0001 to 1.
Navigate to MOTION-->Axes-->Axis1-->Enc-->Parameter-->Scaling Factor Denominator(default:1.0), and change the value from the default 1.0 to 131072.
Here, 131072 is 2 to the power of 18. For a 17-bit servo motor encoder, the encoder resolution is 131072 pulses per revolution.
All parameter configuration is completed. At this point, you can perform manual debugging via MOTION-->Axes-->Axis 1-->Online.
2.5. Add Tc2_MC2 Library File
Select myPLC-->myPLC Project-->References,right-click,and choose Add library....
In the Add Library dialog box, select <b>Motion-->PTP-->Tc2-MC2, then click OK.
2.6. Configure PLC and Visualization
Right-click PLC,select Add New Item-->Standard PLC Project.The soft PLC is created.
Expand the newly created myPLC, find VISUs, right-click it, and select Add-->Visualization.... The soft HMI is now created.
3. Programming Operations
Create a visualization interface including: servo enable button, servo enable status indicator, left jog button, right jog button, current position value display, relative position move button, absolute position move button, relative movement distance value setting, and absolute position address value setting.This is Eric.Zhou’s WeChat Official Account ”Changzhou Electrical Engineer”.
3.1. Variable Definition and Association
Define an axis reference variable in the PLC. Compile the program to deploy the variable to the entire solution.
MyAxis:axis_ref;
Open the property page tab of MyAxis,Settings-->Link To PLC...and select MAIN.MyAxis.The axis reference variable MyAxis is now associated with the physical servo axis.
Define 5 BOOL variables in the PLC for enable, left jog, right jog, relative position move, and absolute position move:
MC_Enable,L_jog,R_jog,bRelative,bAbsolute:BOOL;
Define two DINT variables in the PLC for relative position distance and absolute movement position:
Relative_Distance:DINT;Absolute_Position:DINT;
3.2. Associate Visualization Variables with PLC Variables
Drag and drop 3 Rectangle elements, 1 Lamp1 element, and 5 Button elements into the visualization interface.
The first Rectangle displays the current actual position. Set its Texts.Text property to:MyAxieCurrentPos:%.4f,(The % is a placeholder to be replaced by the text variable.)
Set the Text variable to:
The second Rectangle inputs the relative movement distance. Set its Texts.Text property to:%.4f,Set the Text variable to: MAIN.Relative_Distance.In the input configuration, set OnMouseDown to Write Variable, input type to VisuaDialogs.Numpad, and the variable to edit to MAIN.Relative_Distance.
The third Rectangle inputs the absolute movement position. Set its Texts.Text property to:Absolute Position: %.4f. Set the Text variable to: MAIN.Absolute_Position. In the input configuration, set OnMouseDown to Write Variable, input type to VisuaDialogs.Numpad, and the variable to edit to MAIN.Absolute_Position.
Set the Variable property of Lamp1 to:MAIN.MyAxis.NcToPlc.StateDWord.20
For the button with Text property set to Servo Enable, set its Toggle.Variable property to MAIN.MC_Enable (note: use Toggle.Variable).The Text and Tap.Variable properties for the other 4 buttons are shown in the table below:
Text | Tap.Variable |
L_jog | MAIN.L_jog |
R_jog | MAIN.R_jog |
Move Relative | MAIN.bRelative |
Move Absolute | MAIN.bAbsolute |
3.3. Instantiate Motion Function
In the PLC variable definition window, instantiate the enable function MC_Power with the instance name MC_PowerOn.
MC_PowerOn:MC_Power;//Shortcut for the input assistant: press F2
In the PLC variable definition window, instantiate the jog function MC_Jog with the instance name jog.
jog:MC_Jog;
In the PLC variable definition window, instantiate the relative motion function MC_MoveRelative with the instance name move_r.
move_r:MC_MoveRelative;
In the PLC variable definition window, instantiate the absolute motion function MC_MoveAbsolute with the instance name move_ab.
move_r:MC_MoveAbsolute;
In the PLC program code section write the code as follows:
MC_PowerOn(
Axis:=MyAxis,
Enable:=MC_Enable,//Servo Enable button
Enable_Positive:=TRUE,
Enable_Negative:=TRUE,
Override:= ,
BufferMode:= ,
Options:= ,);
jog(
Axis:= MyAxis,
JogForward:=L_jog,//Left jog button
JogBackwards:=R_jog,//Right jog button
Mode:= ,
Position:= ,
Velocity:= ,
Acceleration:= ,
Deceleration:= ,
Jerk:= , );
//move relative
move_r(
Axis:=MyAxis ,
Execute:=bRelative , //move relative
Distance:=Relative_Distance ,
Velocity:=1 ,
Acceleration:= ,
Deceleration:= ,
Jerk:= ,
BufferMode:= ,
Options:= ,);
//move absolute
move_ab(
Axis:=MyAxis ,
Execute:=bAbsolute , // move absolute
Position:=Absolute_Position ,
Velocity:=1 ,
Acceleration:= ,
Deceleration:= ,
Jerk:= ,
BufferMode:= ,
Options:= , );
3.4. Debugging and Operation
Click Activate Configuration,then click the Login to button.The program will run.
Click the Servo Enable button, and you will see the yellow indicator light turn on.Press Left Jog and Right Jog, and you will see the servo lead screw move accordingly.The LED display on the servo drive changes from OFF to RUN.
Enter the value 2 into the Relative Movement Distance input box and click Move Relative.You will see the current position of the lead screw increase by 2 mm accordingly.
Enter the value 1 into the Absolute Position Address input box and click Move Absolute.You will see the current position of the lead screw change to 1 mm accordingly.