攥写偏主观,有问题在评论区提出;
另外,本站更换了Giscuz评论,任何人评论都需要登录Github!
根据Beckhoff官方视频教程如下几个标题:
Gear.mp4、PLC_code.mp4、System_config.mp4、TC3_Connet_ScanIO_Freerun.mp4、TC3_Motion_Gear1.mp4、TC3_Motion_Gear2.mp4、TC3_Program_Autostart.mp4
其中主要学习了两个实践:
AXIScontrol
和HmiControl
两个文件,创立的意义在于分清Axis轴动控制,和Hmi触摸屏控制;
然后在Main程序中依次引入就可以了如下:AXIScontrol();
//引入HMI控制
HmiControl();
在 (1)之前理应创立好对应的nc虚拟轴,master主轴和slave跟踪轴,(如果是硬件连接了ethercat实体伺服+电机,Twincat系统会自动创建Nc轴)
根据让轴运动的思路,理应给轴使能,我们需要MC_power功能块;在Twincat3中的references
中可引入Tc2_MC2后才能在输入助手中找到该功能块,同时我还引入了Tc2_MC2_Camming,这样就可以引入耦合功能块
我建立了两个轴,一个叫做axis 一个叫做axis2
//变量表
PROGRAM AXIScontrol
VAR
bstart : int :=0;
axis,axis2:axis_ref;
power_do: BOOL;
axis_power : MC_Power;
axis_power2 : MC_Power;
axis_jog :MC_Jog;
axis_jog2:MC_Jog;
axis_headmove: BOOL;
axis_rela : MC_MoveRelative;
axismoverela_distance: LREAL;
axismoverela_velocity: LREAL;
axismoverela_staus : BOOL;
ton1 :TON;
gearin :MC_GearIn;
gearout :MC_GearOut;
axis_headmove2: BOOL;
AxisReset1:MC_Reset;
AxisReset2:MC_Reset;
Axis1Setpos:MC_SetPosition;
Axis1Setpos_do:BOOL;
Axis1SetposWord:REAL;
Axis2SetposWord:REAL;
Axis2Setpos:MC_SetPosition;
Axis2Setpos_do:BOOL;
Axis1Home:MC_Home;
Axis2Home:MC_Home;
Axis1Home_do :BOOL;
Axis2Home_do :BOOL;
HomeSensor : BOOL;
AxisCamIn:MC_CamIn;
AxisCamIn_do :BOOL;
AxisCamout :MC_CamOut;
AxisCamout_do :BOOL;
END_VAR
VAR_INPUT
axismoverela_do: BOOL :=FALSE;
AxisReset_do : BOOL :=FALSE ;
gearin_do : BOOL;
gearout_do : bool;
END_VAR
//给nc轴上使能
axis_power(
Axis:= axis,
Enable:= power_do,
Enable_Positive:= TRUE,
Enable_Negative:=TRUE,
Override:= ,
BufferMode:= ,
Options:= ,
Status=> ,
Busy=> ,
Error=> ,
ErrorID=> );
axis_power2(
Axis:= axis2,
Enable:= power_do,
Enable_Positive:= TRUE,
Enable_Negative:=TRUE,
Override:= ,
BufferMode:= ,
Options:= ,
Status=> ,
Busy=> ,
Error=> ,
ErrorID=> );
//JOG
axis_jog(
Axis:=axis ,
JogForward:= axis_headmove ,
JogBackwards:= ,
Mode:= ,
Position:= ,
Velocity:= ,
Acceleration:= ,
Deceleration:= ,
Jerk:= ,
Done=> ,
Busy=> ,
Active=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
axis_jog2(
Axis:=axis2,
JogForward:= axis_headmove2 ,
JogBackwards:= ,
Mode:= ,
Position:= ,
Velocity:= ,
Acceleration:= ,
Deceleration:= ,
Jerk:= ,
Done=> ,
Busy=> ,
Active=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
//相对运动
axis_rela(
Axis:= axis,
Execute:= axismoverela_do,
Distance:= axismoverela_distance,
Velocity:= axismoverela_velocity,
Acceleration:= ,
Deceleration:= ,
Jerk:= ,
BufferMode:= ,
Options:= ,
Done=> ,
Busy=> ,
Active=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
//ALL轴复位
AxisReset1(
Axis:= axis,
Execute:= AxisReset_do,
Done=> ,
Busy=> ,
Error=> ,
ErrorID=> );
AxisReset2(
Axis:= axis2,
Execute:= AxisReset_do,
Done=> ,
Busy=> ,
Error=> ,
ErrorID=> );
//设置当前位置
Axis1Setpos(
Axis:= Axis,
Execute:= Axis1Setpos_do ,
Position:=Axis1SetposWord ,
Mode:= ,
Options:= ,
Done=> ,
Busy=> ,
Error=> ,
ErrorID=> );
Axis2Setpos(
Axis:= Axis2,
Execute:= Axis2Setpos_do ,
Position:=Axis2SetposWord ,
Mode:= ,
Options:= ,
Done=> ,
Busy=> ,
Error=> ,
ErrorID=> );
//电子齿轮-两轴耦合
gearin(
Master:= axis,
Slave:= axis2,
Execute:=gearin_do ,
RatioNumerator:= 1,
RatioDenominator:= 1,
Acceleration:= ,
Deceleration:= ,
Jerk:= ,
BufferMode:= ,
Options:= ,
InGear=> ,
Busy=> ,
Active=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
//电子齿轮-两轴解耦合
gearout(
Slave:= axis2,
Execute:=gearout_do ,
Options:= ,
Done=> ,
Busy=> ,
Error=> ,
ErrorID=> );
//设置原点home位
Axis1Home(
Axis:= axis,
Execute:= Axis1Home_do,
Position:= 0,
HomingMode:= ,
BufferMode:= ,
Options:= ,
bCalibrationCam:= HomeSensor,
Done=> ,
Busy=> ,
Active=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
Axis2Home(
Axis:= axis2,
Execute:= Axis2Home_do,
Position:= 0,
HomingMode:= ,
BufferMode:= ,
Options:= ,
bCalibrationCam:=HomeSensor ,
Done=> ,
Busy=> ,
Active=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
//电子凸轮表
AxisCamIn(
Master:= axis,
Slave:= axis2,
Execute:= AxisCamIn_do,
MasterOffset:= ,
SlaveOffset:= ,
MasterScaling:= ,
SlaveScaling:= ,
StartMode:= ,
CamTableID:= 1,
BufferMode:= ,
Options:= ,
InSync=> ,
Busy=> ,
Active=> ,
CommandAborted=> ,
Error=> ,
ErrorID=> );
AxisCamout(
Slave:= axis2,
Execute:= AxisCamout_do,
Options:= ,
Done=> ,
Busy=> ,
Error=> ,
ErrorID=> );
在所有功能块中Execute均指向触发变量,都由触发变量来决定是否启用,这样就可以编写触摸屏程序达到目的
完,随便写了这样一篇,主要是为了存档记录,其中细节不做阐述,都可以在Beckhoff的infosys中可查,有误可在评论区指出