Skip to content

1. Get Position in Different Coordinates

Use the connect_robot function to connect to the controller, and through the returned fd, call get_current_position to obtain the robot's real-time position in joint coordinates, Cartesian coordinates, tool coordinates, and user coordinates.

cpp
#include <iostream>
#include "cpp_interface/nrc_api.h"  // Import header file
int main()
{
    SOCKETFD fd = connect_robot("192.168.1.15", "6001");  // Connect to the controller
    if (fd <= 0)
    {
        std::cout << "Connection failed" << std::endl;
        return 0;
    }
    std::cout << "Connection succeeded: "<< fd << std::endl;

    std::vector<double> pos(7);
    for (int coord = 0; coord < 4; coord++)
    {
        get_current_position(fd, coord, pos); // Query current position based on coord value
        for (auto v : pos)
        {
            std::cout << v << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}