Skip to content

快速开始

最小可运行示例:连接控制器、获取版本、读取位置、断开。

代码

cpp
#include <iostream>
#include "cpp_interface/nrc_api.h"

int main()
{
    // 1. 连接控制器
    SOCKETFD fd = connect_robot("192.168.1.15", "6001");
    if (fd <= 0) {
        std::cout << "连接失败" << std::endl;
        return 1;
    }

    // 2. 等待连接就绪
    while (get_connection_status(fd) != 0) {
        Sleep(200);  // Linux: usleep(200000)
    }

    // 3. 获取版本
    std::cout << "SDK 版本: " << get_library_version() << std::endl;

    // 4. 读取当前位置(关节坐标)
    std::vector<double> pos(7);
    get_current_position(fd, 0, pos);
    std::cout << "关节位置: ";
    for (auto v : pos) std::cout << v << " ";
    std::cout << std::endl;

    // 5. 断开
    disconnect_robot(fd);
    return 0;
}

预期输出

text
SDK 版本: Inexbot API v2.0.4-24.03
关节位置: 0.0 0.0 0.0 0.0 0.0 0.0 0.0

下一步

如需更复杂的运动控制,参见 基础应用进阶应用