Example program 2: MM_S2_Viz_Basic

Program Introduction

Description

The robot triggers the Mech-Viz project to run, and then obtains the planned path for picking and placing.

File path

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

Program Description

This part describes the MM_S2_Viz_Basic example program.

DEF MM_S2_Viz_Basic ( )
;---------------------------------------------------
; FUNCTION: trigger Mech-Viz project and get
; planned path
; 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
   ;initialize communication parameters (initialization is required only once)
   MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
   ;move to image-capturing position
LIN camera_capture Vel=1 m/s CPDAT1 Tool[1] Base[0]
   ;trigger Mech-Viz project
   MM_Start_Viz(2,init_jps)
   ;get planned path, 1st argument (1) means getting pose in JPs
   MM_Get_VizData(1,pos_num,vis_pos_num,status)
   ;check whether planned path has been got from Mech-Viz successfully
   IF status<> 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 local variables one by one
   MM_Get_Jps(1,Xpick_point1,label[1],toolid[1])
   MM_Get_Jps(2,Xpick_point2,label[2],toolid[2])
   MM_Get_Jps(3,Xpick_point3,label[3],toolid[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]
   ;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
END

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

sample2

The table below explains the above program. You can click the hyperlink to the command name to view its detailed description.

Feature Code and description

Set the reference frame

   ;set current tool no. to 1
   BAS(#TOOL,1)
   ;set current base no. to 0
   BAS(#BASE,0)
  • BAS(#TOOL,1): Set the current tool reference frame to 1.

  • BAS(#BASE,0): Set the current base reference frame to 0.

The above two statements set the current tool and base reference frames.

Move to the home position

   ;move to robot home position
PTP HOME Vel=100 % DEFAULT
  • PTP: The point-to-point mode. In this mode, the robot moves its TCP along the quickest path to the target point.

  • HOME: The name of the target point (home position).

    You should teach the home position in advance. For detailed instructions, see Teach Calibration Start Point in the calibration document.

  • Vel=100 %: The velocity.

  • DEFAULT: The system-assigned name for a motion data set.

The above statement specifies to move the robot in PTP mode to the taught home position.

Initialize communication parameters

   ;initialize communication parameters (initialization is required only once)
   MM_Init_Socket("XML_Kuka_MMIND",873,871,60)

The MM_Init_Socket command establishes the TCP communication between the robot and the vision system based on the configurations in the XML_Kuka_MMIND.xml file.

For more information about the XML_Kuka_MMIND file, see MM_Init_Socket.

Move to the image-capturing position

   ;move to image-capturing position
LIN camera_capture Vel=1 m/s CPDAT1 Tool[1] Base[0] 
  • LIN: The linear motion mode.

  • camera_capture: The target point name, which is the image-capturing position.

    You should teach the image-capturing position in advance. For detailed instructions, see Teach Calibration Start Point in the calibration document.
  • Vel=1 m/s: The velocity.

  • CPDAT1: The system-assigned name for a motion data set.

  • Tool[1]: The tool reference frame 1.

  • Base[0]: The base reference frame 0.

The above statement specifies to move the robot linearly to the taught image-capturing position.

Trigger the Mech-Viz project to run

   ;trigger Mech-Viz project
   MM_Start_Viz(2,init_jps)
  • MM_Start_Viz: The command to trigger the Mech-Viz project to run.

  • 2: Send the joint positions represented by the init_jps variable to the Mech-Viz project.

  • init_jps: stores custom joint positions. When the picking path is planned, the simulated robot in the Mech-Viz project will move from the joint positions to the first waypoint.

The entire command indicates that the robot triggers the vision system to run the Mech-Viz project, and then Mech-Viz plans the robot’s picking path base on the vision result output by Mech-Vision.

Get the planned path

   ;get planned path, 1st argument (1) means getting pose in JPs
   MM_Get_VizData(1,pos_num,vis_pos_num,status)
  • MM_Get_VizData: The command to obtain the path planned by Mech-Viz.

  • 1: Specify the pose type of obtained waypoints as joint positions.

  • pos_num: The variable that stores the number of waypoints returned by the vision system.

  • vis_pos_num: The variable that stores the position of the Vision Move waypoint (picking waypoint) in the path.

  • status: The variable that stores the command execution status code.

The entire statement indicates that the robot obtains the planned path from the Mech-Viz project.

The returned planned path is saved to the robot memory and cannot be directly obtained. To access the planned path, you must store the planned path in a subsequent step.
   ;check whether planned path has been got from Mech-Viz successfully
   IF status<> 2100 THEN
      ;add error handling logic here according to different error codes
      ;e.g.: status=2038 means no point cloud in ROI
      halt
   ENDIF
  • IF A THEN …​ ENDIF: When condition A is met, the program executes the code between IF and ENDIF.

  • <>: Not equal.

The above statement indicates that when the status code is 2100, the robot has successfully obtained the planned path; otherwise, an exception has occurred in the vision system and the program executes the code between IF and ENDIF. You can perform the corresponding operation based on the specific error code. In this example program, all error codes are handled in the same way, by pausing the program execution using the halt command.

Store the planned path

   ;save waypoints of the planned path to local variables one by one
   MM_Get_Jps(1,Xpick_point1,label[1],toolid[1])
   MM_Get_Jps(2,Xpick_point2,label[2],toolid[2])
   MM_Get_Jps(3,Xpick_point3,label[3],toolid[3])
  • MM_Get_Jps: The command to store the planned path.

  • 1: Store the first waypoint.

  • Xpick_point1: The variable that stores the joint positions of the first waypoint.

  • label[1]: The variable that stores the label of the first waypoint.

  • toolid[1]: The variable that stores the tool ID corresponding to the first waypoint.

The entire statement “MM_Get_Jps(1,Xpick_point1,label[1],toolid[1])” stores the joint positions, label, and tool ID of the first waypoint in the specified variables.

In this example program, the path planned by Mech-Viz consists of three waypoints: the first waypoint is the approach waypoint of picking (Xpick_point1), the second is the picking waypoint (Xpick_point2), and the third is the departure waypoint of picking (Xpick_point3). Please store the planned path based on the actual Mech-Viz project.

Move to the approach waypoint of picking

   ;move to approach waypoint of picking
PTP pick_point1 Vel=50 % PDAT1 Tool[1] Base[0] 

The robot moves to the approach waypoint of picking. pick_point1 and Xpick_point1 indicate the same position.

Move to the picking waypoint

   ;move to picking waypoint
PTP pick_point2 Vel=10 % PDAT2 Tool[1] Base[0] 

The robot moves to the picking waypoint. pick_point2 and Xpick_point2 indicate the same position.

Set DOs to perform picking

   ;add object grasping logic here, such as "$OUT[1]=TRUE"
   halt

After the robot moves to the picking waypoint, you can set a DO (such as “$OUT[1]=TRUE”) to control the robot to use the tool to perform picking. Please set DOs based on the actual situation.

halt indicates to pause the program execution. If you have added a statement to set a DO, you can delete the halt statement here.

Move to the departure waypoint of picking

   ;move to departure waypoint of picking
PTP pick_point3 Vel=50 % PDAT3 Tool[1] Base[0] 

The robot moves to the departure waypoint of picking. pick_point3 and Xpick_point3 indicate the same position.

Move to the intermediate waypoint

   ;move to intermediate waypoint of placing
PTP drop_waypoint CONT Vel=100 % PDAT2 Tool[1] Base[0]

The robot moves to a intermediate waypoint (drop_waypoint) between the departure waypoint of picking and the approach waypoint of placing.

  • Adding intermediate waypoints can ensure smooth robot motion and avoid unnecessary collisions. You can add multiple intermediate waypoints according to the actual situation.

  • You need to teach the intermediate waypoint in advance. For information about how to teach the waypoint, see Teach Calibration Start Point in the calibration document.

Move the robot to the approach waypoint of placing

   ;move to approach waypoint of placing
LIN drop_app Vel=1 m/s CPDAT3 Tool[1] Base[0] 

The robot moves from the intermediate waypoint to the approach waypoint of placing (drop_app).

  • Adding approach waypoints of placing can prevent the robot from colliding with objects (such as bins) in the scene when moving.

  • You need to teach the approach waypoint of placing in advance. For information about how to teach the waypoint, see Teach Calibration Start Point in the calibration document.

Move to the placing waypoint

   ;move to placing waypoint
LIN drop Vel=0.3 m/s CPDAT4 Tool[1] Base[0] 

The robot moves from the approach waypoint of placing to the placing waypoint (drop).

  • The placing waypoint should be located at a safe distance from other stations, personnel, and equipment, and should not exceed the robot’s maximum reach.

  • You need to teach the placing waypoint in advance. For information about how to teach the waypoint, see Teach Calibration Start Point in the calibration document.

Set DOs to perform placing

   ;add object releasing logic here, such as "$OUT[1]=FALSE"
   halt

After the robot moves to the placing waypoint, you can set a DO (such as “$OUT[1]=FALSE”) to control the robot to use the tool to perform placing. Please set DOs based on the actual situation.

halt indicates to pause the program execution. If you have added a statement to set a DO, you can delete the halt statement here.

Move the robot to the departure waypoint of placing

   ;move to departure waypoint of placing
LIN drop_app Vel=1 m/s CPDAT3 Tool[1] Base[0] 

The robot moves from the placing waypoint to the departure waypoint of placing (drop_app).

  • Adding departure waypoints of placing can prevent the robot from colliding with objects (such as bins) in the scene when moving.

  • You need to teach the departure waypoint of placing in advance. For information about how to teach the waypoint, see Teach Calibration Start Point in the calibration document.

Move to the home position

   ;move back to robot home position
PTP HOME Vel=100 % DEFAULT

The robot moves from the departure waypoint of placing to the home waypoint again.

You should teach the home position in advance. For detailed instructions, see Teach Calibration Start Point in the calibration document.

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.