Example Program 10: MM_S10_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 leaves the picking area to obtain the next planned path, shortening the cycle time.

This example is very similar to the MM_S8_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_S10_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_S10_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_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
;---------------------------------------------------
   $OUT[2001]=FALSE
   ;initialize communication parameters (initialization is required only once)
   MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
   LOOP
      IF $OUT[2001]==TRUE THEN
         ;trigger Mech-Viz project
         MM_Start_Viz(2,init_jps_b)
         ;get planned path, 1st argument (1) means getting pose in JPs
         MM_Get_VizData(1,pos_num_b,vis_pos_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,pick_point_b[1],label_b[1],toolid_b[1])
            MM_Get_Jps(2,pick_point_b[2],label_b[2],toolid_b[2])
            MM_Get_Jps(3,pick_point_b[3],label_b[3],toolid_b[3])
         ENDIF
         $OUT[2001]=FALSE
      ENDIF
   ENDLOOP
END

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

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

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

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 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_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
;---------------------------------------------------
   ;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[2001]=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[2001]==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
      halt
   ENDIF
   ;save waypoints of the planned path to jps variables one by one
   Xpick_point1=pick_point_b[1]
   Xpick_point2=pick_point_b[2]
   Xpick_point3=pick_point_b[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]
   ;trigger Mech-Viz project and get planned path in advance
   TRIGGER WHEN DISTANCE = 1 DELAY = 0 DO $OUT[2001]=TRUE
   ;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]
   ;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.

sample10

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[2001]=TRUE

The above code indicates that the main program sets $OUT[2001] to TRUE. In this case, the sub program detects the value of $OUT[2001] 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[2001]==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[2001] changes from TRUE to FALSE).

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

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

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

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).

;trigger Mech-Viz project and get planned path in advance
TRIGGER WHEN DISTANCE = 1 DELAY = 0 DO $OUT[2001]=TRUE
  • TRIGGER WHEN DISTANCE …​ DELAY …​ DO …​: It can trigger a predefined command that executes synchronously with the robot’s motion and is closely related to the start or target point of the motion statement. The start point is pick_point3, and the target point is drop_waypoint.

  • DISTANCE: Specify the position for triggering the predefined command, with a value of 0 or 1.

    • 0: The command is triggered at the start point of the motion statement.

    • 1: The command is triggered at the target point of the motion statement. If the target point is in a trajectory approximation form, the instruction will be triggered at the midpoint of the approximated trajectory arc.

  • DELAY: Specify the delay time for triggering the command at the selected position. The value can be positive or negative, measured in milliseconds, and must be below 10,000,000 ms.

  • DO $OUT[2001]=TRUE: Specify the predefined command to be $OUT[2001]=TRUE, which means to trigger the Mech-Viz project to run and obtain the planned path.

The above code indicates that when the robot approaches the target point (drop_waypoint, the intermediate waypoint during placing), the robot calls $OUT[2001] = TRUE. This command means that the sub program triggers the Mech-Viz project to run again 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 triggers the sub program before the robot moves to the placing waypoint, while this example program triggers the sub program after the robot leaves the picking area.
   ;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]
   ;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

The above example indicates that the robot moves to the intermediate waypoint of placing (drop_waypoint) the approach waypoint of placing (drop_app), and then the placing waypoint (drop), performs placing (such as $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.