KUKA Example Program

You are viewing an old version of the documentation. You can switch to the documentation of the latest version by clicking the top-right corner of the page.

This topic introduces the example programs that perform an actual pick-and-place task.

Prerequisites

  1. You have set up Standard Interface communication with the robot.

  2. You have completed the hand-eye calibration by referring to the section KUKA Calibration Program.

  3. Mech-Vision and Mech-Viz projects are created and set to autoload.

  4. The TCP (Tool Center Point) has been correctly specified.

  5. The robot velocity is set to a low value, so that the operator can notice any unexpected behavior before accidents occur.

Example Programs

The example programs are stored in Communication Component/Robot_Interface/KUKA/sample in the installation directory of Mech-Mind Software Suite.

Obtain Vision Result from Mech-Vision

&ACCESS RVO
&REL 5
DEF MM_SAMPLE01 ( )
  ;FUNCTION:Eye to Hand simple pick and place with {product-vis}
  ;2022-5-31
  INT Job
  INT Pos_Num
  INT Last_Data
  INT MM_Status
  E6POS MM_pick
  E6POS MM_waypoint
  E6POS MM_camera_capture
  E6POS MM_drop
  INT MM_Label
  INT MM_Speed
  ;FOLD PTP HOME Vel=100 % DEFAULT;%{PE}%R 8.3.44,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT
$BWDSTART=FALSE
PDAT_ACT=PDEFAULT
FDAT_ACT=FHOME
BAS(#PTP_PARAMS,100)
$H_POS=XHOME
PTP XHOME
  ;ENDFOLD

  BAS(#TOOL,1)
  LIN MM_camera_capture
  ;Set ip address of IPC
  MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
  wait sec 0.1
  ;Set vision recipe
  MM_Switch_Model(1,1)
  ;Run vision project
  MM_Start_Vis(1,1,2,snap_jps)
  wait sec 1
  MM_Get_VisData(1,Last_Data,Pos_Num,MM_Status)
  IF MM_Status<> 1100 THEN
    halt
  ENDIF
  MM_Get_Pose(1,MM_pick,MM_Label,MM_Speed )
MM_pick.z=MM_pick.z+100
LIN MM_pick
MM_pick.z=MM_pick.z-100
  LIN MM_pick
  ;Add object grasping logic here.
  LIN_REL {z -100}#TOOL
 LIN MM_waypoint
MM_drop.z=MM_drop.z+100
LIN MM_drop
MM_drop.z=MM_drop.z-100
  LIN MM_drop
  ;Add object releasing logic here.
  LIN_REL {z -100}#TOOL
    ;FOLD PTP HOME Vel=100 % DEFAULT;%{PE}%R 8.3.44,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT
$BWDSTART=FALSE
PDAT_ACT=PDEFAULT
FDAT_ACT=FHOME
BAS(#PTP_PARAMS,100)
$H_POS=XHOME
PTP XHOME
  ;ENDFOLD
END

Program Logic

  1. Move the robot to the HOME position.

  2. Move the robot to the image-capturing pose.

  3. Initialize communication with MM_Init_Socket.

  4. If parameter recipes are used in the Mech-Vision project, the recipe to be used is set with MM_Switch_Model.

  5. Run the Mech-Vision project with MM_Start_Vis.

  6. Wait for one second. In the Eye To Hand setup, this WAIT SEC instruction is not needed if there are motion steps between MM_Start_Vis and MM_Get_VisData. In the Eye-In-Hand setup, the WAIT SEC instruction is required to make sure that the robot stays still until image acquisition is completed.

  7. Obtain the vision point from Mech-Vision.

  8. Check if the returned status code indicates any error. If an error code is returned, the program should be halted.

  9. Move the robot to the picking waypoint and perform picking.

  10. Move the robot to an intermediate point between the picking waypoint and placing waypoint.

  11. Move the robot to the set placing waypoint and perform placing.

Customization Required

  • Define the TCP

    Set the tool reference frame that the TCP uses with BAS(#TOOL,1). You need to change the tool reference frame to the one in which the actual TCP value is stored.

  • Teach the image-capturing pose

    LIN MM_camera_capture: Record the image-capturing pose in MM_camera_capture.

  • Teach the intermediate point(s)

    LIN MM_waypoint: Add intermediate points between the picking waypoint and placing waypoint to ensure that the robot doesn’t collide with the surrounding when moving between the picking waypoint and placing waypoint. You can add one or more intermediate points to the variable “MM_waypoint”.

  • Teach the placing waypoint

    LIN MM_drop: Record the placing waypoint in the pose variable “MM_drop”.

  • Define Z-offset from the picking/placing waypoint: To ensure collision doesn’t occur when the robot is approaching or departing the picking/placing pose, you can define Z-offset distances relative to the tool frame from the picking/placing pose. With the Z-offset, the robot moves along the Z-direction of the tool frame.

    • Z-offset when approaching the picking waypoint

      MM_pick.z=MM_pick.z+100

      In this example, the Z-offset when approaching the picking waypoint is set to 100 mm. The setting moves the robot to a position 100 mm above the picking waypoint. Adjust the Z-offset value according to your actual needs.

    • Z-offset when departing the picking waypoint

      LIN_REL {z -100}#TOOL

      In this example, the Z-offset when departing the picking waypoint is set to 100 mm. The setting moves the robot 100 mm along the Z-direction of the tool reference frame from the picking waypoint. Adjust the Z-offset value according to your actual needs.

    • Z-offset when approaching the placing waypoint

      MM_drop.z=MM_drop.z+100

      In this example, the Z-offset when departing the placing waypoint is set to 100 mm. The setting moves the robot to a position 100 mm above the placing waypoint. Adjust the Z-offset value according to your actual needs.

    • Z-offset when departing the placing waypoint

      LIN_REL {z -100}#TOOL

      In this example, the Z-offset when departing the placing waypoint is set to 100 mm. The setting moves the robot 100 mm along the Z-direction of the tool reference frame from the placing waypoint. Adjust the Z-offset value according to your actual needs.

    • Add the object picking and releasing logics for the tool

      Add logic for controlling the tool action when picking or releasing the object.

  • Define the HOME position

    Teach the HOME position before running the program.

Obtain Planned Path from Mech-Viz

&ACCESS RVO
&REL 2
DEF MM_SAMPLE02 ( )
INT Job
  INT Pos_Num
  INT VisPos_Num
  INT Last_Data
  INT MM_Status
  DECL E6POS MM_movepoint[20]
  E6POS MM_waypoint
  E6POS MM_camera_capture
  E6POS MM_drop
  DECL INT MM_Label[20]
  INT MM_Speed[20]
  INT count
  ;FOLD PTP HOME Vel=100 % DEFAULT;%{PE}%R 8.3.44,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT
$BWDSTART=FALSE
PDAT_ACT=PDEFAULT
FDAT_ACT=FHOME
BAS(#PTP_PARAMS,100)
$H_POS=XHOME
PTP XHOME
  ;ENDFOLD

  BAS(#TOOL,1)
  LIN MM_camera_capture
  ;Set ip address of IPC
  MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
  wait sec 0.1
  ;Set vision recipe
  ;MM_Switch_Model(1,1)
  ;Run Viz project
  MM_Start_Viz(1,snap_jps)
  wait sec 0.1
  ;set branch exitport
  ;MM_Set_Branch(1,1)
  ;get planned path
  MM_Get_VizData(2,Last_Data,Pos_Num,VisPos_Num,MM_Status)
  IF MM_Status<> 2100 THEN
    halt
  ENDIF
  FOR count=1 TO Pos_Num
  MM_Get_Pose(count,MM_movepoint[count],MM_Label[count],MM_Speed[count])
  ENDFOR
  ;follow the planned path to pick
  FOR count=1 TO Pos_Num
  LIN MM_movepoint[count]
  IF count==VisPos_Num THEN
   ;add object grasping logic here
  ENDIF
  ENDFOR
  ;go to drop location
  LIN MM_waypoint
MM_drop.z=MM_drop.z+100
  LIN MM_drop
MM_drop.z=MM_drop.z-100
  LIN MM_drop
  ;Add object releasing logic here.
  LIN_REL  {z -100}#TOOL
    ;FOLD PTP HOME Vel=100 % DEFAULT;%{PE}%R 8.3.44,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT
$BWDSTART=FALSE
PDAT_ACT=PDEFAULT
FDAT_ACT=FHOME
BAS(#PTP_PARAMS,100)
$H_POS=XHOME
PTP XHOME
  ;ENDFOLD
END

Program Logic

In this example program, Mech-Viz leads the robot to pick and place objects under the guidance of vision result.

  1. Move the robot to the HOME position.

  2. Move the robot to the image-capturing pose.

  3. Initialize communication with MM_Init_Socket.

  4. If parameter recipes are used in the Mech-Vision project, the recipe to be used is set with MM_Switch_Model.

  5. Run the Mech-Viz project with MM_Start_Viz.

  6. Obtain the planned path from Mech-Viz.

  7. Check if the returned status code indicates any error. If an error code is returned, the program should be halted.

  8. Store obtained waypoints in the planned path to MM_movepoint[] with a FOR loop.

  9. Move the robot along the path planned by Mech-Viz with a FOR loop and perform picking.

  10. Move the robot to an intermediate point between the picking waypoint and placing waypoint.

  11. Move the robot to the set placing waypoint and perform placing.

Customization Required

  • Define the TCP

    Set the tool reference frame that the TCP uses with BAS(#TOOL,1). You need to change the tool reference frame to the one in which the actual TCP value is stored.

  • Teach the image-capturing pose

    LIN MM_camera_capture: Record the image-capturing pose in the pose variable “MM_camera_capture”.

  • Teach the intermediate point(s)

    LIN MM_waypoint: Add intermediate points between the picking waypoint and placing waypoint to ensure that the robot doesn’t collide with the surrounding when moving between the picking waypoint and placing waypoint. You can add one or more intermediate points to the variable “MM_waypoint”.

  • Teach the placing waypoint

    LIN MM_drop: Record the placing waypoint in the pose variable “MM_drop”.

  • Add the object picking and releasing logics for the tool

    Add logic for controlling the tool action when picking or releasing the object.

  • Define the Home position

    Teach the HOME position before running the program.

Obtain Planned Path from Mech-Vision

&A&ACCESS RVO
&REL 2
DEF MM_SAMPLE03 ( )
  ;FUNCTION:Eye to Hand simple pick and place with {product-vis} Path Planning Step
  ;2023-1-10
  INT Pos_Num
  INT VisPos_Num
  INT Last_Data
  INT MM_Status
  DECL E6POS MM_movepoint[20]
  E6POS MM_waypoint
  E6POS MM_camera_capture
  E6POS MM_drop
  INT MM_Label[20]
  INT MM_Speed[20]
  INT count
  ;FOLD PTP HOME Vel=100 % DEFAULT;%{PE}%R 8.3.44,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT
$BWDSTART=FALSE
PDAT_ACT=PDEFAULT
FDAT_ACT=FHOME
BAS(#PTP_PARAMS,100)
$H_POS=XHOME
PTP XHOME
  ;ENDFOLD

  BAS(#TOOL,1)
  LIN MM_camera_capture
  ;Set ip address of IPC
  MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
  wait sec 0.1
  ;Set vision recipe
  MM_Switch_Model(1,1)
  ;Run vision project
  MM_Start_Vis(1,1,2,snap_jps)
  wait sec 1
  ;get planned path
  MM_Get_VisPath(1,2,Last_Data,Pos_Num,VisPos_Num,MM_Status)
  IF MM_Status<> 1103 THEN
    halt
  ENDIF
  FOR count=1 TO Pos_Num
  MM_Get_Pose(count,MM_movepoint[count],MM_Label[count],MM_Speed[count])
  ENDFOR
  ;follow the planned path to pick
  FOR count=1 TO Pos_Num
  LIN MM_movepoint[count]
  IF count==VisPos_Num THEN
   ;add object grasping logic here
  ENDIF
  ENDFOR
  ;go to drop location
  LIN MM_waypoint
MM_drop.z=MM_drop.z+100
  LIN MM_drop
MM_drop.z=MM_drop.z-100
  LIN MM_drop
  ;Add object releasing logic here.
  LIN_REL  {z -100}#TOOL
    ;FOLD PTP HOME Vel=100 % DEFAULT;%{PE}%R 8.3.44,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:HOME, 3:, 5:100, 7:DEFAULT
$BWDSTART=FALSE
PDAT_ACT=PDEFAULT
FDAT_ACT=FHOME
BAS(#PTP_PARAMS,100)
$H_POS=XHOME
PTP XHOME
  ;ENDFOLD
END

Program Logic

In this example program, the path planned by Mech-Vision in the “Path Planning” Step will be used to pick and place objects.

  1. Move the robot to the HOME position.

  2. Move the robot to the image-capturing pose.

  3. Initialize communication with MM_Init_Socket.

  4. If parameter recipes are used in the Mech-Vision project, the recipe to be used is set with MM_Switch_Model.

  5. Run the Mech-Vision project with MM_Start_Vis.

  6. Obtain the planned path from the “Path Planning” Step of Mech-Vision with MM_Get_VisPath.

  7. Check if the returned status code indicates any error. If an error code is returned, the program should be halted.

  8. Store obtained waypoints in the planned path to MM_movepoint[] with a FOR loop.

  9. Move the robot along the planned path with a FOR loop and perform picking.

  10. Move the robot to an intermediate point between the picking waypoint and placing waypoint.

  11. Move the robot to the set placing waypoint and perform placing.

Customization Required

  • Define the TCP

    Set the tool reference frame that the TCP uses with BAS(#TOOL,1). You need to change the tool reference frame to the one in which the actual TCP value is stored.

  • Teach the image-capturing pose

    LIN MM_camera_capture: Record the image-capturing pose in MM_camera_capture.

  • Teach the intermediate point(s)

    LIN MM_waypoint: Add intermediate points between the picking waypoint and placing waypoint to ensure that the robot doesn’t collide with the surrounding when moving between the picking waypoint and placing waypoint. You can add one or more intermediate points to the variable “MM_waypoint”.

  • Teach the placing waypoint

    LIN MM_drop: Record the placing waypoint in the pose variable “MM_drop”.

  • Add the object picking and releasing logics for the tool

    Add logic for controlling the tool action when picking or releasing the object.

  • Define the Home position

    Teach the HOME position before running the program.

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.