Example Program 8: MM_S8_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 performs placing to obtain the next planned path, shortening the cycle time.

This example is very similar to the MM_S10_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_S8_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_S8_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_S8_Sub
!----------------------------------------------------------
! FUNCTION: run Mech-Viz project and get planned path
! in subtask (run together with MM_S8_Viz_Subtask)
! Mech-Mind, 2023-12-25
!----------------------------------------------------------
!define variables
PERS num pose_num_a:=5;
PERS num vis_pose_num_a:=3;
PERS num toolid_a{5}:=[0,0,0,0,0];
PERS num label_a{5}:=[0,0,0,0,0];
PERS num status_a:=2100;
PERS bool flag_vis_a:=FALSE;
CONST jointtarget snap_jps_a:=[[0,0,0,0,90,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
PERS jointtarget jps_a{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_a:=FALSE;
    !initialize communication parameters (initialization is required only once)
    MM_Init_Socket "127.0.0.1",50000,300;
    WHILE TRUE DO
        IF flag_vis_a=TRUE THEN
            MM_Open_Socket;
            !trigger Mech-Viz project
            MM_Start_Viz 2,snap_jps_a;
            !get planned path, 1st argument (1) means getting pose in JPs
            MM_Get_VizData 1, pose_num_a, vis_pose_num_a, status_a;
            !check whether planned path has been got from Mech-Viz successfully
            IF status_a=2100 THEN
                !save waypoints of the planned path to local variables one by one
                MM_Get_Jps 1,jps_a{1},label_a{1},toolid_a{1};
                MM_Get_JPS 2,jps_a{2},label_a{2},toolid_a{2};
                MM_Get_JPS 3,jps_a{3},label_a{3},toolid_a{3};
            ENDIF
            MM_Close_Socket;
            flag_vis_a:=FALSE;
        ENDIF
    ENDWHILE
ENDPROC
ENDMODULE

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

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

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

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_S8_Viz_Subtask
!----------------------------------------------------------
! FUNCTION: run Mech-Viz project and get planned path
! in subtask (run together with MM_S8_Sub)
! Mech-Mind, 2023-12-25
!----------------------------------------------------------
!define local num variables
PERS bool flag_vis_a:=FALSE;
PERS num status_a:=2100;
PERS num pose_num_a:=5;
PERS num toolid_a{5}:=[0,0,0,0,0];
PERS num label_a{5}:=[0,0,0,0,0];
PERS num vis_pose_num_a:=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_a{5}:=
[
    [[0,0,0,0,89,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,89,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
    [[0,0,0,0,89,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]]
];
!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_8()
    !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_a;
LOOP:
    !move to wait position for picking
    MoveL pick_wait_point,v1000,fine,gripper1;
    !wait until subtask program finished
    WaitUntil(flag_vis_a=FALSE);
    !check whether planned path has been got from Mech-Viz successfully
    IF status_a <> 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_a{1},v1000,fine,gripper1;
    !move to picking waypoint
    MoveAbsJ jps_a{2},v300,fine,gripper1;
    !add object grasping logic here, such as "setdo DO_1, 1;"
    Stop;
    !move to departure waypoint of picking
    MoveAbsJ jps_a{3},v1000,fine,gripper1;
    !move to intermediate waypoint of placing
    MoveJ drop_waypoint,v1000,z50,gripper1;
    !move to approach waypoint of placing
    MoveL RelTool(drop,0,0,-100),v1000,fine,gripper1;
    !trigger Mech-Viz project and get planned path in advance
    trigger_vis_a;
    !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_a()
    flag_vis_a:=TRUE;
ENDPROC
ENDMODULE

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

sample8

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_a() function. The code for this function is shown below.

PROC trigger_vis_a()
    flag_vis_a:=TRUE;

In the above example, when flag_vis_a is set to TRUE in the trigger_vis_a() 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_a=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_a changes from TRUE to FALSE), thus ensuring that the planned path has been obtained and stored.

!follow the planned path to pick
!move to approach waypoint of picking
MoveAbsJ jps_a{1},v1000,fine,gripper1;
!move to picking waypoint
MoveAbsJ jps_a{2},v300,fine,gripper1;
!add object grasping logic here, such as "setdo DO_1, 1;"
Stop;
!move to departure waypoint of picking
MoveAbsJ jps_a{3},v1000,fine,gripper1;
!move to intermediate waypoint of placing
MoveJ drop_waypoint,v1000,z50,gripper1;
!move to approach waypoint of placing
MoveL RelTool(drop,0,0,-100),v1000,fine,gripper1;

In the above example, the robot moves along the planned path to the approach waypoint of picking (jps_a{1}) and then to the picking waypoint (jps_a{2}), performs picking (for example, setdo DO_1, 1;), and then moves to the departure waypoint of picking (jps_a{3}), the intermediate waypoint of placing (drop_waypoint), and then the approach waypoint of placing (RelTool(drop,0,0,-100)).

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

In the above example, the primary program calls the trigger_vis_a() function again to trigger the Mech-Viz project to run and obtain the planned path. Now that the robot resides in 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.

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

In the above example, the robot moves to the placing waypoint (drop), performs placing (for example, setdo DO_1, 0;), and then moves to the departure waypoint of placing (RelTool(drop,0,0,-100)) and then 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.