样例程序10:MM_S10_Viz_Subtask

您正在查看最新版本(V2.1.0)的文档。如果您想查阅其他版本的文档,可以点击页面右上角“切换版本”按钮进行切换。

■ 如果您不确定当前使用的产品是哪个版本,请随时联系梅卡曼德技术支持。

程序简介

功能说明

本样例由两个程序组成,其中子任务负责触发Mech-Viz工程运行并获取规划路径;主任务负责根据规划路径移动机器人,且在机器人离开抓取区域时触发子任务运行,从而提前规划下一轮路径,以缩短节拍。

本样例与MM_S8_Viz_Subtask样例十分相似,仅是主任务触发子任务的时机不同,因此,建议用户对比学习这两个样例,以更好地理解它们之间的细微差别。

文件路径

子任务:Mech-Vision和Mech-Viz软件安装目录下Communication Component/Robot_Interface/ABB/sample/sub_prog/MM_S10_Sub

主任务:Mech-Vision和Mech-Viz软件安装目录下Communication Component/Robot_Interface/ABB/sample/MM_S10_Viz_Subtask

对于RobotWare6系统,文件后缀为.mod。对于RobotWare7系统,用户需将.mod修改为.modx

所需工程

Mech-Vision工程和Mech-Viz工程

使用前提

  1. 已完成标准接口通信配置。

  2. 已完成自动标定。

  • 此样例程序仅是示例程序。用户需根据实际情况在此基础上进行修改,请勿直接使用该程序。

  • 主任务属于前台程序。子任务属于后台程序,需要在机器人系统开机后自动运行。

程序解读

以下为子任务的代码及相关解释说明。

在子任务中,触发Mech-Viz工程运行并获取规划路径的代码,与MM_S2_Viz_Basic样例中类似。因此,下文不再重复解释与MM_S2_Viz_Basic样例相同部分的代码(详情请参考MM_S2_Viz_Basic样例说明)。
MODULE MM_S10_Sub
!----------------------------------------------------------
! FUNCTION: run Mech-Viz project and get planned path
! in subtask(run together with MM_S10_Viz_Subtask)
! Mech-Mind, 2023-12-25
!----------------------------------------------------------
!define variables
PERS num pose_num_b:=5;
PERS num vis_pose_num_b:=3;
PERS num toolid_b{5}:=[0,0,0,0,0];
PERS num label_b{5}:=[0,0,0,0,0];
PERS num status_b:=2100;
PERS bool flag_vis_b:=FALSE;
CONST jointtarget snap_jps_b:=[[0,0,0,0,90,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
PERS jointtarget jps_b{5}:=
[
    [[0,0,0,0,90,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,90,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,90,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[11.1329,49.0771,-36.9666,0.5343,79.2476,-169.477],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,90,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]]
];

PROC main()
    flag_vis_b:=FALSE;
    !initialize communication parameters (initialization is required only once)
    MM_Init_Socket "127.0.0.1",50000,300;
    WHILE TRUE DO
        IF flag_vis_b=TRUE THEN
            MM_Open_Socket;
            !trigger Mech-Viz project
            MM_Start_Viz 2,snap_jps_b;
            !get planned path, 1st argument (1) means getting pose in JPs
            MM_Get_VizData 1, pose_num_b, vis_pose_num_b, status_b;
            !check whether planned path has been got from Mech-Viz successfully
            IF status_b=2100 THEN
                !save waypoints of the planned path to local variables one by one
                MM_Get_Jps 1,jps_b{1},label_b{1},toolid_b{1};
                MM_Get_JPS 2,jps_b{2},label_b{2},toolid_b{2};
                MM_Get_JPS 3,jps_b{3},label_b{3},toolid_b{3};
            ENDIF
            MM_Close_Socket;
            flag_vis_b:=FALSE;
        ENDIF
    ENDWHILE
ENDPROC
ENDMODULE

上述代码表示,子任务在运行时,首先将flag_vis_b设置为FALSE,并初始化通信参数,然后通过WHILE循环持续监听flag_vis_b值。

  • 当flag_vis_b为TRUE时,子任务发触发Mech-Viz工程运行并获取规划路径,然后将flag_vis_b设置为FALSE。

  • 当flag_vis_b为FALSE时,子任务持续判断flag_vis_b的值。

以下为主任务的代码及相关解释说明。

在主任务中,根据规划路径进行抓取与放置的代码,与MM_S2_Viz_Basic样例中类似。因此,下文不再重复解释与MM_S2_Viz_Basic样例相同部分的代码(详情请参考MM_S2_Viz_Basic样例说明)。
MODULE MM_S10_Viz_Subtask
!----------------------------------------------------------
! FUNCTION: run Mech-Viz project and get planned path
! in subtask (run together with MM_S10_Sub)
! Mech-Mind, 2023-12-25
!----------------------------------------------------------
!define local num variables
PERS bool flag_vis_b:=FALSE;
PERS num status_b:=2100;
PERS num pose_num_b:=5;
PERS num toolid_b{5}:=[0,0,0,0,0];
PERS num label_b{5}:=[0,0,0,0,0];
PERS num vis_pose_num_b:=3;
LOCAL VAR num count:=0;
!define local joint&pose variables
LOCAL CONST jointtarget home:=[[0,0,0,0,90,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
LOCAL PERS robtarget pick_wait_point:=[[302.00,0.00,558.00],[0,0,-1,0],[0,0,0,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
LOCAL PERS robtarget drop_waypoint:=[[302.00,0.00,558.00],[0,0,-1,0],[0,0,0,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
LOCAL PERS robtarget drop:=[[302.00,0.00,558.00],[0,0,-1,0],[0,0,0,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
PERS jointtarget jps_b{5}:=
[
    [[0,0,0,0,0,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,0,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,0,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,0,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,0,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]]
];
!define local tooldata variables
LOCAL PERS tooldata gripper1:=[TRUE,[[0,0,0],[1,0,0,0]],[0.001,[0,0,0.001],[1,0,0,0],0,0,0]];

PROC Sample_10()
    !set the acceleration parameters
    AccSet 50, 50;
    !set the velocity parameters
    VelSet 50, 1000;
    !move to robot home position
    MoveAbsJ home\NoEOffs,v3000,fine,gripper1;
    !trigger Mech-Viz project and get planned path
    trigger_vis_b;
LOOP:
    !move to wait position for picking
    MoveL pick_wait_point,v1000,fine,gripper1;
    !wait until subtask program finished
    WaitUntil(flag_vis_b=FALSE);
    !check whether planned path has been got from Mech-Viz successfully
    IF status_b <> 2100 THEN
        !add error handling logic here according to different error codes
        !e.g.: status=2038 means no point cloud in ROI
        Stop;
    ENDIF
    !follow the planned path to pick
    !move to approach waypoint of picking
    MoveAbsJ jps_b{1},v1000,fine,gripper1;
    !move to picking waypoint
    MoveAbsJ jps_b{2},v300,fine,gripper1;
    !add object grasping logic here, such as "setdo DO_1, 1;"
    Stop;
    !move to departure waypoint of picking
    MoveAbsJ jps_b{3},v1000,fine,gripper1;
    !move to intermediate waypoint of placing, and trigger Mech-Viz project and get planned path in advance
    MoveJSync drop_waypoint,v1000,z50,gripper1,"trigger_vis_b";
    !move to approach waypoint of placing
    MoveL RelTool(drop,0,0,-100),v1000,fine,gripper1;
    !move to placing waypoint
    MoveL drop,v300,fine,gripper1;
    !add object releasing logic here, such as "setdo DO_1, 0;"
    Stop;
    !move to departure waypoint of placing
    MoveL RelTool(drop,0,0,-100),v1000,fine,gripper1;
    !move back to robot home position
    MoveAbsJ home\NoEOffs,v3000,fine,gripper1;
    GOTO LOOP;
ENDPROC
PROC trigger_vis_b()
    flag_vis_b:=TRUE;
ENDPROC
ENDMODULE

上述样例程序代码对应的流程如下图所示。

sample10

下表为主任务核心代码的逻辑解读。

流程 代码及说明

触发Mech-Viz工程运行并获取规划路径

!trigger Mech-Viz project and get planned path
trigger_vis_a;

上述代码表示,主任务调用trigger_vis_b()函数。该函数的代码如下所示。

PROC trigger_vis_b()
    flag_vis_b:=TRUE;

上述代码表示,在trigger_vis_b()函数中将flag_vis_b设置为TRUE,此时子任务检测到flag_vis_b为TRUE,便触发Mech-Viz工程运行并获取规划路径。

通过循环(抓取→触发下一轮规划→放置)提前规划下一轮路径

LOOP:
    ...
    GOTO LOOP;

上述代码表示,主任务循环执行LOOP与GOTO LOOP之间的代码。

!move to wait position for picking
MoveL pick_wait_point,v1000,fine,gripper1;
!wait until subtask program finished
WaitUntil(flag_vis_b=FALSE);

上述代码表示,机器人移动到抓取前的一个等待点,等待子任务运行完毕(即flag_vis_b从TRUE变为FALSE),从而确保已获取并转存规划路径。

!move to approach waypoint of picking
MoveAbsJ jps_b{1},v1000,fine,gripper1;
!move to picking waypoint
MoveAbsJ jps_b{2},v300,fine,gripper1;
!add object grasping logic here, such as "setdo DO_1, 1;"
Stop;
!move to departure waypoint of picking
MoveAbsJ jps_b{3},v1000,fine,gripper1;

上述代码表示,机器人根据规划的路径先移动到抓取接近点(jps_b{1}),然后移动到抓取点(jps_b{2}),进行抓取(例如,setdo DO_1, 1;),再移动到抓取离开点(jps_b{3})。

!move to intermediate waypoint of placing, and trigger Mech-Viz project and get planned path in advance
MoveJSync drop_waypoint,v1000,z50,gripper1,"trigger_vis_b";

上述代码表示,机器人以最快捷的方式运动至目标点(drop_waypoint,即放置过程中的过渡点),并且在目标点调用trigger_vis_b()函数。主任务程序再次调用trigger_vis_b()函数,即再次触发Mech-Viz工程运行并获取规划路径。此处机器人已处于抓取区域外,因此机器人此时可以提前规划下一轮抓取路径,而不必等待放置完成后再规划下一轮抓取路径。

此处需注意本样例与MM_S8_Viz_Subtask样例的区别,MM_S8_Viz_Subtask样例是在机器人移动至放置点前调用函数,而本样例是在机器人离开抓取区域后调用函数。
!move to approach waypoint of placing
MoveL RelTool(drop,0,0,-100),v1000,fine,gripper1;
!move to placing waypoint
MoveL drop,v300,fine,gripper1;
!add object releasing logic here, such as "setdo DO_1, 0;"
Stop;
!move to departure waypoint of placing
MoveL RelTool(drop,0,0,-100),v1000,fine,gripper1;
!move back to robot home position
MoveAbsJ home\NoEOffs,v3000,fine,gripper1;

上述代码表示,机器人先依次移动到放置接近点(RelTool(drop,0,0,-100))、放置点(drop),然后进行放置操作(例如,setdo DO_1, 0;),然后依次移动到放置离开点(RelTool(drop,0,0,-100))、Home点。

我们重视您的隐私

我们使用 cookie 为您在我们的网站上提供最佳体验。继续使用该网站即表示您同意使用 cookie。如果您拒绝,将使用一个单独的 cookie 来确保您在访问本网站时不会被跟踪或记住。