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 typeList for details ofrm_thread_mode_e

  • Parameter description:
ParameterTypeDescription
moderm_robot_arm_model_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.
  • 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_destory()

Delete the specified robotic arm objectrm_delete_robot_arm()

  • Method prototype:
python
rm_delete_robot_arm(self) -> int:
  • Return value:
ParameterTypeDescription
/int0 indicates it is successfully operated, otherwise, it means failure.
  • 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_destory()

Destroy all threads.

  • Method prototype:
python
rm_destory(self) -> int:
  • Return value:
ParameterTypeDescription
/int0 indicates it is successfully operated, otherwise, it means failure.
  • 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_destory()

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:
ParameterTypeDescription
0intSuccess.
1intThe controller returns false, indicating that the parameters are sent incorrectly or the robotic arm state is wrong.
-1intThe data transmission fails, indicating that a problem occurs during the communication.
-2intThe data reception fails, indicating that a problem occurs during the communication, or the controller has a return timeout.
-3intThe return value parse fails, indicating that the received data format is incorrect or incomplete.
  • 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: | Parameter | Type | Description | | :--- | :--- | :---| | 0 | int | Success. | | 1 | int | The controller returns false, indicating that the parameters are sent incorrectly or the robotic arm state is wrong. | | -1 | int | The data transmission fails, indicating that a problem occurs during the communication. | | -2 | int | The data reception fails, indicating that a problem occurs during the communication, or the controller has a return timeout. | | -3 | int | The return value parse fails, indicating that the received data format is incorrect or incomplete. |

  2. Mode: | Parameter | Type | Description | | :--- | :--- | :---| | / | int | 0: 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_set_arm_run_mode(0))

# 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. State codes executed by functions: | Parameter | Type | Description | | :--- | :--- | :---| | 0 | int | Success. | | -1 | int | No corresponding handle found, the handle is either void or has been deleted. | | -2 | int | The obtained basic information of the robotic arm is invalid. Please check if the handle has been deleted. |

  2. Return the current tool frame dictionary: | Parameter | Type | Description | | :--- | :--- | :---| | dict[str, any] | str | Return the dictionary of the current tool frame, key: field names of rm_robot_info_t. |

  • 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 robotic arm model, end effector force sensor version, and degrees of freedom information
print(arm.rm_get_robot_info())

# Delete the specified robotic arm object
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.

Note: 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
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.codeKey == 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()