Skip to content

1.获取不同坐标系的位置

使用 connect_robot 函数连接到控制器,并通过返回的 fd,调用 get_current_position 获取到机器人分别在关节坐标、直角坐标、工具坐标、用户坐标下的实时位置。

cpp
#include <iostream>
#include "cpp_interface/nrc_api.h"  // 导入头文件
int main()
{
    SOCKETFD fd = connect_robot("192.168.1.15", "6001");  // 连接到控制器
    if (fd <= 0)
    {
        std::cout << "连接失败" << std::endl;
        return 0;
    }
    std::cout << "连接成功: "<< fd << std::endl;

    std::vector<double> pos(7);
    for (int coord = 0; coord < 4; coord++)
    {
        get_current_position(fd, coord, pos); // 根据coord的值,查询当前坐标
        for (auto v : pos)
        {
            std::cout << v << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}