Kawasaki Example Programs

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

Example Programs

The example programs are stored in Mech-Center/Robot_Interface/KAWASAKI/sample in the installation directory of Mech-Vision & Mech-Viz.

There are three example programs for different scenarios.

Obtain Vision Result from Mech-Vision

.PROGRAM vision_sample_1()
;**********************************************************
;* FUNCTION:simple pick and place with Mech-Vision
;* 2022-5-1
;**********************************************************
  accuracy 1 always
  speed 30 always
  TOOL gripper ;set TCP
  Home ;move robot home position
  JMOVE camera_capture ;move to camera capture position
  break
  pos_num = 0
  ;Set ip address of IPC
  call mm_init_skt(127,0,0,1,50000)
  twait 0.1
  ;Set vision recipe
  ;call mm_switch_model(1,1)
  ;Run vision project
  call mm_start_vis(1,1,2,#start_vis) ;(x,x,3,#start_vis) used for ETH pathplan initial position
  twait 1
  call mm_get_visdata(1,pos_num,ret2)
  if ret2 <> 1100
      halt
  end
  call mm_get_pose(1,&pick[1],label[1],speed[1])
  LAPPRO pick[1],100
  LMOVE pick[1]
  break
  ;Add object grasping logic here.
  ldepart 100
  lmove waypoint[1]
  lappro drop[1],100
  lmove drop[1]
  ;Add object releasing logic here.
  ldepart 100
  HOME
.END

Program Logic

  • Line 8: Define the TCP. The TCP is defined in the pose variable “gripper”. For details on how to define the TCP on the teach pendant, refer to the section Set the Robot TCP.

  • Line 9: Move the robot to the HOME position. For details on how to teach the HOME position, refer to section Set the HOME Position.

  • Line 10: Move the robot in linear motion manner to the image-capturing pose. The image-capturing pose is defined in the pose variable “camera_capture”. For details on how to define a pose variable on the teach pendant, refer to the section Teach Pose Data to the Robot.

  • Line 14: Call the mm_init_skt function to initialize the communication. For details, refer to the section Initialize Communication.

  • Lines 16 to 17: If parameter recipes are used in the Mech-Vision project, the recipe to be used is set with mm_switch_model. For details, refer to the section Switch Mech-Vision Recipe.

  • Line 19: Run the Mech-Vision project with mm_start_vis. For details, refer to the section Start Mech-Vision Project.

  • Line 20: Set the time to wait after the camera captures images. In this example, the wait time is one second. In Eye To Hand setup, if there are motion steps (lmove or jmove) between mm_start_vis and mm_get_visdata, this twait instruction is not needed; in Eye In Hand setup, this twait instruction is required to make sure the robot stays still until image acquisition is completed.

  • Line 21: Obtain the vision result form Mech-Vision with mm_get_visdata. “pos_num” stores the number of received poses, and “ret2” stores the received status code. For details, refer to the section Get Vision Target(s).

  • Lines 22 to 24: Check if the returned status code indicates any error (1100 is a normal status code). If an error code is returned, the program is halted.

  • Line 26: Move the robot in linear motion manner to a position 100 mm above the picking pose. You need to modify the Z-offset to ensure that no collision occurs during the approaching.

  • Line 27: Move the robot in the linear motion manner to the picking pose.

  • Line 29: You need to add the gripper control logic for picking the object here.

  • Line 30: Move the robot up 100 mm from the picking pose along the Z axis of the tool reference frame. You need to modify the Z-offset to ensure that no collision occurs during the departing.

  • Line 32: Move the robot to a position 100 mm above the placing pose. You need to modify the Z-offset to ensure that no collision occurs during the approaching.

  • Line 33: Move the robot in the linear motion manner to the fixed placing pose.

  • Line 34: You need to add the gripper control logic for placing the object here.

  • Line 35: Move the robot up 100 mm from the placing pose along the Z axis of the tool reference frame. You need to modify the Z-offset to ensure that no collision occurs during the departing.

  • Line 36: Move the robot to the HOME position.

Obtain Planned Path from Mech-Viz

.PROGRAM vision_sample_2()
;**********************************************************
;* FUNCTION:simple pick and place with Mech-Viz
;* 2022-5-1
;**********************************************************
  accuracy 1 always
  speed 30 always
  TOOL gripper ;set TCP
  Home ;move robot home position
  JMOVE camera_capture ;move to camera_capture position
  break
  pos_num = 0
  ;Set ip address of IPC
  call mm_init_skt(127,0,0,1,50000)
  twait 0.1
  ;Set vision recipe
  ;call mm_switch_model(1,1)
  ;Run Viz project
  call mm_start_viz(1,#start_viz) ;(2,#start_viz) used for ETH viz initial position
  twait 0.1
  ;set branch exitport
  ;call mm_set_branch(1,1)
  ;get planned path
  call mm_get_vizdata(2,pos_num,vispos_num,ret1)
  if ret1 <> 2100
      halt
  end
  for count=1 to pos_num
    call mm_get_pose(count,&movepoint[count],label[count],speed[count])
  end
  ;follow the planned path to pick
  for count =1 to pos_num
    speed speed[count]
    LMOVE movepoint[count]
    if count == vispos_num then
        ;add object grasping logic here
    end
  end
  ;go to drop location
  ldepart 100
  lmove waypoint[1]
  lappro drop[1],100
  lmove drop[1] ;drop point
  ;add object releasing logic here
  ldepart 100
  HOME
.END

Program Logic

  • Line 8: Define the TCP. The TCP is defined in the pose variable “gripper”. For details on how to define the TCP on the teach pendant, refer to the section Set the Robot TCP.

  • Line 9: Move the robot to the HOME position. For details on how to teach the HOME position, refer to section Set the HOME Position.

  • Line 10: Move the robot in linear motion manner to the image-capturing pose. The image-capturing pose is defined in the pose variable “camera_capture”. For details on how to define a pose variable on the teach pendant, refer to the section Teach Pose Data to the Robot.

  • Line 14: Call the mm_init_skt function to initialize the communication. For details, refer to the section Initialize Communication.

  • Lines 16 to 17: If parameter recipes are used in the Mech-Vision project, the recipe to be used is set with mm_switch_model. For details, refer to the section Switch Mech-Vision Recipe.

  • Line 19: Run the Mech-Viz project with mm_start_viz. For details, refer to the section Start Mech-Viz Project.

  • Lines 21 to 22: If you need set the branch in the Mech-Viz project, you can call mm_set_branch to set the exit port for the “Branch by Msg” Step. For details, refer to the section Select Mech-Viz Branch.

  • Line 24: Obtain the picking path planned by the Mech-Viz project with mm_get_vizdata. “pos_num” stores the number of received poses, “vispos_num” stores the location of the first Vision Move waypoint in the planned path, and “ret1” stores the received status code. For details, refer to the section Get Planned Path from Mech-Viz.

  • Lines 25 to 27: Check if the returned status code indicates any error (2100 is a normal status code). If an error code is returned, the program is halted.

  • Lines 28 to 30: Store obtained waypoints in the planned path to variables with a FOR loop. mm_get_pose is called to the vision pose and waypoints on the motion path. For details, refer to the section Store an Obtained TCP Pose.

  • Lines 32 to 38: Move the robot along the path planned by Mech-Viz with a FOR loop to the picking pose. You can add the gripper control logic in line 36 to pick the object.

  • Line 40: Move the robot up 100 mm from the picking pose along the Z axis of the tool reference frame. You need to modify the Z-offset to ensure that no collision occurs during the departing.

  • Line 42: Move the robot to a position 100 mm above the placing pose. You need to modify the Z-offset to ensure that no collision occurs during the approaching.

  • Line 43: Move the robot in the linear motion manner to the fixed placing pose.

  • Line 44: You need to add the gripper control logic for placing the object here.

  • Line 45: Move the robot up 100 mm from the placing pose along the Z axis of the tool reference frame. You need to modify the Z-offset to ensure that no collision occurs during the departing.

  • Line 46: Move the robot to the HOME position.

Obtain Planned Path from Mech-Vision

.PROGRAM vision_sample_3()
;**********************************************************
;* FUNCTION:simple pick and place with Mech-Vision path planning
;* 2023-2-1
;**********************************************************
  accuracy 1 always
  speed 30 always
  TOOL gripper ;set TCP
  Home ;move robot home position
  JMOVE camera_capture ;move to camera_capture position
  break
  pos_num = 0
  ;Set ip address of IPC
  call mm_init_skt(127,0,0,1,50000)
  twait 0.1
  ;Set vision recipe
  ;call mm_switch_model(1,1)
  ;Run Viz project
  call mm_start_vis(1,0,1,#start_vis)
  twait 0.1
  ;get planned path
  call mm_get_vispath(1,2,pos_num,vispos_num,ret1)
  if ret1 <> 1103
      halt
  end
  for count=1 to pos_num
    call mm_get_pose(count,&movepoint[count],label[count],speed[count])
  end
  ;follow the planned path to pick
  for count =1 to pos_num
    speed speed[count]
    LMOVE movepoint[count]
    if count == vispos_num then
        ;add object grasping logic here
    end
  end
  ;go to drop location
  ldepart 100
  lmove waypoint[1]
  lappro drop[1],100
  lmove drop[1] ;drop point
  ;add object releasing logic here
  ldepart 100
  HOME
.END

Program Logic

  • Line 8: Define the TCP. The TCP is defined in the pose variable “gripper”. For details on how to define the TCP on the teach pendant, refer to the section Set the Robot TCP.

  • Line 9: Move the robot to the HOME position. For details on how to teach the HOME position, refer to section Set the HOME Position.

  • Line 10: Move the robot in joint move manner to the image-capturing pose. The image-capturing pose is defined in the pose variable “camera_capture”. For details on how to define a pose variable on the teach pendant, refer to the section Teach Pose Data to the Robot.

  • Line 14: Call the mm_init_skt function to initialize the communication. For details, refer to the section Initialize Communication.

  • Lines 16 to 17: If parameter recipes are used in the Mech-Vision project, the recipe to be used is set with mm_switch_model. For details, refer to the section Switch Mech-Vision Recipe.

  • Line 19: Run the Mech-Vision project with mm_start_vis. For details, refer to the section Start Mech-Vision Project.

  • Line 20: Set the time to wait after the camera captures images. In this example, the wait time is one second. In Eye To Hand setup, if there are motion steps (lmove or jmove) between mm_start_vis and mm_get_vispath, this twait instruction is not needed; in Eye In Hand setup, this twait instruction is required to make sure the robot stays still until image acquisition is completed.

  • Line 22: Obtain the planned path output by the “Path Planning” Step of Mech-Vision with mm_get_vispath. For details, refer to the section Get Result of Step “Path Planning” in Mech-Vision.

  • Lines 23 to 25: Check if the returned status code indicates any error (1103 is a normal status code). If an error code is returned, the program is halted.

  • Lines 26 to 28: Store the obtained waypoints to the specified variables with a FOR loop. For details, refer to the section Store an Obtained TCP Pose.

  • Lines 30 to 36: Move the robot along the planned path with a FOR loop to the picking pose. You can add the gripper control logic to pick the object.

  • Line 38: Move the robot up 100 mm from the picking pose along the Z axis of the tool reference frame. You need to modify the Z-offset to ensure that no collision occurs during the departing.

  • Line 40: Move the robot to a position 100 mm above the placing pose. You need to modify the Z-offset to ensure that no collision occurs during the approaching.

  • Line 41: Move the robot in the linear motion manner to the fixed placing pose.

  • Line 42: You need to add the gripper control logic for placing the object here.

  • Line 43: Move the robot up 100 mm from the placing pose along the Z axis of the tool reference frame. You need to modify the Z-offset to ensure that no collision occurs during the departing.

  • Line 44: Move the robot to the HOME position.

Run the Example Program

Before running the example program, the following prerequisites should be met:

  1. You have completed the communication configuration by referring to the section Set up Standard Interface Communication with Kawasaki.

  2. You have completed the hand-eye calibration by referring to the section Kawasaki Automatic Calibration.

  3. The Mech-Vision solution and project have been built and the “Autoload the solution” option has been set.

  4. The Mech-Viz project has been built and the Autoload Project option has been selected for the project by right-clicking the project name in the Mech-Viz Resources panel and select the checkbox.

  5. The HOME position, image-capturing pose, TCP, and intermediate waypoints have been taught.

When all the prerequisites are met, run the example program by referring to the section Run the Robot 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.