Example Program 8: MM_S8_Viz_Subtask

You are currently viewing the documentation for the latest version (2.1.0). To access a different version, click the "Switch version" button located in the upper-right corner of the page.

■ If you are not sure which version of the product you are currently using, please feel free to contact Mech-Mind Technical Support.

Program Introduction

Description

This example program consists of two programs: a main program and a sub program. The sub program (background program) triggers the Mech-Viz project to run to obtain the planned path. The main program (the foreground program) moves the robot based on the planned path. Then, the main program triggers the sub 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 main program to trigger the sub program is different. It is recommended that you compare the two examples to better understand their nuances.

File path

Sub 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/KUKA/sample/sub_prog/MM_S8_Sub path.

Main 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/KUKA/sample/MM_S8_Viz_Subtask path.

Project

Mech-Vision and Mech-Viz projects

Prerequisites

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

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

Program Description

The following part describes the sub program.

Similar to the MM_S2_Viz_Basic example program, the sub program triggers the Mech-Viz project to run and obtains the planned path code. As such, the features of the sub 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.
DEF 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
;---------------------------------------------------
   $OUT[2000]=FALSE
   ;initialize communication parameters (initialization is required only once)
   MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
   LOOP
      IF $OUT[2000]==TRUE THEN
         ;trigger Mech-Viz project
         MM_Start_Viz(2,init_jps_a)
         ;get planned path, 1st argument (1) means getting pose in JPs
         MM_Get_VizData(1,pos_num_a,vis_pos_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,pick_point_a[1],label_a[1],toolid_a[1])
            MM_Get_Jps(2,pick_point_a[2],label_a[2],toolid_a[2])
            MM_Get_Jps(3,pick_point_a[3],label_a[3],toolid_a[3])
         ENDIF
         $OUT[2000]=FALSE
      ENDIF
   ENDLOOP
END

The above code shows that the sub program sets $OUT[2000] to FALSE, initializes the communication parameters, and then continuously listens to the value of $OUT[2000] through a loop.

  • When $OUT[2000] is set to TRUE, the sub program triggers the Mech-Viz project to run, obtains the planned path, and then sets $OUT[2000] to FALSE.

  • When $OUT[2000] is set to FALSE, the sub program continuously listens to the value of $OUT[2000].

The following part describes the main program.

Similar to the MM_S2_Viz_Basic example program, the main program performs picking and placing based on the planned path code. As such, the features of the main 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.
DEF  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
;---------------------------------------------------
   ;set current tool no. to 1
   BAS(#TOOL,1)
   ;set current base no. to 0
   BAS(#BASE,0)
   ;move to robot home position
PTP HOME Vel=100 % DEFAULT
   ;trigger Mech-Viz project and get planned path
   $OUT[2000]=TRUE
LOOP
   ;move to wait position for picking
LIN pick_wait_point Vel=1 m/s CPDAT6 Tool[1] Base[0]
   ;wait until subtask program finished
   Wait for ($OUT[2000]==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
      halt
   ENDIF
   ;save waypoints of the planned path to jps variables one by one
   Xpick_point1=pick_point_a[1]
   Xpick_point2=pick_point_a[2]
   Xpick_point3=pick_point_a[3]
   ;follow the planned path to pick
   ;move to approach waypoint of picking
PTP pick_point1 Vel=50 % PDAT1 Tool[1] Base[0]
   ;move to picking waypoint
PTP pick_point2 Vel=10 % PDAT2 Tool[1] Base[0]
   ;add object grasping logic here, such as "$OUT[1]=TRUE"
   halt
   ;move to departure waypoint of picking
PTP pick_point3 Vel=50 % PDAT3 Tool[1] Base[0]
   ;move to intermediate waypoint of placing
PTP drop_waypoint CONT Vel=100 % PDAT2 Tool[1] Base[0]
   ;move to approach waypoint of placing
LIN drop_app Vel=1 m/s CPDAT3 Tool[1] Base[0]
   ;trigger Mech-Viz project and get planned path in advance
   $OUT_C[2000]=TRUE
   ;move to placing waypoint
LIN drop Vel=0.3 m/s CPDAT4 Tool[1] Base[0]
   ;add object releasing logic here, such as "$OUT[1]=FALSE"
   halt
   ;move to departure waypoint of placing
LIN drop_app Vel=1 m/s CPDAT3 Tool[1] Base[0]
   ;move back to robot home position
PTP HOME Vel=100 % DEFAULT
ENDLOOP
END

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 main program.

Workflow Code and description

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

;trigger Mech-Viz project and get planned path
$OUT[2000]=TRUE

The above code indicates that the main program sets $OUT[2000] to TRUE. In this case, the sub program detects the value of $OUT[2000] to be TRUE. Then, the sub program triggers the Mech-Viz project to run and obtains the planned path.

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

LOOP
    ...
ENDLOOP

The above code indicates that the main program loops through the code between LOOP and ENDLOOP.

   ;move to wait position for picking
LIN pick_wait_point Vel=1 m/s CPDAT6 Tool[1] Base[0]
   ;wait until subtask program finished
   Wait for ($OUT[2000]==FALSE)

In the above example, the robot moves to a waiting waypoint before picking and waits for the sub program to obtain and store the planned path (i.e., $OUT[2000] changes from TRUE to FALSE).

;save waypoints of the planned path to jps variables one by one
Xpick_point1=pick_point_a[1]
Xpick_point2=pick_point_a[2]
Xpick_point3=pick_point_a[3]

In the above example, the planned path (pick_point_a[1], pick_point_a[2], and pick_point_a[3]) obtained by the sub program will be stored in Xpick_point1, Xpick_point2, and Xpick_point3.

   ;follow the planned path to pick
   ;move to approach waypoint of picking
PTP pick_point1 Vel=50 % PDAT1 Tool[1] Base[0]
   ;move to picking waypoint
PTP pick_point2 Vel=10 % PDAT2 Tool[1] Base[0]
   ;add object grasping logic here, such as "$OUT[1]=TRUE"
   halt
   ;move to departure waypoint of picking
PTP pick_point3 Vel=50 % PDAT3 Tool[1] Base[0]
   ;move to intermediate waypoint of placing
PTP drop_waypoint CONT Vel=100 % PDAT2 Tool[1] Base[0]
   ;move to approach waypoint of placing
LIN drop_app Vel=1 m/s CPDAT3 Tool[1] Base[0]

In the above example, the robot moves along the planned path to the approach waypoint of picking (pick_point1) and then to the picking waypoint (pick_point2), performs picking (for example, $OUT[1]=TRUE), and then moves to the departure waypoint of picking (pick_point3), the intermediate waypoint of placing (drop_waypoint), and then the approach waypoint of placing (drop_app).

;trigger Mech-Viz project and get planned path in advance
$OUT_C[2000]=TRUE

The above code indicates that the main program sets $OUT_C[2000] to TRUE again to trigger the Mech-Viz project to run again 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
LIN drop Vel=0.3 m/s CPDAT4 Tool[1] Base[0]
   ;add object releasing logic here, such as "$OUT[1]=FALSE"
   halt
   ;move to departure waypoint of placing
LIN drop_app Vel=1 m/s CPDAT3 Tool[1] Base[0]
   ;move back to robot home position
PTP HOME Vel=100 % DEFAULT

In the above example, the robot moves to the placing waypoint (drop), performs placing (for example, $OUT[1]=FALSE), and then moves to the departure waypoint of placing (drop_app) 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.