FANUC Inline Measurement Program

Program Introduction

Description

The robot triggers Mech-Metrics to perform measurement using Mech-MSR and return the measurement results to Mech-Metrics.

File path

In the installation directory of Mech-MSR and Mech-Metrics: center/MSR_Interface/FANUC/MSR_Metrics_Sample1.LS.

Resource requirements

Mech-MSR solution and Mech-Metrics project

Prerequisites

  • Prepare on the inline measurement system side:

    • The current part is associated with the Mech-MSR solution in Mech-Metrics.

    • The current features are bound to the Mech-MSR project in Mech-Metrics.

    • The Mech-MSR solution and project are open in Mech-MSR.

  • Prepare the robot:

    • The operations in Set up Standard Interface Communication with FANUC have been completed.

    • The operations in FANUC Automatic Calibration have been completed.

    • The measurement positions have been taught.

    • The robot has been moved to the first measurement position.

    • The robot and camera have been preheated for 30 minutes before starting the measurement.

    • External lighting and temperature are stable before starting the measurement.

This example program is provided for reference only. Modify the program according to the actual scenario before use. Do not use this program directly.

Program Explanation

The following is the code of the MSR_Metrics_Sample1 example program and the related explanation.

   1:  !-------------------------------- ;
   2:  !FUNCTION: MSR_Metrics_Sample1 ;
   3:  !Mech-Mind, 2024-05-27 ;
   4:  !-------------------------------- ;
   5:   ;
   6:  !set current uframe NO. to 0 ;
   7:  UFRAME_NUM=0 ;
   8:  !set current tool NO. to 1 ;
   9:  UTOOL_NUM=1 ;
  10:  !move to robot home position ;
  11:  J P[4] 100% FINE    ;
  12:  !Init Socket!Modify IP Address ;
  13:  CALL MSR_INIT_SKT('8','192.168.1.20',30000,5) ;
  14:  !Set Custom Values ;
  15:  CALL MSR_MEAS_PAR(0,0,0,0,0,0,0,0) ;
  16:  !Start Measurement Task ;
  17:  CALL MSR_ST_MEAS(1,1,2,10,10,53) ;
  18:  !check whether metrics project ;
  19:  !has been triggered successfully ;
  20:  IF (R[53]<>8100),JMP LBL[99] ;
  21:  !Import Part ID During ;
  22:  !Measurement ;
  23:  CALL MSR_SET_WP(1,2,53) ;
  24:  !check whether Part ID has ;
  25:  !been imported successfully ;
  26:  IF (R[53]<>8103),JMP LBL[99] ;
  27:  !move to 1st image-capturing ;
  28:  !position ;
  29:  J P[1] 100% FINE    ;
  30:  !Set Robot_Id,Index ;
  31:  !R No.2:MM Status ;
  32:  CALL MSR_MEAS_FEAT(1,3,53) ;
  33:  !check whether feature measureme- ;
  34:  !nt has been run successfully ;
  35:  IF (R[53]<>8101),JMP LBL[99] ;
  36:  !move to 2ed image-capturing ;
  37:  !position ;
  38:  J P[2] 100% FINE    ;
  39:  !Set Robot_Id,Index ;
  40:  !R No.2:MM Status ;
  41:  CALL MSR_MEAS_FEAT(1,3,53) ;
  42:  !check whether feature measureme- ;
  43:  !nt has been run successfully ;
  44:  IF (R[53]<>8101),JMP LBL[99] ;
  45:  !move to 3rd image-capturing ;
  46:  !position ;
  47:  J P[3] 100% FINE    ;
  48:  !Set Robot_Id,Index ;
  49:  !R No.2:MM Status ;
  50:  CALL MSR_MEAS_FEAT(1,3,53) ;
  51:  !check whether feature measureme- ;
  52:  !nt has been run successfully ;
  53:  IF (R[53]<>8101),JMP LBL[99] ;
  54:  CALL MSR_END_MEAS(1,11,12,13,14,53) ;
  55:  !check whether metrics project ;
  56:  !has been ended successfully ;
  57:  IF (R[53]<>8102),JMP LBL[99] ;
  58:  !Query Part Historical Data ;
  59:  CALL MSR_VIEW_WP(1,2,53) ;
  60:  !check whether part historical ;
  61:  !data has been viewed ;
  62:  !successfully ;
  63:  IF (R[53]<>8104),JMP LBL[99] ;
  64:  WAIT   1.00(sec) ;
  65:  END ;
  66:   ;
  67:  LBL[99:handling error] ;
  68:  !add error handling logic here ;
  69:  !according to different ;
  70:  !error codes ;
  71:  !e.g.: R[53]=-99 means ;
  72:  !failed to open socket ;
  73:  PAUSE ;

The following table explains the logic of the preceding program. In the preceding code, the commented-out content starts with ! and is not explained in the table below.

Process Code and Description

Set the coordinate systems

   6:  !set current uframe NO. to 0 ;
   7:  UFRAME_NUM=0 ;
   8:  !set current tool NO. to 1 ;
   9:  UTOOL_NUM=1 ;
  • UFRAME_NUM=0: Sets the currently selected user coordinate system to No. 0 (the world coordinate system).

  • UTOOL_NUM=1: Sets the currently selected tool coordinate system to No. 1 (you need to set tool coordinate system No. 1 in advance).

Move to the specified position

  10:  !move to robot home position ;
  11:  J P[4] 100% FINE    ;
  • J: The joint movement command of the robot, indicating that the robot moves along an arc to the specified position.

  • P[4]: Specifies the target position that the robot moves to.

  • 100%: The percentage relative to the maximum movement speed.

  • FINE: The robot arrives at the specified position accurately.

Initialize the communication

12:  !Init Socket!Modify IP Address ;
13:  CALL MSR_INIT_SKT('8','192.168.1.20',30000,5) ;
  • CALL MSR_INIT_SKT('8','192.168.1.20',30000,5): Establishes the TCP communication between the inline measurement system and the robot.

    • '8': The robot port number.

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

    • 30000: The port number of the IPC.

    • 5: The communication timeout period, in minutes.

      You need to modify the IP address and port number of the IPC here according to actual conditions, and ensure that they are consistent with those set in Mech-MSR.

Set custom parameters

14:  !Set Custom Values ;
15:  CALL MSR_MEAS_PAR(0,0,0,0,0,0,0,0) ;
  • CALL MSR_MEAS_PAR(0,0,0,0,0,0,0,0): Sets the custom parameters.

    • 0,0,0,0,0,0,0,0: A set of custom parameters. A value of 0 indicates that the custom parameter is not used. Custom parameters are used only when more part information needs to be provided to Mech-Metrics.

Start the measurement

  16:  !Start Measurement Task ;
  17:  CALL MSR_ST_MEAS(1,1,2,10,10,53) ;
  18:  !check whether metrics project ;
  19:  !has been triggered successfully ;
  20:  IF (R[53]<>8100),JMP LBL[99] ;
  • CALL MSR_ST_MEAS(1,1,2,10,10,53): Starts the measurement task.

    • 1: The part ID.

    • 1: The ID of the string register that stores the part name.

    • 2: The ID of the string register that stores the part SN.

    • 10: The measurement group ID. The value range of measurement group IDs is 10 to 9999. The meanings of each value are as follows:

      • 10: ID of the fixed group.

      • 11–9999: Composite ID of the fixed group + rotating group.

      The specified measurement group ID must have been configured in the Measurement Group Editor interface.

      The measurement group ID here must be consistent with that set in Mech-Metrics.

    • 10: The ID of the numeric register that stores whether the execution mode returned by Mech-Metrics is loop execution or one-time execution.

    • 53: The ID of the numeric register that stores the command status code.

  • IF (R[53]<>8100),JMP LBL[99]: If the status code is not 8100, the start measurement task command is executed abnormally, and the program jumps to LBL[99] for error handling.

Import the part SN during the measurement

  21:  !Import Part ID During ;
  22:  !Measurement ;
  23:  CALL MSR_SET_WP(1,2,53) ;
  24:  !check whether Part ID has ;
  25:  !been imported successfully ;
  26:  IF (R[53]<>8103),JMP LBL[99] ;
  • CALL MSR_SET_WP(1,2,53): Sets the part information to input the part SN during the measurement.

    • 1: The part ID.

    • 2: The ID of the string register that stores the part SN to be input.

    • 53: The ID of the numeric register that stores the command status code.

  • IF (R[53]<>8103),JMP LBL[99]: If the status code is not 8103, the command for importing the part SN is executed abnormally, and the program jumps to LBL[99] for error handling.

Move the robot to the specified positions and perform feature measurement

  27:  !move to 1st image-capturing ;
  28:  !position ;
  29:J P[1] 100% FINE    ;
  30:  !Set Robot_Id,Index ;
  31:  !R No.2:MM Status ;
  32:  CALL MSR_MEAS_FEAT(1,3,53) ;
  33:  !check whether feature measureme- ;
  34:  !nt has been run successfully ;
  35:  IF (R[53]<>8101),JMP LBL[99] ;
  36:  !move to 2ed image-capturing ;
  37:  !position ;
  38:J P[2] 100% FINE    ;
  39:  !Set Robot_Id,Index ;
  40:  !R No.2:MM Status ;
  41:  CALL MSR_MEAS_FEAT(1,3,53) ;
  42:  !check whether feature measureme- ;
  43:  !nt has been run successfully ;
  44:  IF (R[53]<>8101),JMP LBL[99] ;
  45:  !move to 3rd image-capturing ;
  46:  !position ;
  47:J P[3] 100% FINE    ;
  48:  !Set Robot_Id,Index ;
  49:  !R No.2:MM Status ;
  50:  CALL MSR_MEAS_FEAT(1,3,53) ;
  51:  !check whether feature measureme- ;
  52:  !nt has been run successfully ;
  53:  IF (R[53]<>8101),JMP LBL[99] ;
  • J P[1] 100% FINE: Moves accurately to the first measurement position at a speed of 100%.

  • CALL MSR_MEAS_FEAT(1,3,53): The robot triggers the Mech-MSR project with part ID 1 and feature measurement ID 3 to run.

    • 1: The part ID.

    • 3: The feature measurement ID.

    • 53: The ID of the numeric register that stores the command status code.

      The feature ID in each call needs to be modified according to actual conditions.

  • IF (R[53]<>8101),JMP LBL[99]: If the status code is not 8101, the run feature measurement command is executed abnormally, and the program jumps to LBL[99] for error handling.

  • J P[2] 100% FINE: Moves accurately to the second measurement position at a speed of 100%.

  • J P[3] 100% FINE: Moves accurately to the third measurement position at a speed of 100%.

    You need to teach these three measurement positions in advance. For the teaching method, refer to the Teach the calibration start point section in FANUC Automatic Calibration.

End the measurement

  54:  CALL MSR_END_MEAS(1,11,12,13,14,53) ;
  55:  !check whether metrics project ;
  56:  !has been ended successfully ;
  57:  IF (R[53]<>8102),JMP LBL[99] ;
  • CALL MSR_END_MEAS(1,11,12,13,14,53): Ends the measurement task, and saves and returns the measurement results.

    • 1: The part ID.

    • 11: The ID of the numeric register that stores the part judgment result. 1 indicates OK, and 0 indicates NG.

    • 12,13,14: The IDs of numeric registers for storing the number of part features whose value exceeds tolerance 1, 2, and 3.

    • 53: The ID of the numeric register that stores the command status code.

  • IF (R[53]<>8102),JMP LBL[99]: If the status code is not 8102, the stop measurement task command is executed abnormally, and the program jumps to LBL[99] for error handling.

Query historical data

  58:  !Query Part Historical Data ;
  59:  CALL MSR_VIEW_WP(1,2,53) ;
  60:  !check whether part historical ;
  61:  !data has been viewed ;
  62:  !successfully ;
  63:  IF (R[53]<>8104),JMP LBL[99] ;
  • CALL MSR_VIEW_WP(1,2,53): Inputs the part SN to Mech-Metrics and switches the main interface of Mech-Metrics to the data view of the part.

    • 1: The part ID.

    • 2: The ID of the string register that stores the part SN to be input.

    • 53: The ID of the numeric register that stores the command status code.

  • IF (R[53]<>8104),JMP LBL[99]: If the status code is not 8104, the query historical data command is executed abnormally, and the program jumps to LBL[99] for error handling.

End the program and handle errors

  64:  WAIT   1.00(sec) ;
  65:  END ;
  66:   ;
  67:  LBL[99:handling error] ;
  68:  !add error handling logic here ;
  69:  !according to different ;
  70:  !error codes ;
  71:  !e.g.: R[53]=-99 means ;
  72:  !failed to open socket ;
  73:  PAUSE ;
  • WAIT 1.00(sec): Waits for 1 second.

  • END: Ends the program.

  • LBL[99:handling error]: The error handling label. When the command status code is abnormal, the program jumps here.

  • PAUSE: Pauses the program. You can add custom error handling logic at LBL[99] according to different error codes (for example, R[53]=-99 indicates that the communication connection failed to be established).

Is this page helpful?

You can give a feedback in any of the following ways:

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.