Example Program 1: MM_S1_Vis_Basic

You are currently viewing the documentation for a pre-release version (2.2.0). To access documentation for other versions, click the "Switch Version" button located in the upper-right corner of the page.

■ If you're unsure about the version of the product you are using, please contact Mech-Mind Technical Support for assistance.

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 Name

You can navigate to the installation directory of Mech-Vision and Mech-Viz and find the file by using the Communication Component/Robot_Interface/TOPSTAR/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.

  — This is a LUA program.
  require("MM_Module")
  IP_Address = "192.168.1.8"
  Server_Port = 50000
  Time_Out = 60
  --initialize communication parameters (initialization is required only once)
  MM_Init_Socket(IP_Address,Server_Port,Time_Out)
  --close socket connection
  MM_Close_Socket()
  --open socket connection
  MM_Open_Socket()
  --switch recipe of NO.1 Mech-Vision project
  TOP_Status=MM_Switch_Model(1,1)
  print("Vision system status code:",TOP_Status)
  ---check whether the recipe is switched successful
  if TOP_Status ~= 1107 then
    print("Abnormal vision system status!!!",TOP_Status)
    Pause()
  end
  --trigger NO.1 Mech-Vision project
  TOP_Status = MM_Start_Vis(1,1,1,JP[100])
  print("Vision system status code:",TOP_Status)
  --check whether the Mech-Vision project has been triggered successfully
  if TOP_Status ~= 1102 then
    print("Abnormal vision system status!!!",TOP_Status)
    Pause()
  end
  --get vision result from NO.1 Mech-Vision project
  TOP_Status,TOP_Last_Data,TOP_Pos_Num = MM_Get_VisData(1)
  print("Vision result:",TOP_Status,TOP_Last_Data,TOP_Pos_Num)
  --check whether vision result has been got successfull
  if TOP_Status ~= 1100 then
    print("Failed to obtain vision result!!!",TOP_Status)
    Pause()
  end
  --save first vision point data to local variables
  MM_Get_Pose(1,20,50,60)
  local pose1 = NewPose(0, 0, 200, 0, 0, 0)
  --move to approach waypoint of picking
  MovL(PR[20],{cnt = -1,uof = pose1})
  --move to picking waypoint
  MovL(PR[20],{cnt = -1})
  --add object grasping logic here, such as "setdo DO_1, 1
  Pause()
  --move to departure waypoint of picking
  MovL(PR[20],{cnt = -1,uof = pose1})

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

Include the MM_Module header file

  -- This is a LUA program.
  require("MM_Module")

Initialize communication parameters

  IP_Address = "192.168.1.8"
  Server_Port = 50000
  Time_Out = 60
  --initialize communication parameters (initialization is required only once)
  MM_Init_Socket(IP_Address,Server_Port,Time_Out)
  --close socket connection
  MM_Close_Socket()
  --open socket connection
  MM_Open_Socket()
  • MM_INIT_SOCKET: The command to initialize the communication.

    Input Parameters:

    • '50000': The port number of the IPC.

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

    • '60': The communication timeout wait time is 60 seconds.

  • MM_Close_Socket: Command to close the communication.

  • MM_Open_Socket: Command to establish the communication.

Close the communication first, then reconnect to ensure no project is currently connected.

Switch Mech-Vision Parameter Recipe

  --switch recipe of NO.1 Mech-Vision project
  TOP_Status=MM_Switch_Model(1,1)
  • MM_Switch_Model: The command to switch the Mech-Vision parameter recipe.

  • First 1: The Mech-Vision project ID.

  • Second 1: The ID of the parameter recipe in the Mech-Vision project.

Print the status code and verify

  print("Vision system status code:",TOP_Status)
  ---check whether the recipe is switched successful
  if TOP_Status ~= 1107 then
    print("Abnormal vision system status!!!",TOP_Status)
    Pause()
  end

Trigger the Mech-Vision project to run

  --trigger NO.1 Mech-Vision project
  TOP_Status = MM_Start_Vis(1,1,1,JP[100])
  print("Vision system status code:",TOP_Status)
  • MM_Start_Vis: The command to trigger the Mech-Vision project to run.

  • First 1: The Mech-Vision project ID.

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

  • Third 1:Specify that the robot flange pose must be input to the ** project.

  • JP[100]: Custom joint positions. The joint positions in this example program are of no practical use but must be set.

Print the status code and verify

  print("Vision system status code:",TOP_Status)
  --check whether the Mech-Vision project has been triggered successfully
  if TOP_Status ~= 1102 then
    print("Abnormal vision system status!!!",TOP_Status)
    Pause()
  end

Get Vision Result

  --get vision result from NO.1 Mech-Vision project
  TOP_Status,TOP_Last_Data,TOP_Pos_Num = MM_Get_VisData(1)
  • MM_GET_VISDATA: The command to obtain the vision result.

  • 1: The Mech-Vision project ID.

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.

Print the vision results and verify

  print("Vision result:",TOP_Status,TOP_Last_Data,TOP_Pos_Num)
  --check whether vision result has been got successfull
  if TOP_Status ~= 1100 then
    print("Failed to obtain vision result!!!",TOP_Status)
    Pause()
  end

Store the vision result

  --save first vision point data to local variables
  MM_Get_Pose(1,20,50,60)
  local pose1 = NewPose(0, 0, 200, 0, 0, 0)
  • MM_GET_POSE: The command to store the vision result.

  • 1: The first vision point is stored.

  • 60: The position register JPR[20], which stores the tool pose of the first vision point, i.e., the tool pose at the pick point.

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

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

  • NewPose: Declare the offset variable.

This instruction writes the tool pose, label, and end-effector tool number of the first vision point into the specified registers, respectively.

Move to the approach waypoint of picking

  --move to approach waypoint of picking
  MovL(PR[20],{cnt = -1,uof = pose1})

Move to the picking waypoint

  --move to picking waypoint
  MovL(PR[20],{cnt = -1})

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

Set DO commands to perform picking

  --add object grasping logic here, such as "setdo DO_1, 1;"
  Pause()

After the robot moves to the picking waypoint, you can set a DO command (such as setdo DO_1, 1;) 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

  --move to departure waypoint of picking
  MovL(PR[20],{cnt = -1,uof = pose1})  ;

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 Z-axis negative offset based on the actual scenario to ensure that no collision occurs during the departing process.

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.