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/FANUC/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.

   1:  !-------------------------------- ;
   2:  !FUNCTION: trigger Mech-Viz ;
   3:  !project and get planned path ;
   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 Mech-Viz project ;
  20:  CALL MM_START_VIZ(2,10) ;
  21:  !get planned path, 1st argument ;
  22:  !(1) means getting pose in JPs ;
  23:  CALL MM_GET_VIZ(1,51,52,53) ;
  24:  !check whether planned path has ;
  25:  !been got from Mech-Viz ;
  26:  !successfully ;
  27:  IF R[53]<>2100,JMP LBL[99] ;
  28:  !save waypoints of the planned ;
  29:  !path to local variables one ;
  30:  !by one ;
  31:  CALL MM_GET_JPS(1,60,70,80) ;
  32:  CALL MM_GET_JPS(2,61,71,81) ;
  33:  CALL MM_GET_JPS(3,62,72,82) ;
  34:  !follow the planned path to pick ;
  35:  !move to approach waypoint ;
  36:  !of picking ;
  37:J PR[60] 50% FINE    ;
  38:  !move to picking waypoint ;
  39:J PR[61] 10% FINE    ;
  40:  !add object grasping logic here, ;
  41:  !such as "DO[1]=ON" ;
  42:  PAUSE ;
  43:  !move to departure waypoint ;
  44:  !of picking ;
  45:J PR[62] 50% FINE    ;
  46:  !move to intermediate waypoint ;
  47:  !of placing ;
  48:J P[3] 50% CNT100    ;
  49:  !move to approach waypoint ;
  50:  !of placing ;
  51:L P[4] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  52:  !move to placing waypoint ;
  53:L P[4] 300mm/sec FINE    ;
  54:  !add object releasing logic here, ;
  55:  !such as "DO[1]=OFF" ;
  56:  PAUSE ;
  57:  !move to departure waypoint ;
  58:  !of placing ;
  59:L P[4] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  60:  !move back to robot home position ;
  61:J P[1] 100% FINE    ;
  62:  END ;
  63:   ;
  64:  LBL[99:vision error] ;
  65:  !add error handling logic here ;
  66:  !according to different ;
  67:  !error codes ;
  68:  !e.g.: status=2038 means no ;
  69:  !point cloud in ROI ;
  70:  PAUSE ;

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

   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 objects 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-Viz project to run

  19:  !trigger Mech-Viz project ;
  20:  CALL MM_START_VIZ(2,10) ;
  • MM_START_VIZ: The command to trigger the Mech-Viz project to run.

  • 2: Send the joint positions represented by position register PR[10] to the Mech-Viz project.

  • 10: The position register PR[10], which is used to store custom joint positions.You need to teach the position represented by the custom joint positions in advance. 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.

Obtain the planned path

  21:  !get planned path, 1st argument ;
  22:  !(1) means getting pose in JPs ;
  23:  CALL MM_GET_VIZ(1,51,52,53) ;
  • MM_GET_VIZ: The command to obtain the path planned by Mech-Viz.

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

  • 51: The numeric register R[51], which stores the number of waypoints returned by the vision system.

  • 52: The numeric register R[52], which stores the position of the Vision Move waypoint (picking waypoint) in the path.

  • 53: The numeric register R[53], which 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.
  24:  !check whether planned path has ;
  25:  !been got from Mech-Viz ;
  26:  !successfully ;
  27:  IF R[53]<>2100,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 2100, the robot has successfully obtained the planned path; 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].

  64:  LBL[99:vision error] ;
  65:  !add error handling logic here ;
  66:  !according to different ;
  67:  !error codes ;
  68:  !e.g.: status=2038 means no ;
  69:  !point cloud in ROI ;
  70:  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 planned path

  28:  !save waypoints of the planned ;
  29:  !path to local variables one ;
  30:  !by one ;
  31:  CALL MM_GET_JPS(1,60,70,80) ;
  32:  CALL MM_GET_JPS(2,61,71,81) ;
  33:  CALL MM_GET_JPS(3,62,72,82) ;
  • MM_GET_JPS: The command to store the planned path.

  • 1: Store the first waypoint.

  • 60: The position register PR[60], which stores the joint positions of the first waypoint.

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

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

The entire command “CALL MM_GET_JPS(1,60,70,80)” stores the joint positions, label, and tool ID of the first waypoint in the specified registers.

In this example, the path planned by Mech-Viz consists of three waypoints: the first waypoint is the approach waypoint of picking (PR[60]), the second waypoint is the picking waypoint (PR[61]), and the third waypoint is the departure waypoint of picking (PR[62]). Please store the planned path based on the actual Mech-Viz project.

Move to the approach waypoint of picking

  34:  !follow the planned path to pick ;
  35:  !move to approach waypoint ;
  36:  !of picking ;
  37:J PR[60] 50% FINE    ;

The robot moves to the approach waypoint of picking (the position represented by PR[60]).

Move to the picking waypoint

  38:  !move to picking waypoint ;
  39:J PR[61] 10% FINE    ;

The robot moves to the picking waypoint (the position represented by PR[61]).

Set DO to Perform Picking

  40:  !add object grasping logic here, ;
  41:  !such as "DO[1]=ON" ;
  42:  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

  43:  !move to departure waypoint ;
  44:  !of picking ;
  45:J PR[62] 50% FINE    ;

The robot moves to the departure waypoint of picking (the position represented by PR[62]).

Move to the intermediate waypoint

  46:  !move to intermediate waypoint ;
  47:  !of placing ;
  48: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 command moves the robot in joint positions to a certain 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[3]) 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

  49:  !move to approach waypoint ;
  50:  !of placing ;
  51:L P[4] 1000mm/sec FINE Tool_Offset,PR[2]    ;
  • P[4]: The placing waypoint. You need to teach the placing waypoint (P[4]) 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[4]) 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

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

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

Set DO commands to perform placing

  54:  !add object releasing logic here, ;
  55:  !such as "DO[1]=OFF" ;
  56:  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

  57:  !move to departure waypoint ;
  58:  !of placing ;
  59:L P[4] 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

  60:  !move back to robot home position ;
  61: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.