索性再给一个jog的fb吧,代码如下:
quote:
FUNCTION_BLOCK FB_JOG //***********FB 点动***********
VAR_INPUT
axisName: driveaxis; //要点动的轴
jogForward: BOOL; //正转点动
jogBackward: BOOL; //反转点动
speedsetpoint: LREAL; //点动速度
END_VAR
VAR
forwardRpulse: r_trig; //正转启动脉冲
forwardFpulse: f_trig; //正转停止脉冲
backRpulse: r_trig; //反转启动脉冲
backFpulse: f_trig; //反转停止脉冲
myRetDINT: DINT;
END_VAR
IF axisname.control=ACTIVE THEN //如果该轴控制已经使能,则检测各个动作的上升延
forwardRpulse(jogForward AND NOT jogBackward); //正转启动脉冲检测
forwardFpulse(jogForward AND NOT jogBackward);
backRpulse(jogBackward AND NOT jogForward);
backFpulse(jogBackward AND NOT jogForward);
END_IF;
IF forwardRpulse.q THEN //检测到正转启动脉冲
myRetDINT :=
_move( //_move()是系统函数,可以在帮助文件中找到相关资料
axis:= axisName, // 对应轴
direction:= POSITIVE, // 运动方向为正
velocitytype:= DIRECT, // 速度给定方式为直接得出
velocity:= speedsetpoint, //运动速度值
// movetimeouttype:=WITHOUT_TIME_LIMIT,
// movetimeout:=0.0,
positiveacceltype:=DIRECT, //正向加速度给定方式为直接得出
positiveaccel:=100.0, //正向加速度为 100.0 m/s2
negativeacceltype:=DIRECT, //反向加速度给定方式为直接得出
negativeaccel:=100.0 //反向加速度为 100.0 m/s2
// positiveaccelstartjerktype:=USER_DEFAULT,
// positiveaccelstartjerk:=100.0,
// positiveaccelendjerktype:=USER_DEFAULT,
// positiveaccelendjerk:=100.0,
// negativeaccelstartjerktype:=USER_DEFAULT,
// negativeaccelstartjerk:=100.0,
// negativeaccelendjerktype:=USER_DEFAULT,
// negativeaccelendjerk:=100.0,
// velocityprofile:=USER_DEFAULT,
// mergemode:=SEQUENTIAL,
// nextcommand:=IMMEDIATELY,
// commandid:=(0,0),
// movingmode:=POSITION_CONTROLLED
);
END_IF;
IF backRpulse.q THEN //检测到正转停止脉冲
myRetDINT :=
_move(
axis:= axisName,
direction:= NEGATIVE,
velocitytype:= DIRECT,
velocity:= speedsetpoint,
// movetimeouttype:=WITHOUT_TIME_LIMIT,
// movetimeout:=0.0,
positiveacceltype:=DIRECT,
positiveaccel:=100.0,
negativeacceltype:=DIRECT,
negativeaccel:=100.0
// positiveaccelstartjerktype:=USER_DEFAULT,
// positiveaccelstartjerk:=100.0,
// positiveaccelendjerktype:=USER_DEFAULT,
// positiveaccelendjerk:=100.0,
// negativeaccelstartjerktype:=USER_DEFAULT,
// negativeaccelstartjerk:=100.0,
// negativeaccelendjerktype:=USER_DEFAULT,
// negativeaccelendjerk:=100.0,
// velocityprofile:=USER_DEFAULT,
// mergemode:=SEQUENTIAL,
// nextcommand:=IMMEDIATELY,
// commandid:=(0,0),
// movingmode:=POSITION_CONTROLLED
);
END_IF;
IF forwardFpulse.q OR backFpulse.q THEN //检测到正向或者反向点动停止脉冲
myRetDINT :=
_stop( //_stop() 系统函数, 在帮助中可以得到相关参数信息
axis:= axisName, // 要停止的轴
// stopmode:=STOP_WITHOUT_ABORT,
// stopspecification:=ALL_AXIS_MOTION,
// stopid:=(0,0),
positiveacceltype:=DIRECT,
positiveaccel:=100.0,
negativeacceltype:=DIRECT,
negativeaccel:=100.0
// positiveaccelstartjerktype:=USER_DEFAULT,
// positiveaccelstartjerk:=100.0,
// positiveaccelendjerktype:=USER_DEFAULT,
// positiveaccelendjerk:=100.0,
// negativeaccelstartjerktype:=USER_DEFAULT,
// negativeaccelstartjerk:=100.0,
// negativeaccelendjerktype:=USER_DEFAULT,
// negativeaccelendjerk:=100.0,
// velocityprofile:=USER_DEFAULT,
// mergemode:=IMMEDIATELY,
// nextcommand:=IMMEDIATELY,
// commandid:=(0,0),
// movingmode:=CURRENT_MODE
);
END_IF;
END_FUNCTION_BLOCK
因为没法贴图,解释下引脚功能:
这个FB在调用时有4个引脚
axisname ----需要jog的轴名称
jogforward ----正向jog
jogbackward----反向jog
speedsetpiont---jog速度