C and C++:
Robotic Arm Connection ConfigurationArmRobotic
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:
char* rm_api_version(void)
- Return value:
Parameter | Type | Description |
---|---|---|
/ | char* | Returned version number |
- Usage demo
char *version = rm_api_version();
printf("api version: %s\n", version);
Initialize thread mode rm_init()
- Method prototype:
int rm_init(rm_thread_mode_e mode)
Jump to rm_thread_mode_e for details of types
- Parameter description:
Parameter | Description |
---|---|
mode:RM_SINGLE_MODE_E | Single-thread mode, waiting for data return in a non-blocking manner. |
mode:RM_DUAL_MODE_E | Dual-thread mode, adding a receiving thread to monitor data in the queue. |
mode:RM_TRIPLE_MODE_E | Triple-thread mode, adding a thread to monitor UDP interface data based on the dual-thread mode. |
- Return value:
Parameter | Type | Description |
---|---|---|
0 | int | Success |
-1 | int | Creation of thread fails. Check the log for specific errors |
- Usage demo
// 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:
int rm_destory(void )
- Return value:
Parameter | Type | Description |
---|---|---|
0 | int | Success |
- Usage demo
rm_destory();
Configure log printing rm_set_log_call_back()
- Method prototype:
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:
Parameter | Description |
---|---|
LogCallback | Log printing callback function. |
level | Log printing level. 0: debug level; 1: info level; 2: warn level; 3: error level. |
- Usage demo
// 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:
rm_robot_handle* rm_create_robot_arm(const char * ip, int port)
Jump to rm_robot_handle for details of the structure
- Parameter description:
Parameter | Description |
---|---|
ip | IP address of robotic arm. |
port | Port 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
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:
int rm_delete_robot_arm(rm_robot_handle * handle)
Jump to rm_robot_handle for details of the structure
- Parameter description:
Variable | Description |
---|---|
handle | Robotic arm handle to delete. |
- Return value:
Parameter | Type | Description |
---|---|---|
0 | int | Success. |
-1 | int | No corresponding handle found, the handle is either void or has been deleted. |
- Usage demo
rm_delete_robot_arm(robot_handle);
Set robotic arm simulation/real mode rm_set_arm_run_mode()
- Method prototype:
int rm_set_arm_run_mode(rm_robot_handle * handle,int mode)
Jump to rm_robot_handle for details of the structure
- Parameter description:
Parameter | Description |
---|---|
handle | Robotic arm control handle. |
mode | 0: simulation mode; 1: real mode. |
- Return value:
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. |
- Usage demo
// 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:
int rm_get_arm_run_mode(rm_robot_handle * handle,int * mode)
Jump to rm_robot_handle for details of the structure
- Parameter description:
Parameter | Description |
---|---|
handle | Robotic arm control handle. |
mode | 0: simulation mode; 1: real mode. |
- Return value:
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. |
- Usage demo
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:
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:
Parameter | Type | Description |
---|---|---|
handle | Input | Robotic arm control handle. |
robot_info | Input | Structure storing the basic information of robotic arm. |
- Return value:
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 robotic arm is invalid. Check if the handle has been deleted. |
- Usage demo
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:
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:
Parameter | Value | Description |
---|---|---|
handle | User-defined | Robotic arm control handle. |
event_callback | User-defined | Robotic arm event callback function. This function receives rm_event_push_data_t data as parameters, and returns no value. |
- Usage demo
// 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);