Example program 2: MM_S2_Viz_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

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_S2_Viz_Basic path.

Description

The robot triggers the Mech-Viz project to run, and then obtains the planned path for picking and placing.

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_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.

    — 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()
    --trigger  Mech-Viz project
    TOP_Status = MM_Start_Viz(2)
    print("Vision system status code:",TOP_Status)
    --check whether the Mech-Vision project has been triggered successfully
    if TOP_Status ~= 2103 then
        print("Abnormal vision system status!!!",TOP_Status)
        Pause()
    end
    --Set branch
    TOP_Status = MM_Set_Branch(1,1)
    print("Vision system status code:",TOP_Status)
    --check whether the branch has been set successfully
    if TOP_Status ~= 2105 then
        print("Failed to set the branch!!!",TOP_Status)
        Pause()
    end
    --get planned path
    TOP_Status,TOP_Last_Data,TOP_Pos_Num,TOP_VisPosNum=MM_Get_VizData(1)
    print("Planned path:",TOP_Status,TOP_Last_Data,TOP_Pos_Num)
    --check whether planned path has been got from Mech-Viz successfully
    if TOP_Status ~= 2100 then
        print("Failed to get the planned data!!!",TOP_Status)
        Pause()
    end
    --save waypoints of the planned path to local variables one by one
    MM_Get_JPR(1,10,20,30)
    MM_Get_JPR(2,11,21,31)
    MM_Get_JPR(3,12,22,32)
    --move to picking waypoint
    MovJ(JPR[10],{cnt = -1})
    --Mov grabbing point
    MovJ(JPR[11],{cnt = -1})
    --add object grasping logic here, such as "setdo DO_1, 1;"
    Pause()
    --move to departure waypoint of picking
    MovJ(JPR[12],{cnt = -1})

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

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.

Start VIZ and return the status code

    --trigger  Mech-Viz project
    TOP_Status = MM_Start_Viz(2)
  • MM_Start_Viz:Command to start Mech-Viz.

  • 2: Set the pose type to 2

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 ~= 2103 then
        print("Abnormal vision system status!!!",TOP_Status)
        Pause()
    end

Set the Exit Port for the Branch by Msg Step in Mech-Viz

    --Set branch
    TOP_Status = MM_Set_Branch(1,1)
  • MM_Set_Branch: The command to set the exit port for the Branch by Msg Step in Mech-Viz.

  • First 1: The Step ID of the Branch by Msg Step.

  • Second 1: The Mech-Viz project takes exit port 0 of the Branch by Msg Step. Note that if this parameter is set to N, the exit port is N-1.

Print the status code and verify

    print("Vision system status code:",TOP_Status)
    --check whether the branch has been set successfully
    if TOP_Status ~= 2105 then
    print("Failed to set the branch!!!",TOP_Status)
    Pause()
    end

Obtain the planned path

    --get planned path{
    TOP_Status,TOP_Last_Data,TOP_Pos_Num,TOP_VisPosNum=MM_Get_VizData(1)}
  • MM_Get_VizData: The command to obtain the path planned by Mech-Viz.

  • 1: Obtain waypoints in the form of joint angles.

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

Print the status code and verify

    print("Planned path:",TOP_Status,TOP_Last_Data,TOP_Pos_Num)
    --check whether planned path has been got from Mech-Viz successfully
    if TOP_Status ~= 2100 then
    print("Failed to get the planned data!!!",TOP_Status)
    Pause()
    end

Store the planned path

    --save waypoints of the planned path to local variables one by one
    MM_Get_JPR(1,10,20,30)
    MM_Get_JPR(2,11,21,31)
    MM_Get_JPR(3,12,22,32)
  • MM_Get_JPR: The command to store the planned path. Take the first item as an example

  • 1: Store the first waypoint.

  • 10: The joint angles of the first path will be saved to position registerJPR[10].

  • 20: The label will be saved to numeric register HR[20].

  • 30: The motion speed will be saved to numeric registerHR[30].

Move to the approach waypoint of picking

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

Move to the picking waypoint

    --Mov grabbing point
    MovJ(JPR[11],{cnt = -1})

The robot moves to the approach waypoint of picking.

Set DO commands to perform placing

    --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 the robot to the departure waypoint of placing

    --move to departure waypoint of picking
    MovJ(JPR[12],{cnt = -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 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.