Skip to content

4.15 C99 CoordinateSystem Interface ​

Overview ​

C99 CoordinateSystem manages user coordinate systems and tool coordinate systems. It supports list queries, detail queries, add, update, delete, and coordinate system pose calculation from teaching points.

Corresponding header:

  • include/c_arm_coordinate.h

Interface Signatures ​

Arm_CoordinateSystem_GetList ​

c
int Arm_CoordinateSystem_GetList(ArmHandle* h, int coordinateSystemType, ArmCoordinateInfo* outArray, size_t maxCount, size_t* outCount);
ItemDescription
DescriptionQueries the coordinate system list
Request Parametersh : ArmHandle* , C99 session handle, usually from Arm_Create() ; business APIs require connection first
coordinateSystemType : int , coordinate system type, user frame or tool frame
outArray : ArmCoordinateInfo* , output array allocated by the caller
maxCount : size_t , output array capacity, meaning the maximum number of elements the caller can receive
outCount : size_t* , output count pointer. On success, receives the actual count
Return ValueSTATUS_CODE integer value; 0 means success, other values should be handled as status codes
NotesThe caller allocates the output array. maxCount is the capacity, and outCount returns the actual count

Arm_CoordinateSystem_Get ​

c
int Arm_CoordinateSystem_Get(ArmHandle* h, int coordinateSystemType, int32_t id, ArmCoordinate* outCoordinate);
ItemDescription
DescriptionQueries coordinate system details
Request Parametersh : ArmHandle* , C99 session handle, usually from Arm_Create() ; business APIs require connection first
coordinateSystemType : int , coordinate system type, user frame or tool frame
id : int32_t , coordinate system ID
outCoordinate : ArmCoordinate* , output structure pointer for coordinate system details
Return ValueSTATUS_CODE integer value; 0 means success, other values should be handled as status codes

Arm_CoordinateSystem_Add ​

c
int Arm_CoordinateSystem_Add(ArmHandle* h, int coordinateSystemType, const ArmCoordinate* coordinate);
ItemDescription
DescriptionAdds a coordinate system
Request Parametersh : ArmHandle* , C99 session handle, usually from Arm_Create() ; business APIs require connection first
coordinateSystemType : int , coordinate system type, user frame or tool frame
coordinate : const ArmCoordinate* , coordinate system detail structure pointer
Return ValueSTATUS_CODE integer value; 0 means success, other values should be handled as status codes

Arm_CoordinateSystem_Update ​

c
int Arm_CoordinateSystem_Update(ArmHandle* h, int coordinateSystemType, const ArmCoordinate* coordinate);
ItemDescription
DescriptionUpdates a coordinate system
Request Parametersh : ArmHandle* , C99 session handle, usually from Arm_Create() ; business APIs require connection first
coordinateSystemType : int , coordinate system type, user frame or tool frame
coordinate : const ArmCoordinate* , coordinate system detail structure pointer
Return ValueSTATUS_CODE integer value; 0 means success, other values should be handled as status codes

Arm_CoordinateSystem_Delete ​

c
int Arm_CoordinateSystem_Delete(ArmHandle* h, int coordinateSystemType, int32_t id);
ItemDescription
DescriptionDeletes a coordinate system
Request Parametersh : ArmHandle* , C99 session handle, usually from Arm_Create() ; business APIs require connection first
coordinateSystemType : int , coordinate system type, user frame or tool frame
id : int32_t , coordinate system ID
Return ValueSTATUS_CODE integer value; 0 means success, other values should be handled as status codes

Arm_CoordinateSystem_Calculate ​

c
int Arm_CoordinateSystem_Calculate(ArmHandle* h, int coordinateSystemType, const ArmCoordinate* coordinates, size_t count, ArmCoordinatePose* outPose);
ItemDescription
DescriptionCalculates coordinate system pose from teaching points
Request Parametersh : ArmHandle* , C99 session handle, usually from Arm_Create() ; business APIs require connection first
coordinateSystemType : int , coordinate system type, user frame or tool frame
coordinates : const ArmCoordinate* , teaching point array used to calculate the coordinate system
count : size_t , number of array elements
outPose : ArmCoordinatePose* , output pose structure pointer
Return ValueSTATUS_CODE integer value; 0 means success, other values should be handled as status codes

Types and Rules ​

ArmCoordinateSystemType ​

Enum ValueValueDescription
ARM_COORDINATE_SYSTEM_USER_FRAME0User coordinate system, used for workpieces, stations, and other user-defined frames
ARM_COORDINATE_SYSTEM_TOOL_FRAME1Tool coordinate system, used for the TCP frame of the end effector

ArmCoordinatePose ​

FieldTypeDescription
xdoubleX-axis position
ydoubleY-axis position
zdoubleZ-axis position
adoubleA orientation angle
bdoubleB orientation angle
cdoubleC orientation angle

ArmCoordinateInfo ​

FieldTypeDescription
idint32_tCoordinate system ID
namechar[128]Coordinate system name
commentchar[256]Coordinate system comment
groupIdint32_tGroup ID

ArmCoordinate ​

FieldTypeDescription
idint32_tCoordinate system ID
namechar[128]Coordinate system name
commentchar[256]Coordinate system comment
groupIdint32_tGroup ID
dataArmCoordinatePoseCoordinate system pose

Prerequisites and Failure Semantics ​

ScenarioReturn
Not connected or invalid handleOTHER_ERR
Invalid coordinate system typeINVALID_PARAMETER
Arm_CoordinateSystem_Calculate() is missing robot model informationINVALID_PARAMETER
Required input or output pointer is nullINVALID_PARAMETER
outArray == NULL in Arm_CoordinateSystem_GetList()Count-only mode; writes outCount on success
Insufficient buffer capacity in Arm_CoordinateSystem_GetList()BUFFER_TOO_SMALL

Arm_CoordinateSystem_Calculate() depends on robot model information obtained after connection. Callers must complete Arm_Connect() first and pass the coordinate point array used for calibration.

Cartesian Angle Wrap-Around ​

In the ArmCoordinatePose returned by Arm_CoordinateSystem_Calculate() , orientation components a / b / c are in the range [-180, 180] . The same physical orientation may be represented as -180 or 180 ; the two are equivalent.

When comparing whether two poses are close, x / y / z can be compared directly by difference. a / b / c must first be normalized over the 360 degree period to avoid false deviation across the boundary.

c
double posDiff = fabs(pose1.x - pose2.x);
double angleDiff = fmod(fabs(pose1.a - pose2.a), 360.0);
if (angleDiff > 180.0) {
    angleDiff = 360.0 - angleDiff;
}

Minimal Call Example ​

c
#include <stdio.h>     // printf for printing coordinate count
#include "c_arm_api.h" // C99 SDK umbrella header

int main(void)
{
    ArmHandle* h = Arm_Create();
    ArmCoordinateInfo infos[8] = {0};
    size_t count = 0U;
    if (h == NULL) {
        return 1;
    }

    if (Arm_Connect(h, "10.27.1.2", "10.27.1.102") != 0) {
        Arm_Destroy(h);
        return 1;
    }

    int ret = Arm_CoordinateSystem_GetList(h, ARM_COORDINATE_SYSTEM_USER_FRAME, infos, 8, &count);
    printf("coordinate_count=%zu\n", count);
    Arm_Disconnect(h);
    Arm_Destroy(h);
    return ret == 0 ? 0 : 1;
}

Scenario Examples ​

c
ArmCoordinateInfo infos[8] = {0};
ArmCoordinate coord = {0};
ArmCoordinatePose pose = {0};
size_t coordCount = 0U;
int listRet = Arm_CoordinateSystem_GetList(h, ARM_COORDINATE_SYSTEM_USER_FRAME, infos, 8, &coordCount);
int getRet = Arm_CoordinateSystem_Get(h, ARM_COORDINATE_SYSTEM_USER_FRAME, 1, &coord);
int calcRet = Arm_CoordinateSystem_Calculate(h, ARM_COORDINATE_SYSTEM_USER_FRAME, &coord, 1, &pose);
/* int addRet = Arm_CoordinateSystem_Add(h, ARM_COORDINATE_SYSTEM_USER_FRAME, &coord); */
/* int updateRet = Arm_CoordinateSystem_Update(h, ARM_COORDINATE_SYSTEM_USER_FRAME, &coord); */
/* int deleteRet = Arm_CoordinateSystem_Delete(h, ARM_COORDINATE_SYSTEM_USER_FRAME, 1); */
(void)listRet;
(void)getRet;
(void)calcRet;

Example code:

c99/coordinate_system_basic/src/main.cpp
cpp
#include <stdio.h>
#include <string.h>

extern "C" {
#include "c_arm_api.h"
}

int main(void)
{
    // [ZH] 本示例直接在源码中写死连接地址,不解析命令行参数。
    // [EN] This example hard-codes the connection addresses in the source code and does not parse command-line arguments.
    // [ZH] 创建并连接 SDK 句柄。
    // [EN] Create the SDK handle and connect to the robot.
    ArmHandle* handle = Arm_Create();
    if (handle == NULL) {
        printf("[c99_coordinate] 创建句柄失败 / Failed to create the handle\n");
        return 1;
    }
    int ret = Arm_Connect(handle, "10.27.1.2", "10.27.1.102");
    if (ret != 0) {
        printf("[c99_coordinate] 连接失败 / Connect failed, 状态码 / Status code: %d\n", ret);
        Arm_Destroy(handle);
        return 1;
    }
    printf("[c99_coordinate] 机器人连接成功 / Robot connected successfully\n");

    // [ZH] 读取工具坐标系列表与第一个坐标系详情。
    // [EN] Read the tool-frame list and the first frame detail.
    ArmCoordinateInfo infoList[8] = {0};
    size_t infoCount = 0U;
    ret = Arm_CoordinateSystem_GetList(handle, ARM_COORDINATE_SYSTEM_TOOL_FRAME, infoList, 8U, &infoCount);
    printf("[c99_coordinate] GetList 状态码 / GetList status code: %d, 数量 / Count: %zu\n", ret, infoCount);
    if (infoCount > 0U) {
        ArmCoordinate detail = {0};
        ret = Arm_CoordinateSystem_Get(handle, ARM_COORDINATE_SYSTEM_TOOL_FRAME, infoList[0].id, &detail);
        printf("[c99_coordinate] Get 状态码 / Get status code: %d, id=%d, name=%s\n", ret, detail.id, detail.name);
    }

    // [ZH] 构造 3 点并计算用户坐标系。
    // [EN] Build three points and calculate a user frame.
    ArmCoordinate calculatePoints[3] = {0};
    for (int index = 0; index < 3; ++index) {
        calculatePoints[index].id = index + 1;
        calculatePoints[index].groupId = 1;
        snprintf(calculatePoints[index].name, sizeof(calculatePoints[index].name), "p%d", index + 1);
        snprintf(calculatePoints[index].comment, sizeof(calculatePoints[index].comment), "sdk example");
        calculatePoints[index].data.x = 1.0 + index * 3.0;
        calculatePoints[index].data.y = 2.0 + index * 3.0;
        calculatePoints[index].data.z = 3.0 + index * 3.0;
        calculatePoints[index].data.a = 10.0 + index * 30.0;
        calculatePoints[index].data.b = 20.0 + index * 30.0;
        calculatePoints[index].data.c = 30.0 + index * 30.0;
    }
    ArmCoordinatePose pose = {0};
    ret = Arm_CoordinateSystem_Calculate(handle, ARM_COORDINATE_SYSTEM_USER_FRAME, calculatePoints, 3U, &pose);
    printf("[c99_coordinate] Calculate 状态码 / Calculate status code: %d, 位姿 / Pose: [%.6f, %.6f, %.6f, %.6f, %.6f, %.6f]\n",
        ret,
        pose.x,
        pose.y,
        pose.z,
        pose.a,
        pose.b,
        pose.c);

    // [ZH] 顺序执行新增、更新和删除接口。
    // [EN] Execute the add, update, and delete APIs in sequence.
    ArmCoordinate userFrame = {0};
    userFrame.id = 10;
    userFrame.groupId = 1;
    snprintf(userFrame.name, sizeof(userFrame.name), "user_demo");
    snprintf(userFrame.comment, sizeof(userFrame.comment), "sdk example");
    userFrame.data = pose;
    ret = Arm_CoordinateSystem_Add(handle, ARM_COORDINATE_SYSTEM_USER_FRAME, &userFrame);
    printf("[c99_coordinate] Add 状态码 / Add status code: %d\n", ret);
    ret = Arm_CoordinateSystem_Update(handle, ARM_COORDINATE_SYSTEM_USER_FRAME, &userFrame);
    printf("[c99_coordinate] Update 状态码 / Update status code: %d\n", ret);
    ret = Arm_CoordinateSystem_Delete(handle, ARM_COORDINATE_SYSTEM_USER_FRAME, userFrame.id);
    printf("[c99_coordinate] Delete 状态码 / Delete status code: %d\n", ret);

    // [ZH] 断开连接并销毁句柄。
    // [EN] Disconnect and destroy the handle.
    Arm_Disconnect(handle);
    Arm_Destroy(handle);
    printf("[c99_coordinate] 示例结束 / Example finished\n");
    return 0;
}