Skip to content

Robotic Arm Connection Control ArmRobotic ​

Operations for connecting and disconnecting of, and setting up logs for the robotic arm.

Initialize thread mode__init__()
​

This is the constructor function.

  • Method prototype:
python
__init__(self, mode: rm_thread_mode_e = None):

Jump to Type description for details ofrm_thread_mode_e

  • Parameter description:
ParameterTypeDescription
moderm_thread_mode_eRM_SINGLE_MODE_E: single-thread mode, waiting for data return in a non-blocking manner; RM_DUAL_MODE_E: dual-thread mode, adding a receiving thread to monitor data in the queue; RM_TRIPLE_MODE_E: triple-thread mode, adding a thread to monitor UDP interface data based on the dual-thread mode.
  • Return value:
ParameterTypeDescriptionHandling Suggestions
0intSuccess.-
-1intCreation of thread fails. Check the log for specific errorsObtain detailed error information when thread creation fails through logs:
On Windows, when a thread creation error occurs, the specific error code can be obtained by calling the GetLastError function, and its definition can be viewed in the Windows header file <windows.h>.
On Linux, when a thread creation error occurs, the return value of pthread_create is returned, and its return value definition can be viewed in <pthread.h>.
  • Usage demo
python
from Robotic_Arm.rm_robot_interface import *

# Initialize in triple-thread mode
arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)

# Create the robotic arm connection and print the connection ID
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
print(handle.id)

# End the control of the robotic arm and delete the specified robotic arm object
arm.rm_delete_robot_arm()

Create robotic arm connection control handlerm_create_robot_arm() ​

  • Method prototype:
python
rm_create_robot_arm(self, ip: str, port: int, level: int = 3, log_func: CFUNCTYPE = None) -> rm_robot_handle:

Jump to rm_robot_handle for details of the structure.

  • Parameter description:
ParameterTypeDescription
ipstrIP address of the robotic arm.
portintPort number of the robotic arm.
levelintLog printing level (3 by default): - 0: debug mode; - 1: info mode; - 2: warning mode; - 3: error mode.
log_funcCFUNCTYPECustom log printing function, currently not supported in the Python API version (None by default).
  • Return value:
ParameterTypeDescription
/rm_robot_handleRobotic arm handle, which includes the arm's ID identifier.
  • Usage demo Connect two robotic arms via the RoboticArm class and query their states:
python
from Robotic_Arm.rm_robot_interface import *

# Initialize in triple-thread mode
arm1 = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)
arm2 = RoboticArm()

# Create the robotic arm connection and print the connection ID
handle1 = arm1.rm_create_robot_arm("192.168.1.18", 8080)
print(handle1.id)
handle2 = arm2.rm_create_robot_arm("192.168.1.19", 8080)
print(handle2.id)

# Get the current robotic arm state
print(arm1.rm_get_current_arm_state())
print(arm2.rm_get_current_arm_state())

# Disconnect all connections and destroy threads
RoboticArm.rm_destroy()

Delete the specified robotic arm objectrm_delete_robot_arm()
​

  • Method prototype:
python
rm_delete_robot_arm(self) -> int:
  • Return value:
ParameterTypeDescriptionHandling Suggestions
0intSuccess.-
-1intNo corresponding handle found, the handle is either void or has been deleted.Check if the handle parameter passed in is valid.
  • Usage demo
python
from Robotic_Arm.rm_robot_interface import *

# Initialize in triple-thread mode
arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)

# Create the robotic arm connection and print the connection ID
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
print(handle.id)

# Delete the specified robotic arm object
arm.rm_delete_robot_arm()

Close all robotic arm connectionsrm_destroy() ​

Destroy all threads.

  • Method prototype:
python
rm_destroy(self) -> int:
  • Return value:
ParameterTypeDescription
0intSuccess
  • Usage demo
python
from Robotic_Arm.rm_robot_interface import *

# Initialize in triple-thread mode
arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)

# Create the robotic arm connection and print the connection ID
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
print(handle.id)

# Disconnect all connections
RoboticArm.rm_destroy()

Save logs to filerm_set_log_save() ​

  • Method prototype:
python
rm_set_log_save(self, path) -> None:
  • Parameter description:
ParameterTypeDescription
pathstringPath to save the log file.
  • Usage demo
python
from Robotic_Arm.rm_robot_interface import *

# Initialize in triple-thread mode
arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)

# Create the robotic arm connection and print the connection ID
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
print(handle.id)

arm.rm_set_log_save("/home/aisha/work/rm_log.txt")

# Delete the specified robotic arm object
arm.rm_delete_robot_arm()

Set real/simulation moderm_set_arm_run_mode() ​

  • Method prototype:
python
rm_set_arm_run_mode(self, mode: int) -> int:
  • Parameter description:
ParameterTypeDescription
modeintMode, 0: simulation, 1: real.
  • Return value: State codes executed by functions:

    0 represents success. For other error codes, please refer to the API2 Error Codes.

  • Usage demo

python
from Robotic_Arm.rm_robot_interface import *

# Initialize in triple-thread mode
arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)

# Create the robotic arm connection and print the connection ID
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
print(handle.id)

# Set the robotic arm to simulation mode
arm.rm_set_arm_run_mode(0)

# Delete the specified robotic arm object
arm.rm_delete_robot_arm()

Get real/simulation moderm_get_arm_run_mode() ​

  • Method prototype:
python
rm_get_arm_run_mode(self) -> tuple[int, int]:
  • Return value:

    tuple[int, int]: a tuple containing two elements.

    1. State codes executed by functions:

      0 represents success. For other error codes, please refer to the API2 Error Codes.

    2. Mode:

    ParameterTypeDescription
    /int0: simulation, 1: real.
  • Usage demo

python
from Robotic_Arm.rm_robot_interface import *

# Initialize in triple-thread mode
arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)

# Create the robotic arm connection and print the connection ID
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
print(handle.id)

# Get the current running mode of the robotic arm
print(arm.rm_get_arm_run_mode())

# Delete the specified robotic arm object
arm.rm_delete_robot_arm()

Get basic information of robotic arm rm_get_robot_info()
​

  • Method prototype:
python
rm_get_robot_info(self) -> tuple[int, dict[str, any]]:
  • Return value:

    tuple[int, dict[str, any]]: a tuple containing two elements.

    1. The status code returned by the function. This interface uses the dedicated meanings in the table below.
    Return valueDescriptionHandling Suggestions
    0Succeeded.The returned information dictionary can be used.
    -1No matching handle was found; the handle is empty or has been deleted.Check the robotic arm connection and whether the handle is valid.
    -2The obtained robotic arm basic information is invalid.Check whether the handle has been deleted. This is not the generic "receive timeout".
    -3For models that require distinguishing the 4th-generation six-axis force naming, the controller software version has not been successfully obtained or parsed, so the name cannot be determined.Check the return value of rm_get_arm_software_info(); query again after the software information is obtained and parsed successfully.
    1. dict[str, any]: the robotic arm basic information dictionary.
    ParameterTypeDescription
    arm_dofintNumber of degrees of freedom of the robotic arm.
    arm_modelstrRobotic arm model name.
    force_typestrRobotic arm end force control type name.
    robot_controller_versionintController generation, 4: 4th generation; 3: 3rd generation.

    Jump to rm_robot_info_t for details of the structure.

  • Usage demo

python
from Robotic_Arm.rm_robot_interface import RoboticArm, rm_thread_mode_e

arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
if handle.id <= 0:
    raise RuntimeError("Failed to connect to the robot")

try:
    ret, software_info = arm.rm_get_arm_software_info()
    if ret != 0:
        print("Failed to obtain or parse the controller software information, status code:", ret)
    else:
        ret, robot_info = arm.rm_get_robot_info()
        if ret == 0:
            print(robot_info)
        else:
            print("Failed to get the robotic arm basic information, status code:", ret)
finally:
    arm.rm_delete_robot_arm()

Register the robotic arm event callback functionrm_get_arm_event_call_back() ​

Data is returned when the robotic arm completes a move-to-position command or finishes executing a file run command.

  • Method prototype:
python
rm_get_arm_event_call_back(self, event_callback: rm_event_callback_ptr):
  • Parameter description:
ParameterTypeDescription
event_callbackrm_event_callback_ptrRobotic arm event callback function. This callback function receives data of rm_event_push_data_t type as its parameter and does not return any value.

WARNING

The callback function cannot be used in single-thread mode.

  • Usage demo
python
# The following is an example of how to register a robotic arm event callback function:
# In this example, we define a function named `event_callback` to handle the robotic arm events and register it as a callback function.
When a robotic arm event occurs, the `event_callback` function will be called and receive an object containing event data as its parameter
import time
from Robotic_Arm.rm_robot_interface import *

def event_func(data:rm_event_push_data_t) -> None:
    print("The motion is complete, the arm is in place.")
    # Determine the interface type
    if data.event_type == 1:  # Trajectory planning completed
        print("Motion result:", data.trajectory_state)
        print("Current device:", data.device)
        print("Whether to connect to the next trajectory:", data.trajectory_connect)
    elif data.event_type == 2:  # Online programming file execution completed
        print("Online programming file ended id:", data.program_id)

# Initialize in triple-thread mode
arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E)

# Create the robotic arm connection and print the connection ID
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
print(handle.id)

event_callback = rm_event_callback_ptr(event_func)
arm.rm_get_arm_event_call_back(event_callback)

# Non-blocking joint motion
ret = arm.rm_movej([0, 30, 60, 0, 90, 0], 50, 0, 0, 0)
print("movej: ", ret)

# Wait for printing data
time.sleep(10)

# Delete the specified robotic arm object
arm.rm_delete_robot_arm()

Set Global Timeout rm_set_timeout() ​

Set the global timeout, Unit: ms. When there is significant network latency, you may appropriately increase the timeout duration.

  • Method prototype:
python
rm_set_timeout(self,timeout: int) -> None:
  • Parameter description:
ParameterTypeDescription
timeoutintThe timeout duration for receiving instructions from the controller. The default timeout for most interfaces is 500ms. Unit: ms.
  • Usage demo
python
from Robotic_Arm.rm_robot_interface import *
# Initialize to triple-thread mode
arm = RoboticArm(rm_thread_mode_e.RM_TRIPLE_MODE_E) 
# Create a robotic arm connection and print the connection ID
handle = arm.rm_create_robot_arm("192.168.1.18", 8080)
print(handle.id)
# Set the global timeout to 1000ms
arm.rm_set_timeout(1000)
# Non-blocking joint movement
ret = arm.rm_movej([0, 30, 60, 0, 90, 0], 50, 0, 0, 0)
print("movej: ", ret)
# Delete the specified robotic arm object
arm.rm_delete_robot_arm()