Example Program 10: MM_S10_Viz_Subtask

Program Introduction

Description

This example program consists of two programs. The secondary program triggers the Mech-Viz project to run to obtain the planned path. The primary program moves the robot based on the planned path. Then, the primary program triggers the secondary program to run when the robot leaves the picking area to obtain the next planned path, shortening the cycle time.

This example program is very similar to the MM_S8_Viz_Subtask example program, except that the timing of the primary program to trigger the secondary program is different. It is recommended that you compare the two examples to better understand their nuances.

File path

Secondary program: You can navigate to the installation directory of Mech-Vision and Mech-Viz and find the file by using the Communication Component/Robot_Interface/ABB/sample/sub_prog/MM_S10_Sub path.

Primary program:You can navigate to the installation directory of Mech-Vision and Mech-Viz and find the file by using the Communication Component/Robot_Interface/ABB/sample/MM_S10_Viz_Subtask path.

For RobotWare6, the file extension is .mod. For RobotWare7, please modify the file extension from .mod to .modx.

Project

Mech-Vision and Mech-Viz projects

Prerequisites

  1. You have set up the standard interface communication.

  2. Automatic calibration is completed.

  • This example program is provided for reference only. Before using the program, please modify the program according to the actual scenario.

  • The primary program is a foreground program. The secondary program is a background program that needs to be automatically run after the robot system starts.

Program Description

The following part describes the secondary program.

Similar to the MM_S2_Viz_Basic example program, the secondary program triggers the Mech-Viz project to run and obtains the planned path. As such, the features of the secondary program that are similar to those of MM_S2_Viz_Basic are not described in this part. For more information about these features, see Example Program 2: 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

The above code shows that the secondary program sets flag_vis_b to FALSE, initializes the communication parameters, and then continuously listens to the value of flag_vis_b through the WHITE loop.

  • When flag_vis_b is set to TRUE, the secondary program triggers the Mech-Viz project to run, obtains the planned path, and then sets flag_vis_b to FALSE.

  • When flag_vis_b is set to FALSE, the secondary program continuously listens to the value of flag_vis_b.

The following part describes the primary program.

Similar to the MM_S2_Viz_Basic example program, the primary program performs picking and placing based on the planned path. As such, the features of the primary program that are similar to those of MM_S2_Viz_Basic are not described in this part. For more information about these features, see Example Program 2: 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

The workflow corresponding to the above example program code is shown in the figure below.

sample10

The table below illustrates the core code of the primary program.

Feature Code and description

Trigger the Mech-Viz project to run and obtain the planned path

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

In the above example, the primary program calls the trigger_vis_b() function. The code for this function is shown below.

PROC trigger_vis_b()
    flag_vis_b:=TRUE;

In the above example, when flag_vis_b is set to TRUE in the trigger_vis_b() function, the secondary program will detect the TRUE value, trigger the Mech-Viz project to run, and then obtain the planned path.

Plan the next path in advance by looping (picking→triggering the next round of path planning→placing)

LOOP:
    ...
    GOTO LOOP;

The above code indicates that the primary program loops through the code between LOOP and 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);

In the above example, the robot moves to a waiting waypoint before picking and waits for the secondary program to finish running (i.e., flag_vis_b changes from TRUE to FALSE), thus ensuring that the planned path has been obtained and stored.

!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;

In the above example, the robot moves along the planned path to the approach waypoint of picking (jps_b{1}) and then to the picking waypoint (jps_b{2}), performs picking (for example, setdo DO_1, 1;), and then moves to the departure waypoint of picking (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";

In the above code, the robot moves to the target position (drop_waypoint, i.e., the intermediate waypoint during placing) and calls the trigger_vis_b() function at the target position. The primary program calls the trigger_vis_b() function again to trigger the Mech-Viz project to run and obtain the planned path. Now that the robot resides outside the area for placing, the robot can plan the next picking path in advance without waiting for the placing to complete and then planning the next picking path.

Please note the difference between this example program and the MM_S8_Viz_Subtask example program. The MM_S8_Viz_Subtask example program calls the function before the robot moves to the placing waypoint, while this example program calls the function after the robot leaves the picking area.
!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;

The above example indicates that the robot moves to the approach waypoint of placing (RelTool(drop,0,0,-100)) and then to the placing waypoint (drop), performs placing (such as setdo DO_1, 0;), and then moves to the departure waypoint of placing (RelTool(drop,0,0,-100)) and then to the home position.

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.