01
什么是多任务
一台机械臂,可以有前后台程序,其中前台用于处理机器人运动相关,后台处于处于非动作相关的,比如实时监控数据、通信等;
02
如何配置后台任务
前提条件:需要配置选项623-1 MultiTasking 首先在新建TASK中选择Type类型为Normal
然后进行后台任务编程
MODULE MainModule
PERS bool bIs_Home;
PROC main()
WHILE TRUE DO
bIs_Home:=CurrentPosionIsAtHome();
IF bIs_Home THEN
Set do1;
ELSE
Reset do1;
ENDIF
WaitTime 0.001;
ENDWHILE
ENDPROC
FUNC bool CurrentPosionIsAtHome()
VAR jointtarget curJoint;
CONST jointtarget jHome:=[[0,0,0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]];
VAR num count:=0;
curJoint:=CJointT();
IF abs(curJoint.robax.rax_1 - jHome.robax.rax_1)<=5 count:=count+1;
IF abs(curJoint.robax.rax_2 - jHome.robax.rax_2)<=5 count:=count+1;
IF abs(curJoint.robax.rax_3 - jHome.robax.rax_3)<=5 count:=count+1;
IF abs(curJoint.robax.rax_4 - jHome.robax.rax_4)<=5 count:=count+1;
IF abs(curJoint.robax.rax_5 - jHome.robax.rax_5)<=5 count:=count+1;
IF abs(curJoint.robax.rax_6 - jHome.robax.rax_6)<=5 count:=count+1;
RETURN count=6;
ENDFUNC
ENDMODULE
程序编辑完成后,需要将Type切换成“Semistatic”
03
前后台程序如何进行交互
前台程序和后台程序通过程序数据进行交互,该数据需要在双方任务的模块下进行定义,比如此处的PERS bool bIs_Home
前台任务程序参考
MODULE Module1
PERS bool bIs_Home;
CONST jointtarget jPos1:=[[0,0,0,0,0,0],[9e9,9e9,9e9,9e9,9e9,9e9]];
CONST jointtarget jPos2:=[[90,0,0,0,90,0],[9e9,9e9,9e9,9e9,9e9,9e9]];
PROC main()
WHILE TRUE DO
MoveAbsJ jPos1,v1000,fine,tool0;
WaitTime 0.01;
TPWrite "Current Position is at Home:"\Bool:=bIs_Home;
MoveAbsJ jPos2,v1000,z0,tool0;
TPWrite "Current Position is at Home:"\Bool:=bIs_Home;
WaitTime 0.01;
ENDWHILE
ENDPROC
ENDMODULE
结果展示