KUKA Example Programs

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 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 Mech-Center/Robot_Interface/KUKA/sample in the installation directory of Mech-Vision & Mech-Viz.

Obtain Vision Result from Mech-Vision

&ACCESS RVO
&REL 1
DEF MM_SAMPLE01 ( )
;FUNCTION:Eye to Hand simple pick and place with Mech-Vision
;2022-5-31
BAS(#TOOL,1)
BAS(#BASE,0)
BAS(#VEL_CP,200)
BAS(#ACC_CP,80)
PTP HOME Vel=100 % DEFAULT
HALT
;Please touch-up MM_camera_capture then go on;
;Move to MM_camera_capture position
LIN MM_Camera_Capture CONT Vel=1 m/s CPDAT1 Tool[1] Base[0] ColDetect[1]
;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,0,2,init_jps)
wait sec 1
MM_Get_VisData(1,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
;MOVE to MM_waypoint
LIN MM_waypoint CONT Vel=1 m/s CPDAT2 Tool[1] Base[0] ColDetect[1]
MM_drop.z=MM_drop.z+100
;MOVE to Approach Point
LIN MM_drop CONT Vel=1 m/s CPDAT3 Tool[1] Base[0] ColDetect[1]
MM_drop.z=MM_drop.z-100
;MOVE to MM_drop
LIN MM_drop Vel=0.5 m/s CPDAT3 Tool[1] Base[0] ColDetect[1]
;Add object releasing logic here.
;MOVE to Retreat Point
LIN_REL {z -100}#TOOL
PTP HOME Vel=100 % DEFAULT
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, the wait time 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 time should be set to 1 second so 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: Users should record the image-capturing pose in the 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.

  • 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 1
DEF MM_SAMPLE02 ( )
;FUNCTION:Eye to Hand simple pick and place with Mech-Viz
;2022-5-31
BAS(#TOOL,1)
BAS(#BASE,0)
BAS(#VEL_CP,200)
BAS(#ACC_CP,80)
PTP HOME Vel=100 % DEFAULT
HALT
;Please touch-up MM_camera_capture then go on;
;Move to MM_camera_capture position
LIN MM_Camera_Capture CONT Vel=1 m/s CPDAT1 Tool[1] Base[0] ColDetect[1]
;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,init_jps)
wait sec 0.1
;set branch exitport
;MM_Set_Branch(1,1)
;get planned path
MM_Get_VizData(2,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
;MOVE to MM_waypoint
LIN MM_waypoint CONT Vel=1 m/s CPDAT2 Tool[1] Base[0] ColDetect[1]
MM_drop.z=MM_drop.z+100
;MOVE to Approach Point
LIN MM_drop CONT Vel=1 m/s CPDAT3 Tool[1] Base[0] ColDetect[1]
MM_drop.z=MM_drop.z-100
;MOVE to MM_drop
LIN MM_drop Vel=0.5 m/s CPDAT3 Tool[1] Base[0] ColDetect[1]
;Add object releasing logic here.
;MOVE to Retreat Point
LIN_REL {z -100}#TOOL
PTP HOME Vel=100 % DEFAULT
END

Program Logic

This example program uses Mech-Viz for vision-guided picking and placing objects to the set placing waypoint.

  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 is stopped.

  8. Store obtained poses 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: Users should record the image-capturing pose in the 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

&ACCESS RVO
&REL 1
&PARAM DISKPATH = KRC:\R1\mechmind
DEF MM_SAMPLE03 ( )
;FUNCTION:Eye to Hand simple pick and place with Mech-Vision Path Planning Step
;2023-1-10
BAS(#TOOL,1)
BAS(#BASE,0)
BAS(#VEL_CP,200)
BAS(#ACC_CP,80)
PTP HOME Vel=100 % DEFAULT
HALT
;Please touch-up MM_camera_capture then go on;
;Move to MM_camera_capture position
LIN MM_Camera_Capture CONT Vel=1 m/s CPDAT1 Tool[1] Base[0] ColDetect[1]
;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,0,2,init_jps)
wait sec 1
;get planned path
MM_Get_VisPath(1,2,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
;MOVE to MM_waypoint
LIN MM_waypoint CONT Vel=1 m/s CPDAT2 Tool[1] Base[0] ColDetect[1]
MM_drop.z=MM_drop.z+100
;MOVE to Approach Point
LIN MM_drop CONT Vel=1 m/s CPDAT3 Tool[1] Base[0] ColDetect[1]
MM_drop.z=MM_drop.z-100
;MOVE to MM_drop
LIN MM_drop Vel=0.5 m/s CPDAT3 Tool[1] Base[0] ColDetect[1]
;Add object releasing logic here.
;MOVE to Retreat Point
LIN_REL {z -100}#TOOL
PTP HOME Vel=100 % DEFAULT
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 the variable 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: Users should record the image-capturing pose in the 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.

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.