坐标控制(RobotArm)

坐标控制指在基坐标系下指定末端位姿 [x, y, z, rx, ry, rz]:其中 x、y、z 为位置(mm),rx、ry、rz 为姿态(°,欧拉角语义以下位机为准)。本文档基于 RobotArminclude/RobotArm.hpp),适用于 MyCobotPro450;运行环境为 Linux,通信为 TCP(见 环境搭建编译)。

下文接口均按 功能返回值参数说明取值范围 列出。完整 API 索引见 API 说明


坐标分量取值(MyCobotPro450)

轴 id 分量 范围
1 x(mm) -474 ~ 474
2 y(mm) -474 ~ 474
3 z(mm) -180 ~ 677
4 rx(°) -180 ~ 180
5 ry(°) -180 ~ 180
6 rz(°) -180 ~ 180

速度档 sp / speed1 ~ 100(全篇同)。


单轴

int sendCoord(uint8_t axis, float coord, uint8_t sp)

  • 功能:下发单轴目标坐标或姿态分量。
  • 返回值:成功多为 1,失败 -1
  • 参数说明axis1~6(对应 x,y,z,rx,ry,rz);coord 为目标值;sp 为速度档。
  • 取值范围axis1 ~ 6coord见上表sp1 ~ 100

六轴

Coords getCoords()

  • 功能:读取当前六位姿 [x,y,z,rx,ry,rz]
  • 返回值Coordsstd::array<float, 6>),下标 0 ~ 5 对应 轴 1 ~ 6
  • 参数说明:无。
  • 取值范围:无。

int SendCoords(Coords coords, uint8_t sp)

  • 功能:一次性下发完整六位姿。
  • 返回值:成功多为 1,失败 -1
  • 参数说明coords 六个分量;sp 速度档。
  • 取值范围:各分量 按轴 1~6 见上表sp1 ~ 100

坐标 JOG

int jogCoord(uint8_t axis, uint8_t direction, uint8_t speed)

  • 功能:指定坐标轴沿某方向连续运动,直至限位或调用 stop() 等停止。
  • 返回值:成功多为 1,失败 -1
  • 参数说明axisdirectionspeed
  • 取值范围axis1 ~ 6direction0 负向、1 正向;speed1 ~ 100

到位判断(坐标目标)

int isInPosition(Angles angle_coords, bool mode)

  • 功能:判断当前末端是否到达给定的六维目标;用于坐标时第二参数取 true(参数类型仍为 Angles/Coords 同一底层 std::array<float,6>)。
  • 返回值1 到位;0 未到位;-1 异常或无有效应答。
  • 参数说明angle_coords 六个目标量(此处表示 x,y,z,rx,ry,rz);mode
  • 取值范围:判断坐标mode == true;各分量 见本节坐标表

运动停止(与 JOG 等配合)

int stop()

  • 功能:停止当前运动。
  • 返回值:成功多为 1,失败 -1
  • 参数说明:无。
  • 取值范围:无。

示例(节选)

以下示例演示读取坐标、下发六位姿、按坐标判断是否到位、坐标 JOG 与停止,请保证目标点在机器人工作空间内且路径安全。

#include "RobotArm.hpp"
#include "config.hpp"
#include <iostream>
#include <thread>
#include <chrono>

using namespace std::chrono_literals;

int main() {
    Param p;
    p.ip_serial = "192.168.0.232";
    p.port_baud = 4500;

    RobotArm arm(TCP_COMM, p);

    if (arm.powerOn() != 1) {
        std::cerr << "powerOn failed\n";
        return 1;
    }

    Coords cur = arm.getCoords();
    std::cout << "x=" << cur[0] << " y=" << cur[1] << " z=" << cur[2] << "\n";

    Coords goal = {200.f, 100.f, 250.f, 0.f, 0.f, 0.f}; //根据当前机器实际姿态给坐标点位
    if (arm.SendCoords(goal, 30) != 1) {
        std::cerr << "SendCoords failed\n";
    }

    while (arm.isInPosition(goal, true) != 1) {
        cur = arm.getCoords();
        std::cout << "x=" << cur[0] << " ...\n";
        std::this_thread::sleep_for(200ms);
    }

    arm.jogCoord(1, 1, 30);
    std::this_thread::sleep_for(2s);
    arm.stop();

    arm.powerOff();
    return 0;
}

← 上一章 | 下一章 →

results matching ""

    No results matching ""