Skip to content

Robotic Arm Connection Configuration ArmRobotic

This module provides interfaces for API and robotic arm initialization, including API version number query, API initialization, robotic arm connection/disconnection, log setting, robotic arm simulation/real mode setting, robotic arm information acquisition, motion information, and registration of robotic arm real-time state callback function, etc.

Query sdk version number rm_api_version()

  • Method prototype:
C
char* rm_api_version(void)
  • Return value:
ParameterTypeDescription
/char*Returned version number
  • Usage demo
C
char *version = rm_api_version();
printf("api version: %s\n", version);

Initialize thread mode rm_init()

  • Method prototype:
C
int rm_init(rm_thread_mode_e mode)

Jump to rm_thread_mode_e for details of types

  • Parameter description:
ParameterDescription
mode:RM_SINGLE_MODE_ESingle-thread mode, waiting for data return in a non-blocking manner.
mode:RM_DUAL_MODE_EDual-thread mode, adding a receiving thread to monitor data in the queue.
mode:RM_TRIPLE_MODE_ETriple-thread mode, adding a thread to monitor UDP interface data based on the dual-thread mode.
  • Return value:
ParameterTypeDescription
0intSuccess
-1intCreation of thread fails. Check the log for specific errors
  • Usage demo
C
// The initial thread mode is triple-thread mode
rm_init(RM_TRIPLE_MODE_E);

Destroy all threads rm_destory()

Note: This will disable all connections.

  • Method prototype:
C
int rm_destory(void )
  • Return value:
ParameterTypeDescription
0intSuccess
  • Usage demo
C
rm_destory();

Configure log printing rm_set_log_call_back()

  • Method prototype:
C
void rm_set_log_call_back(void(*)(const char *message, va_list args) LogCallback, int level)

Jump to rm_thread_mode_e for details of types

  • Parameter description:
ParameterDescription
LogCallbackLog printing callback function.
levelLog printing level. 0: debug level; 1: info level; 2: warn level; 3: error level.
  • Usage demo
C
// Get the current time information
char *get_cur_time()
{
  static char s[32] = {0};
  struct tm* ltime;
  struct timeval stamp;
  gettimeofday(&stamp, NULL);
  ltime = localtime(&stamp.tv_sec);
  strftime(s, 20, "%Y%m%d %H:%M:%S", ltime);
  return s;
}

// Log callback function
void api_log(const char* message, va_list args) {
    printf("[%s]: ",get_cur_time());
    vfprintf(stdout, message, args);
}

// Register the log printing callback function to print the error-level log information
rm_set_log_call_back(api_log, 3);

Create a robotic arm control instance rm_create_robot_arm()

  • Method prototype:
C
rm_robot_handle* rm_create_robot_arm(const char * ip, int port)

Jump to rm_robot_handle for details of the structure

  • Parameter description:
ParameterDescription
ipIP address of robotic arm.
portPort No. of robotic arm.
  • Return value:

After the instance is created successfully, the robotic arm control rm_robot_handle handle ID will be returned. The ID will be greater than 0 if connection succeeds. If connection fails, "-1" will be returned, and if the maximum number of connections is reached, "void" will be returned.

  • Usage demo
C
rm_robot_handle *robot_handle = rm_create_robot_arm("192.168.1.18",8080);
if(robot_handle->id == -1)
{
    rm_delete_robot_arm(robot_handle);
    printf("arm connect err...\n");
}
else if(robot_handle != NULL)
{
    printf("connect success,arm id %d\n",robot_handle->id);
}

Delete the specified robotic arm instance rm_delete_robot_arm()

  • Method prototype:
C
int rm_delete_robot_arm(rm_robot_handle * handle)

Jump to rm_robot_handle for details of the structure

  • Parameter description:
VariableDescription
handleRobotic arm handle to delete.
  • Return value:
ParameterTypeDescription
0intSuccess.
-1intNo corresponding handle found, the handle is either void or has been deleted.
  • Usage demo
C
rm_delete_robot_arm(robot_handle);

Set robotic arm simulation/real mode rm_set_arm_run_mode()

  • Method prototype:
C
int rm_set_arm_run_mode(rm_robot_handle * handle,int mode)

Jump to rm_robot_handle for details of the structure

  • Parameter description:
ParameterDescription
handleRobotic arm control handle.
mode0: simulation mode; 1: real mode.
  • Return value:
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
C
// Set the robotic arm to simulation mode
int ret = rm_set_arm_run_mode(robot_handle, 0);   
if (ret == 0) {  
    // Succeed  
    printf("Robot arm run mode set successfully.\n");  
} else {  
    // Fail
    printf("Failed to set robot arm run mode. Error code: %d\n", ret);  
}

Get robotic arm simulation/real mode rm_get_arm_run_mode()

  • Method prototype:
C
int rm_get_arm_run_mode(rm_robot_handle * handle,int * mode)

Jump to rm_robot_handle for details of the structure

  • Parameter description:
ParameterDescription
handleRobotic arm control handle.
mode0: simulation mode; 1: real mode.
  • Return value:
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
C
int mode;
ret = rm_get_arm_run_mode(robot_handle, &mode);   
if (ret == 0) {  
    // Succeed  
    printf("Robot arm run mode get successfully. Current run mode: %d\n", mode);  
} else {  
    // Handle in case of setting failure
    printf("Failed to get robot arm run mode. Error code: %d\n", ret);  
}

Get basic information of robotic arm rm_get_robot_info()

  • Method prototype:
C
int rm_get_robot_info(rm_robot_handle * handle,rm_robot_info_t * robot_info)

Jump to rm_robot_handle and rm_robot_info_t for details of the structure

  • Parameter description:
ParameterTypeDescription
handleInputRobotic arm control handle.
robot_infoInputStructure storing the basic information of robotic arm.
  • Return value:
ParameterTypeDescription
0intSuccess.
-1intNo corresponding handle found, the handle is either void or has been deleted.
-2intThe obtained basic information of robotic arm is invalid. Check if the handle has been deleted.
  • Usage demo
C
rm_robot_info_t robot_info;
ret = rm_get_robot_info(robot_handle, &robot_info);
printf("Get robot info result : %d\n", ret);
printf("Robot info : %d %d %d \n", robot_info.arm_dof,robot_info.arm_model,robot_info.force_type);

Register the robotic arm event callback function rm_get_arm_event_call_back()

  • Method prototype:
C
void rm_get_arm_event_call_back(rm_event_callback_ptr event_callback)

Here the robotic arm event callback function rm_event_callback_ptr is used.
Method prototype: typedef void(* rm_event_callback_ptr) (rm_event_push_data_t data).
Jump to rm_realtime_arm_joint_state_t for details of the structure.

Note: This function cannot be used to get the in-position information in single-thread mode.

  • Parameter description:
ParameterValueDescription
handleUser-definedRobotic arm control handle.
event_callbackUser-definedRobotic arm event callback function. This function receives rm_event_push_data_t data as parameters, and returns no value.
  • Usage demo
C
// Robotic arm event callback function
void callback_event(rm_event_push_data_t data)
{
    printf("CallbackCallbackCallbackCallbackCallback\n");
    switch (data.event_type)
    {
    case RM_CURRENT_TRAJECTORY_STATE_E:
        printf("Current trajectory running result: %d, device in position: %d, existence of following trajectory: %d\n",data.trajectory_state,data.device, data.trajectory_connect);
        break;
    case RM_PROGRAM_RUN_FINISH_E:
        printf("Online program running ends, ending program ID: %d\n", data.program_id);
        break;
    default:
        break;
    }
}
// Register the robotic arm event callback function
rm_get_arm_event_call_back(callback_event);