Example Program 1: MM_S1_Vis_Basic

Program Introduction

Description

The robot triggers the Mech-Vision project to run, and then obtains the vision result for picking and placing the object.

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/FANUC/sample/MM_S1_Vis_Basic path.

Project

Mech-Vision project

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_S1_Vis_Basic example program.

   1:  !-------------------------------- ;
   2:  !FUNCTION: trigger Mech-Vision ;
   3:  !project and get vision result ;
   4:  !Mech-Mind, 2023-12-25 ;
   5:  !-------------------------------- ;
   6:   ;
   7:  !set current uframe NO. to 0 ;
   8:  UFRAME_NUM=0 ;
   9:  !set current tool NO. to 1 ;
  10:  UTOOL_NUM=1 ;
  11:  !move to robot home position ;
  12:J P[1] 100% FINE    ;
  13:  !initialize communication ;
  14:  !parameters(initialization is ;
  15:  !required only once) ;
  16:  CALL MM_INIT_SKT('8','127.0.0.1',50000,5) ;
  17:  !move to image-capturing position ;
  18:L P[2] 1000mm/sec FINE    ;
  19:  !trigger NO.1 Mech-Vision project ;
  20:  CALL MM_START_VIS(1,0,2,10) ;
  21:  !get vision result from NO.1 ;
  22:  !Mech-Vision project ;
  23:  CALL MM_GET_VIS(1,51,53) ;
  24:  !check whether vision result has ;
  25:  !been got from Mech-Vision ;
  26:  !successfully ;
  27:  IF R[53]<>1100,JMP LBL[99] ;
  28:  !save first vision point data to ;
  29:  !local variables ;
  30:  CALL MM_GET_POS(1,60,70,80) ;
  31:  !move to intermediate waypoint ;
  32:  !of picking ;
  33:J P[3] 50% CNT100    ;
  34:  !move to approach waypoint ;
  35:  !of picking ;
  36:L PR[60] 1000mm/sec FINE Tool_Offset,PR[1]    ;
  37:  !move to picking waypoint ;
  38:L PR[60] 300mm/sec FINE    ;
  39:  !add object grasping logic here, ;
  40:  !such as "DO[1]=ON" ;
  41:  PAUSE ;
  42:  !move to departure waypoint ;
  43:  !of picking ;
  44:L PR[60] 1000mm/sec FINE Tool_Offset,PR[1]    ;
  45:  !move to intermediate waypoint ;
  46:  !of placing ;
  47:J P[4] 50% CNT100    ;
  48:  !move to approach waypoint ;
  49:  !of placing ;
  50:L P[5] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  51:  !move to placing waypoint ;
  52:L P[5] 300mm/sec FINE    ;
  53:  !add object releasing logic here, ;
  54:  !such as "DO[1]=OFF" ;
  55:  PAUSE ;
  56:  !move to departure waypoint ;
  57:  !of placing ;
  58:L P[5] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  59:  !move back to robot home position ;
  60:J P[1] 100% FINE    ;
  61:  END ;
  62:   ;
  63:  LBL[99:vision error] ;
  64:  !add error handling logic here ;
  65:  !according to different ;
  66:  !error codes ;
  67:  !e.g.: status=1003 means no ;
  68:  !point cloud in ROI ;
  69:  !e.g.: status=1002 means no ;
  70:  !vision results ;
  71:  PAUSE ;

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

sample1

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

   7:  !set current uframe NO. to 0 ;
   8:  UFRAME_NUM=0 ;
   9:  !set current tool NO. to 1 ;
  10:  UTOOL_NUM=1 ;
  • UFRAME_NUM=0: Set the selected user reference frame to 0. 0 indicates the world reference frame.

  • UTOOL_NUM=1: Set the selected tool reference frame to 1. You must specify the tool reference frame represented by 1.

The above two statements set the selected user and tool reference frames.

Move to the home position

  11:  !move to robot home position ;
  12:J P[1] 100% FINE    ;
  • J: The joint position motion command of the robot, indicating that the robot moves along the arc to a specified position.

  • P[1]: Specify the target position to which the robot moves, i.e., the home position that is taught. The home position is usually a safe one where the robot is away from workobjects and the surrounding equipment.

  • 100%: The percentage of relative maximum movement velocity.

  • FINE: The robot pauses briefly upon reaching a target position before moving to the next target.

The entire statement indicates that the robot moves to the taught home position by using joint position movement.

You should teach the home position (P[1]) in advance. For detailed instructions, see Teach Calibration Starting Point in the calibration document.

Initialize communication parameters

  13:  !initialize communication ;
  14:  !parameters(initialization is ;
  15:  !required only once) ;
  16:  CALL MM_INIT_SKT('8','127.0.0.1',50000,5) ;
  • MM_INIT_SKT: The command to initialize the communication.

  • '8': The port number of the robot.

  • '127.0.0.1': The IP address of the IPC.

  • 50000: The port number of the IPC.

  • 5: Specify the communication timeout period as 5 minutes.

The entire statement indicates that the robot establishes the connection with the vision system by specifying the IP address, port number, and timeout period of the communication target (the IPC) through the MM_INIT_SKT command.

Please modify the IP address and port number of the IPC according to the actual situation. The IP address and port number must be consistent with those set in the vision system.

Move to the image-capturing position

  17:  !move to image-capturing position ;
  18:L P[2] 1000mm/sec FINE    ;
  • L: The linear motion command of the robot. This command specifies to move the robot along a linear path to a specified position.

  • P[2]: Specify the target position to which the robot moves, i.e., the image-capturing position that is taught. The image-capturing position refers to the position of the robot where the camera on the robot captures images. At this position, the robot arm should not block the camera’s FOV.

The entire command indicates that the robot moves to the image-capturing position in linear motion, with a velocity of 1000 mm/sec.

You should teach the image-capturing position (P[2]) in advance. For detailed instructions, see Teach Calibration Start Point in the calibration document.

Trigger the Mech-Vision project to run

  19:  !trigger NO.1 Mech-Vision project ;
  20:  CALL MM_START_VIS(1,0,2,10) ;
  • MM_START_VIS: The command to trigger the Mech-Vision project to run.

  • 1: The Mech-Vision project ID.

  • 0: The Mech-Vision project is expected to return all vision points.

  • 2: Specify that the robot flange pose must be input to the Mech-Vision project.

  • 10: The position register PR[10], which stores custom joint positions. In this example program, the joint positions have no practical use, but the position register ID must be specified.

The entire statement indicates that the robot triggers the vision system to run the Mech-Vision project with an ID of 1 and expects the Mech-Vision project to return all vision points.

Obtain the vision result

  21:  !get vision result from NO.1 ;
  22:  !Mech-Vision project ;
  23:  CALL MM_GET_VIS(1,51,53) ;
  • MM_GET_VIS: The command to obtain the vision result.

  • 1: The Mech-Vision project ID.

  • 51: The numeric register R[51], which stores the obtained number of vision points.

  • 53: The numeric register R[53], which stores the command execution status code.

The entire statement indicates that the robot obtains the vision result from the Mech-Vision project with an ID of 1.

The returned vision result is saved to the robot memory and cannot be directly obtained. To access the vision result, you must store the vision result in a subsequent step.
  24:  !check whether vision result has ;
  25:  !been got from Mech-Vision ;
  26:  !successfully ;
  27:  IF R[53]<>1100,JMP LBL[99] ;
  • “IF A,JMP B”: If condition A is met, the program will jump to point B and execute the instructions there.

  • <>: Not equal.

The statement means that when the status code in R[53] is 1100, the robot has successfully obtained all vision result; otherwise, an exception has occurred in the vision system, and the program will jump to LBL[99] and execute the instructions there. The following is the code at LBL[99].

  63:  LBL[99:vision error] ;
  64:  !add error handling logic here ;
  65:  !according to different ;
  66:  !error codes ;
  67:  !e.g.: status=1003 means no ;
  68:  !point cloud in ROI ;
  69:  !e.g.: status=1002 means no ;
  70:  !vision results ;
  71:  PAUSE ;

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 stopping the program execution using the PAUSE command.

Store the vision result

  28:  !save first vision point data to ;
  29:  !local variables ;
  30:  CALL MM_GET_POS(1,60,70,80) ;
  • MM_GET_POS: The command to store the vision result.

  • 1: The first vision point is stored.

  • 60: The position register PR[60], which stores the TCP of the first vision point, i.e., the TCP of the picking point.

  • 70: The numeric register R[70], which stores the label of the first vision point.

  • 80: The numeric register R[80], which stores the tool ID of the first vision point.

The entire statement stores the TCP, label, and tool ID of the first vision point in the specified registers.

Move to the intermediate waypoint

  31:  !move to intermediate waypoint ;
  32:  !of picking ;
  33:J P[3] 50% CNT100    ;
  • P[3]: Specifies the target position to which the robot moves, which is the intermediate waypoint.

  • CNT: The robot approaches the target position but does not stop at that position; instead, it stops at the next position. The subsequent number indicates the degree to which the robot is approaching the target position; a larger value means it is further from the target position.

The entire statement moves the robot in joint positions to a certain intermediate waypoint between the image-capturing position and the approach waypoint of picking.

  • 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 (P[3]) in advance. For information about how to teach the waypoint, see Teach Calibration Start Point in the calibration document.

Move to the approach waypoint of picking

  34:  !move to approach waypoint ;
  35:  !of picking ;
  36:L PR[60] 1000mm/sec FINE Tool_Offset,PR[1]    ;
  • L: The robot moves linearly.

  • PR[60]: The TCP of the picking waypoint.

  • “Tool_Offset,PR[1]”: The robot adjusts its position relative to the picking waypoint (PR[60]) using the offset specified in PR[1]. In this case, you only need to set the Z-axis value of PR[1]. For instance, setting the Z-axis to -100 and all other values to 0 means the position is 100mm below the picking waypoint along the Z-axis (i.e., the robot will move 100mm above the picking waypoint to reach the approach waypoint of picking).

The entire statement directs the robot to move linearly to a position situated above the picking waypoint.

Adding approach waypoints of picking can prevent the robot from colliding with objects (such as bins) in the scene when moving. You can modify the PR[1] value based on the actual scenario to ensure that no collision occurs during the approaching process.

Move to the picking waypoint

  37:  !move to picking waypoint ;
  38:L PR[60] 300mm/sec FINE    ;

The robot moves from the approach waypoint of picking to the picking waypoint linearly.

Set DO commands to perform picking

  39:  !add object grasping logic here, ;
  40:  !such as "DO[1]=ON" ;
  41:  PAUSE ;

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

PAUSE indicates to stop the program execution. If you have added a statement to set a DO command, you can delete the PAUSE statement here.

Move to the departure waypoint of picking

  42:  !move to departure waypoint ;
  43:  !of picking ;
  44:L PR[60] 1000mm/sec FINE Tool_Offset,PR[1]    ;

The robot moves to position above the picking waypoint and reaches the departure waypoint of picking.

Adding departure waypoints of picking can prevent the robot from colliding with objects (such as bins) in the scene when moving. You can modify the PR[1] value based on the actual scenario to ensure that no collision occurs during the departing process.

Move to the intermediate waypoint

  45:  !move to intermediate waypoint ;
  46:  !of placing ;
  47:J P[4] 50% CNT100    ;

The robot moves to a intermediate 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 (P[4]) 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

  48:  !move to approach waypoint ;
  49:  !of placing ;
  50:L P[5] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  • P[5]: The placing waypoint. You need to teach the placing waypoint (P[5]) in advance. For information about how to teach the waypoint, see Teach Calibration Start Point in the calibration document.

  • “Tool_Offset,PR[2]”: The robot adjusts its position relative to the placing waypoint (P[5]) using the offset specified in PR[2]. In this case, you only need to set the Z-axis value of PR[2]. For instance, setting the Z-axis to -100 and all other values to 0 means the position is 100mm below the placing waypoint along the Z-axis (i.e., the robot will move 100mm above the placing waypoint to reach the approach waypoint of placing).

Adding approach waypoints of placing can prevent the robot from colliding with objects (such as bins) in the scene when moving. You can modify the PR[2] value based on the actual scenario to ensure that no collision occurs during the approaching process.

Move to the placing waypoint

  51:  !move to placing waypoint ;
  52:L P[5] 300mm/sec FINE    ;

The robot moves from the approach waypoint of placing to the placing waypoint.

Set DO commands to perform placing

  53:  !add object releasing logic here, ;
  54:  !such as "DO[1]=OFF" ;
  55:  PAUSE ;

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

PAUSE indicates to stop the program execution. If you have added a statement to set a DO command, you can delete the PAUSE statement here.

Move the robot to the departure waypoint of placing

  56:  !move to departure waypoint ;
  57:  !of placing ;
  58:L P[5] 1000mm/sec FINE Tool_Offset,PR[2]    ;

The robot moves to a position above the placing waypoint and reaches the departure waypoint of placing.

Adding departure waypoints of placing can prevent the robot from colliding with objects (such as bins) in the scene when moving. You can modify the PR[2] value based on the actual scenario to ensure that no collision occurs during the departing process.

Move to the home position

  59:  !move back to robot home position ;
  60:J P[1] 100% FINE    ;

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

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.