坐标控制

坐标控制是让机械臂以指定姿态移动到指定点,分为x,y,z,rx,ry,rz。X,Y,Z 表示的是机械臂头部在空间中的位置(该坐标系为直角坐标系),rx,ry,rz表示的是机械臂头部在该点的姿态(该坐标系为欧拉坐标)。

1 单参数控制

1.1 发送单参数坐标

WriteCoord(Axis axis, double value, int speed = DefaultSpeed)
返回值:无
参数说明:参数1:坐标号(Axis枚举类型,int:1-6(X-RZ)),参数2:坐标(X、Y、Z取值范围 -300-300.00 单位 mm RX、RY、RZ,取值范围-180-180),参数3:速度(0-100),默认为30
示例:
mycobot::MyCobot::I().WriteCoord(mycobot::Axis::X, 10, 30);

2 多参数控制

2.1 获取全部坐标

GetCoords()
返回值:Coords类型
参数说明:无
示例:
mycobot::Coords coords = mycobot::MyCobot::I().GetCoords();

2.2 发送全部坐标

WriteCoords(const Coords& coords, int speed = DefaultSpeed)
返回值:无
参数说明:参数1:坐标(X、Y、Z取值范围 -300-300.00 单位 mm RX、RY、RZ,取值范围-180-180
参数2:速度(0-100),默认为30
示例:

mycobot::Coords goal_coords = { 5, 5, 5, 5, 5, 5 };
mycobot::MyCobot::I().WriteCoords(goal_coords, 30);

3 完整使用案例

int main(int argc, char* argv[])
try {
    QCoreApplication a(argc, argv);
    using namespace std::chrono_literals;
    if (!mycobot::MyCobot::I().IsControllerConnected()) {
        std::cerr << "Robot is not connected\n";
        exit(EXIT_FAILURE);
    }
    std::cout << "Robot is connected\n";
    mycobot::MyCobot::I().PowerOn();
    mycobot::MyCobot::I().StopRobot();
    std::cout << "Robot is moving: " << mycobot::MyCobot::I().IsMoving() << "\n";
    mycobot::Angles angles = mycobot::MyCobot::I().GetAngles();
    std::this_thread::sleep_for(200ms);
    mycobot::Coords coords = mycobot::MyCobot::I().GetCoords();
    angles = mycobot::MyCobot::I().GetAngles();
    std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", " << angles[mycobot::J3] << ", "
        << angles[mycobot::J4] << ", " << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]";
    mycobot::Angles goal_angles = { 5, 5, 5, 5, 5, 5 };
    mycobot::MyCobot::I().WriteAngles(goal_angles);
    while (!mycobot::MyCobot::I().IsInPosition(goal_angles, false)) {
        angles = mycobot::MyCobot::I().GetAngles();
        std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", "
            << angles[mycobot::J3] << ", " << angles[mycobot::J4] << ", "
            << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]" << std::flush;
        std::this_thread::sleep_for(200ms);
    }

    mycobot::MyCobot::I().JogAngle(mycobot::Joint::J1, 1, 5);
    std::this_thread::sleep_for(5000ms);
    mycobot::MyCobot::I().StopRobot();

    std::cout << "\n";
    exit(EXIT_SUCCESS);
} catch (std::error_code&) {
    std::cerr << "System error. Exiting.\n";
    exit(EXIT_FAILURE);
} catch (...) {
    std::cerr << "Unknown exception thrown. Exiting.\n";
    exit(EXIT_FAILURE);
}

results matching ""

    No results matching ""