Skip to content

1.2 빠른 연동

권장 경로

현재 권장하는 연동 경로는 다음과 같습니다.

  1. 먼저 Arm 을 인스턴스화합니다.
  2. Connect(controllerIp, teachPanelIp) 를 호출해 기본 RPC 연결을 설정합니다.
  3. arm.controllerInfo / arm.motionControl / arm.programManager / ... 를 통해 업무 기능을 호출합니다.
  4. 구독/발행을 사용하는 경우 arm.topicPubSub.Connect() 를 별도로 호출합니다.
  5. 종료 시 Disconnect() 를 호출합니다.

C++17 최소 연동

예제 코드

cpp17/info_get_controller_version/src/main.cpp
cpp
#include "query_version_and_model/run.h"
#include "query_statuses/run.h"

int main(void)
{
    // [ZH] 默认只调用一个门面方法;如需体验其他接口,请把下一行替换成下面任意一行。
    // [EN] The main function calls only one facade by default. Replace the next line with any line below to try other APIs.
    return RunInfoGetControllerVersionQueryVersionAndModel();
    // return RunInfoGetControllerVersionQueryStatuses();
}
cpp17/info_get_controller_version/src/query_version_and_model/run.cpp
cpp
#include <iostream>
#include "arm_api.h"
#include "status_code.h"

#include "query_version_and_model/run.h"

/**
 * 查询版本与型号门面。
 * @return 0 表示成功,否则返回 1。
 */
int RunInfoGetControllerVersionQueryVersionAndModel(void)
{
    // [ZH] 连接机器人,请直接修改下面的魔鬼字符串。
    // [EN] Connect to the robot and edit the hard-coded magic strings below directly.
    Arm arm;
    STATUS_CODE connectRet = arm.Connect("10.27.1.2", "10.27.1.102");
    if (connectRet != STATUS_CODE::OK) {
        std::cerr << "[cpp17_info_basic] 连接机器人失败 / Connect to the robot failed, 状态码 / Status code: "
                  << static_cast<int>(connectRet) << "\n";
        return 1;
    }
    std::cout << "[cpp17_info_basic] 机器人连接成功 / Robot connected successfully\n";
    // [ZH] 获取控制器版本和机械臂型号。
    // [EN] Get the controller version and robot model.
    std::pair<std::string, STATUS_CODE> versionPair = arm.controllerInfo.GetControllerVersion();
    std::pair<std::string, STATUS_CODE> modelPair = arm.controllerInfo.GetArmModelInfo();
    std::cout << "[cpp17_info_basic] GetControllerVersion 状态码 / GetControllerVersion status code: "
              << static_cast<int>(versionPair.second)
              << ", 版本 / Version: " << versionPair.first << "\n";
    std::cout << "[cpp17_info_basic] GetArmModelInfo 状态码 / GetArmModelInfo status code: "
              << static_cast<int>(modelPair.second)
              << ", 型号 / Model: " << modelPair.first << "\n";

    // [ZH] 断开连接,结束示例。
    // [EN] Disconnect and finish the example.
    arm.Disconnect();
    std::cout << "[cpp17_info_basic] 示例结束 / Example finished\n";
    return 0;
}

C99 최소 연동

예제 코드

c99/info_basic/src/main.cpp
cpp
#include <stdio.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_info] 创建句柄失败 / 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_info] 连接失败 / Connect failed, 状态码 / Status code: %d\n", ret);
        Arm_Destroy(handle);
        return 1;
    }
    printf("[c99_info] 机器人连接成功 / Robot connected successfully\n");

    // [ZH] 读取控制器版本与机械臂型号。
    // [EN] Read the controller version and robot model.
    char version[128] = {0};
    char model[128] = {0};
    ret = Arm_Info_GetControllerVersion(handle, version, sizeof(version));
    printf("[c99_info] GetControllerVersion 状态码 / GetControllerVersion status code: %d, 版本 / Version: %s\n", ret, version);
    ret = Arm_Info_GetArmModelInfo(handle, model, sizeof(model));
    printf("[c99_info] GetArmModelInfo 状态码 / GetArmModelInfo status code: %d, 型号 / Model: %s\n", ret, model);

    // [ZH] 获取并归还 SDK 控制权限。
    // [EN] Acquire and release the SDK control access.
    Arm_Info_AcquireAccess(handle);
    printf("[c99_info] 已获取控制权 / SDK access acquired\n");
    Arm_Info_ReleaseAccess(handle);
    printf("[c99_info] 已归还控制权 / SDK access released\n");

    // [ZH] 顺序读取全部状态类接口。
    // [EN] Read all status-oriented APIs in sequence.
    int opMode = 0;
    int ctrlStatus = 0;
    int robotStatus = 0;
    int servoStatus = 0;
    int softMode = 0;
    ret = Arm_Info_GetOpMode(handle, &opMode);
    printf("[c99_info] GetOpMode 状态码 / GetOpMode status code: %d, 操作模式 / Operation mode: %d\n", ret, opMode);
    ret = Arm_Info_GetCtrlStatus(handle, &ctrlStatus);
    printf("[c99_info] GetCtrlStatus 状态码 / GetCtrlStatus status code: %d, 控制器状态 / Controller status: %d\n", ret, ctrlStatus);
    ret = Arm_Info_GetRobotStatus(handle, &robotStatus);
    printf("[c99_info] GetRobotStatus 状态码 / GetRobotStatus status code: %d, 机器人状态 / Robot status: %d\n", ret, robotStatus);
    ret = Arm_Info_GetServoStatus(handle, &servoStatus);
    printf("[c99_info] GetServoStatus 状态码 / GetServoStatus status code: %d, 伺服状态 / Servo status: %d\n", ret, servoStatus);
    ret = Arm_Info_GetSoftMode(handle, &softMode);
    printf("[c99_info] GetSoftMode 状态码 / GetSoftMode status code: %d, 软模式 / Soft mode: %d\n", ret, softMode);

    // [ZH] 顺序执行全部写接口与动作接口。
    // [EN] Execute all setter APIs and action APIs in sequence.
    ret = Arm_Info_SetSoftMode(handle, softMode);
    printf("[c99_info] SetSoftMode 状态码 / SetSoftMode status code: %d\n", ret);
    ret = Arm_Info_SetOpMode(handle, opMode);
    printf("[c99_info] SetOpMode 状态码 / SetOpMode status code: %d\n", ret);
    ret = Arm_Info_SwitchLedLight(handle, 1);
    printf("[c99_info] SwitchLedLight 状态码 / SwitchLedLight status code: %d\n", ret);
    ret = Arm_Info_ServoOn(handle);
    printf("[c99_info] ServoOn 状态码 / ServoOn status code: %d\n", ret);
    ret = Arm_Info_ServoOff(handle);
    printf("[c99_info] ServoOff 状态码 / ServoOff status code: %d\n", ret);
    ret = Arm_Info_ServoReset(handle);
    printf("[c99_info] ServoReset 状态码 / ServoReset status code: %d\n", ret);
    ret = Arm_Info_Estop(handle);
    printf("[c99_info] Estop 状态码 / Estop status code: %d\n", ret);

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

Connect 의미

항목설명
controllerIp컨트롤러 IP
teachPanelIp비워 둘 수 있습니다. 비어 있으면 SDK가 기본 연결 규칙에 따라 주소를 추론합니다. 모호함을 피하려면 업무 코드에서 명시적으로 전달하는 것을 권장합니다.
주소 보완산업용 로봇 주소 조합과 협동 로봇 주소 조합은 SDK 기본 연결 규칙에 따라 처리됩니다.
성공 후 채움version , model , robotType
동기 바인딩연결 단계에서 controllerInfo , motionControl , programManager , ioSignals , registerBank , trajectoryManager , coordinateSystemManager , modbusClient , topicPubSub 등의 인터페이스 모듈을 바로 사용할 수 있습니다.

연결 후 공개 멤버

멤버역할관련 문서
version / model / robotType연결 시 채워지는 장치 식별 정보Arm
controllerInfo컨트롤러 상태 및 기본 제어ControllerInfo
alarmClient알람 조회 및 리셋AlarmClient
motionControl모션 및 페이로드MotionControl
programManager프로그램 실행 및 포즈ProgramManager
ioSignalsIO 읽기/쓰기IoSignals
registerBankR/PR/SR/MR/MH/MI 레지스터RegisterBank
trajectoryManager오프라인 궤적 및 경로 테이블TrajectoryManager
realTimeTrajectoryControl실시간 궤적RealTimeTrajectoryControl
controllerFileManager파일 업로드, 다운로드 및 검색ControllerFileManager
joggingControl티칭 모션JoggingControl
extensionClient확장 서비스ExtensionClient
topicPubSubWebSocket 구독 및 발행TopicPubSub
coordinateSystemManager좌표계 관리CoordinateSystemManager
modbusClientModbus 기능ModbusClient

반환값 규칙

언어반환 형식
C++17STATUS_CODE 또는 std::pair<T, STATUS_CODE>
C99int 상태 코드 + out 파라미터

C++17

  • 순수 동작 인터페이스는 STATUS_CODE 를 반환합니다.
  • 조회 인터페이스는 std::pair<T, STATUS_CODE> 를 반환합니다.
  • 연결이 완료되지 않았거나 인터페이스 모듈이 초기화되지 않은 경우, 실패 데이터 값은 일반적으로 빈 문자열, UNKNOWN , 0 값 구조체 또는 빈 컨테이너를 반환합니다.

C99

  • 반환값은 int 상태 코드입니다.
  • 업무 결과는 out 파라미터를 통해 반환됩니다.
  • 문자열/배열 출력은 버퍼 크기와 BUFFER_TOO_SMALL 에 특히 주의해야 합니다.

topicPubSub 별도 연결

Arm::Connect()topicPubSub 을 현재 컨트롤러/티치 펜던트 주소에 바인딩하기만 합니다. 실제로 WebSocket 연결을 만들려면 여전히 다음 호출이 필요합니다.

cpp
STATUS_CODE ret = arm.topicPubSub.Connect();  // Arm::Connect()로 바인딩된 주소를 사용해 TopicPubSub WebSocket 연결을 설정합니다.

Arm 을 통해 진입하지 않고 독립적인 TopicPubSub 객체를 직접 사용하는 경우 주소를 명시적으로 전달해야 합니다.

cpp
TopicPubSub topicPubSub;  // 독립적인 TopicPubSub 객체를 생성합니다.
STATUS_CODE ret = topicPubSub.Connect("192.168.110.102");  // 티치 펜던트 또는 프록시 측 WebSocket 주소를 명시적으로 전달합니다.