CTE手臂#

介绍#

arm 类用于控制 CTE 工作单元中使用的 6 轴机械臂。在 VEX V5 C++ 中,6 轴机械臂可以将末端执行器移动到三维空间中的指定位置,旋转末端执行器,检查运动是否可行,并控制诸如磁性拾取工具或笔架工具等连接的工具。

VEXcode V5 中未将 6 轴机械臂配置为设备。要在 VEX V5 C++ 项目中使用它,请在代码中手动创建一个 arm 对象,并将 6 轴机械臂连接到该智能端口。

本页上的示例使用手动构建的名为 Arm的 6 轴机械臂。

构造函数#

arm#

arm 创建一个 6 轴机械臂对象。

可用功能

arm(int32_t index);

范围

类型

描述

index

int32_t

6轴机械臂连接的智能端口,记为 PORTx,其中 x 是端口号。例如, PORT1。

例子

// Create a 6-Axis Arm named Arm on Port 1
arm Arm = arm(PORT1);

毁灭者#

~arm#

~arm 销毁 arm 对象并释放相关资源。

可用功能

~arm();

成员功能#

arm 类包含以下成员函数:

动作——将六轴机械臂移动到指定位置或方向。

  • moveTo — 将末端执行器移动到指定的 x、y 和 z 坐标。

  • moveInc — 将末端执行器从其当前位置移动指定的距离。

  • moveEndEffectorTo — 将末端执行器旋转到指定的偏航角、横滚角和俯仰角。

  • moveEndEffectorInc — 将末端执行器旋转指定的偏航角、横滚角和俯仰角。

变异器 — 配置移动、工具和控制设置。

获取器 — 返回运动状态、位置、方向和连接值。

  • isDone — 返回 6 轴机械臂是否已完成移动。

  • isCrashed — 返回 6 轴机械臂在移动过程中是否发生碰撞。

  • getX — 返回末端执行器的当前 x 位置。

  • getY — 返回末端执行器的当前 y 位置。

  • getZ — 返回末端执行器的当前 z 位置。

  • getYaw — 返回末端执行器的当前偏航角。

  • getRoll — 返回末端执行器的当前滚动角度。

  • getPitch — 返回末端执行器的当前俯仰角。

  • canArmReachTo — 返回 6 轴机械臂是否可以到达指定位置。

  • canArmReachInc — 返回 6 轴机械臂是否可以移动指定的距离。

  • canEndEffectorReachTo — 返回末端执行器是否可以达到指定的方向。

  • canEndEffectorReachInc — 返回末端执行器是否可以旋转指定的量。

  • isConnected — 返回 6 轴机械臂是否连接到 V5 大脑。

  • timestamp — 返回从 6 轴机械臂接收到的最后一个状态数据包的时间戳。

  • installed — 返回 6 轴机械臂是否已连接。

回调函数——在发生起动事件时运行函数。

  • controlStopped — 注册一个在启用控制停止时要运行的函数。

  • crashed — 注册一个在检测到崩溃时要运行的函数。

行动#

moveTo#

moveTo 将 6 轴机械臂移动到指定的 x、y 和 z 坐标。

x、y 和 z 坐标描述了末端执行器在三维空间中的位置。如果目标位置可能超出六轴机械臂的可达工作空间,请在调用此函数之前使用 canArmReachTo。

可用功能

bool moveTo(
  double x,
  double y,
  double z,
  bool   waitForCompletion = true
);

范围

类型

描述

x

double

目标位置的 x 坐标(单位:毫米)。

y

double

目标位置的y坐标(单位:毫米)。

z

double

目标位置的z坐标(单位:毫米)。

waitForCompletion

bool

可选。0 为真 true (默认值)等待移动完成后再继续。2 false 开始移动并立即继续执行下一行代码。

返回值

返回布尔值。

  • true — 6轴机械臂到达目标位置。

  • false — 6轴机械臂未到达目标位置,或 waitForCompletion 设置为 false。

示例

// Move the 6-Axis Arm to (200, 0, 100)
Arm.moveTo(200, 0, 100);

// Start moving, then print the y-position while the arm moves
Arm.moveTo(-100, 200, 100, false);

while (!Arm.isDone()) {
  Brain.Screen.print(Arm.getY());
  Brain.Screen.newLine();
  wait(0.25, seconds);
}

moveInc#

moveInc 将 6 轴机械臂沿 x、y 和 z 轴从其当前位置移动指定的距离。

使用此函数相对于末端执行器当前位置进行移动。如果移动可能使六轴机械臂超出其可达工作空间,请在此函数之前使用 canArmReachInc。

可用功能

bool moveInc(
  double x,
  double y,
  double z,
  bool   waitForCompletion = true
);

范围

类型

描述

x

double

沿 x 轴移动的距离(单位:毫米)。

y

double

沿 y 轴移动的距离(单位:毫米)。

z

double

沿 z 轴移动的距离,单位为毫米。

waitForCompletion

bool

可选。0 为真 true (默认值)等待移动完成后再继续。2 false 开始移动并立即继续执行下一行代码。

返回值

返回布尔值。

  • true — 6轴机械臂已到达指定位置。

  • false — 6轴机械臂未到达请求的位置,或 waitForCompletion 设置为 false。

例子

// Move the 6-Axis Arm 100 millimeters along the y-axis
Arm.moveInc(0, 100, 0);

moveEndEffectorTo#

moveEndEffectorTo 将 6 轴机械臂的末端执行器旋转到指定的偏航角、横滚角和俯仰角。

Orientation describes how the end effector is rotated. yaw rotates around the z-axis, roll rotates around the x-axis, and pitch rotates around the y-axis.

可用功能

bool moveEndEffectorTo(
  double yaw,
  double roll = 0,
  double pitch = 0,
  bool   waitForCompletion = true
);

范围

类型

描述

yaw

double

目标偏航角(以度为单位)。

roll

double

可选。目标横滚角,单位为度。默认值为 0。

pitch

double

可选。目标俯仰角,单位为度。默认值为 0。

waitForCompletion

bool

可选。0 为真 true (默认值)等待移动完成后再继续。2 false 开始移动并立即继续执行下一行代码。

返回值

返回布尔值。

  • true — 末端执行器已达到目标方向。

  • false — 末端执行器未达到目标方向,或 waitForCompletion 设置为 false。

例子

// Rotate the end effector to 90 degrees of roll
Arm.moveEndEffectorTo(0, 90, 0);

moveEndEffectorInc#

moveEndEffectorInc 将 6 轴机械臂的末端执行器从其当前方向旋转指定的偏航角、横滚角和俯仰角。

使用此功能可相对于末端执行器的当前偏航角、横滚角或俯仰角进行旋转。

可用功能

bool moveEndEffectorInc(
  double yaw,
  double roll = 0,
  double pitch = 0,
  bool   waitForCompletion = true
);

范围

类型

描述

yaw

double

偏航角的变化量,以度为单位。

roll

double

可选。滚动角度的变化量,以度为单位。默认值为 0。

pitch

double

可选。音调变化量,以度为单位。默认值为 0。

waitForCompletion

bool

可选。0 为真 true (默认值)等待移动完成后再继续。2 false 开始移动并立即继续执行下一行代码。

返回值

返回布尔值。

  • true — 末端执行器已达到要求的方向。

  • false — 末端执行器未达到请求的方向,或 waitForCompletion 设置为 false。

例子

// Rotate the end effector -50 degrees in pitch
Arm.moveEndEffectorInc(0, 0, -50);

变异体#

setSpeed#

setSpeed 设置 6 轴机械臂的运动速度。

可用功能

void setSpeed(uint32_t speed);

范围

类型

描述

speed

uint32_t

6轴机械臂的移动速度,单位为毫米每秒。

返回值

此函数不返回值。

例子

// Set the 6-Axis Arm movement speed
Arm.setSpeed(100);

setEndEffectorType#

setEndEffectorType 设置连接到 6 轴机械臂的末端执行器的类型。

当末端执行器类型改变时,6轴机械臂会自动调整其z轴偏移量以匹配所选工具。

可用功能

bool setEndEffectorType(
  endEffectorType type,
  bool            waitForCompletion = true
);

范围

类型

描述

type

endEffectorType

安装在 6 轴臂上的工具: magnet (磁铁拾取工具)或 pen (笔架工具)。

waitForCompletion

bool

可选。0 为真 true (默认值)等待更改完成后再继续。2 为假 false 开始更改并立即继续执行下一行代码。

返回值

返回布尔值。

  • true — 请求的类型已设置。

  • false — 请求的类型未设置,或者 waitForCompletion 设置为 false。

例子

// Set the end effector type to the Magnet Pickup Tool
Arm.setEndEffectorType(magnet);

setEndEffectorMagnet#

setEndEffectorMagnet 启用或禁用磁铁拾取工具。

可用功能

void setEndEffectorMagnet(bool enabled);

范围

类型

描述

enabled

bool

true 为启用磁铁吸附物体; false 为禁用磁铁并丢弃吸附的物体。

返回值

此函数不返回值。

例子

// Pick up objects and then drop them
Arm.setEndEffectorType(magnet);
Arm.setEndEffectorMagnet(true);
wait(2, seconds);
Arm.setEndEffectorMagnet(false);

setPenOffset#

setPenOffset 设置当笔架工具连接到 6 轴臂时使用的 z 轴偏移量。

使用此功能前,请将末端执行器类型设置为 pen 如果未选择笔架工具,此功能无效。

笔偏移量是指从笔架工具顶部到白板笔笔尖的距离。正的 z 值会使偏移量从工具安装点向上移动。

可用功能

void setPenOffset(double zOffset);

范围

类型

描述

zOffset

double

笔偏移值,单位为毫米。

返回值

此函数不返回值。

例子

// Set the end effector type to the Pen Holder Tool and set the pen offset
Arm.setEndEffectorType(pen);
Arm.setPenOffset(25);

setControlStop#

setControlStop 启用或禁用 6 轴机械臂的控制停止。

启用控制停止功能后,6 轴机械臂会立即停止运动,并防止进一步的线性或关节运动。

可用功能

void setControlStop(bool state = true);

范围

类型

描述

state

bool

可选。0 为真 true (默认值)启用控制停止功能,防止进一步的线性或关节运动。2 false 禁用控制停止功能。

返回值

此函数不返回值。

例子

// Stop the 6-Axis Arm and prevent further movement
Arm.setControlStop();

setTimeout#

setTimeout 设置移动 6 轴机械臂时使用的超时值。

如果在超时之前某个动作没有完成,项目将继续执行下一行代码。

可用功能

void setTimeout(
  int32_t   timeout,
  timeUnits units
);

范围

类型

描述

timeout

int32_t

新的超时值。

units

timeUnits

时间单位: sec (秒)或 msec (毫秒)。

返回值

此函数不返回值。

例子

// Set the 6-Axis Arm timeout to 2 seconds
Arm.setTimeout(2, sec);

获取器#

isDone#

isDone 返回 6 轴机械臂是否已完成移动。

在 waitForCompletion 设置为 false ,则此函数非常有用。

可用功能

bool isDone();

参数

此函数没有参数。

返回值

返回布尔值。

  • true — 6轴机械臂已完成移动。

  • false — 6轴机械臂仍在移动。

例子

// Display the 6-Axis Arm's y-position while it moves
Arm.moveTo(-100, 200, 100, false);

while (!Arm.isDone()) {
  Brain.Screen.print(Arm.getY());
  Brain.Screen.newLine();
  wait(0.25, seconds);
}

isCrashed#

isCrashed 返回 6 轴机械臂在移动过程中是否发生碰撞。

当检测到碰撞时,六轴机械臂会停止电机运动,并可能出现无力状态。这可以减轻机械臂的压力,并有助于保护电机免受意外损坏。

可用功能

bool isCrashed();

参数

此函数没有参数。

返回值

返回布尔值。

  • true — 6轴机械臂已坠毁。

  • false — 6轴机械臂没有发生碰撞。

例子

// Quickly move to a new location
Arm.setSpeed(100);
Arm.moveTo(-40, 250, 40, false);

// While moving, check for a crash
while (true) {
  if (Arm.isCrashed()) {
    // Indicate a crash with the Brain screen
    Brain.Screen.print("Crash Detected");
    break;
  }

  wait(5, msec);
}

getX#

getX 返回末端执行器的当前 x 位置(以毫米为单位)。

使用此函数读取末端执行器当前沿 x 轴的位置。

可用功能

float getX();

参数

此函数没有参数。

返回值

返回一个浮点数 float 表示末端执行器的 x 坐标(单位为毫米)。

例子

// Print the current x position of the 6-Axis Arm
Brain.Screen.print(Arm.getX());

getY#

getY 返回末端执行器的当前 y 位置(以毫米为单位)。

使用此函数读取末端执行器当前沿 y 轴的位置。

可用功能

float getY();

参数

此函数没有参数。

返回值

返回一个 float 表示末端执行器的 y 坐标(单位为毫米)。

例子

// Print the current y position of the 6-Axis Arm
Brain.Screen.print(Arm.getY());

getZ#

getZ 返回末端执行器的当前 z 位置(以毫米为单位)。

使用此函数读取末端执行器当前沿 z 轴的位置。

可用功能

float getZ();

参数

此函数没有参数。

返回值

返回一个 float 表示末端执行器的 z 轴位置(单位为毫米)。

例子

// Print the current z position of the 6-Axis Arm
Brain.Screen.print(Arm.getZ());

getYaw#

getYaw 返回末端执行器的当前偏航角(以度为单位)。

可用功能

float getYaw();

参数

此函数没有参数。

返回值

返回一个 float 表示末端执行器的当前偏航角(以度为单位)。

例子

// Print the current yaw of the end effector
Brain.Screen.print(Arm.getYaw());

getRoll#

getRoll 返回末端执行器的当前滚动角度(以度为单位)。

可用功能

float getRoll();

参数

此函数没有参数。

返回值

返回一个 float 表示末端执行器的当前滚动角度(以度为单位)。

例子

// Print the current roll of the end effector
Brain.Screen.print(Arm.getRoll());

getPitch#

getPitch 返回末端执行器的当前俯仰角(以度为单位)。

可用功能

float getPitch();

参数

此函数没有参数。

返回值

返回一个 float 表示末端执行器的当前俯仰角(以度为单位)。

例子

// Print the current pitch of the end effector
Brain.Screen.print(Arm.getPitch());

canArmReachTo#

canArmReachTo 返回 6 轴机械臂是否可以将末端执行器移动到指定的 x、y 和 z 坐标。

使用此函数在执行 moveTo 之前检查目标位置。

可用功能

bool canArmReachTo(
  double x,
  double y,
  double z
);

范围

类型

描述

x

double

目标位置的 x 坐标(单位:毫米)。

y

double

目标位置的y坐标(单位:毫米)。

z

double

目标位置的z坐标(单位:毫米)。

返回值

返回布尔值。

  • true — 6轴机械臂可以到达所请求的位置。

  • false — 6轴机械臂无法到达请求的位置。

例子

// Move the 6-Axis Arm to (100, -20, 50) if it can reach
if (Arm.canArmReachTo(100, -20, 50)) {
  Arm.moveTo(100, -20, 50);
}

canArmReachInc#

canArmReachInc 返回 6 轴机械臂是否可以将末端执行器从其当前位置移动指定的 x、y 和 z 距离。

使用此函数在应用 moveInc 之前检查相对移动。

可用功能

bool canArmReachInc(
  double x,
  double y,
  double z
);

范围

类型

描述

x

double

沿 x 轴移动的距离(单位:毫米)。

y

double

沿 y 轴移动的距离(单位:毫米)。

z

double

沿 z 轴移动的距离,单位为毫米。

返回值

返回布尔值。

  • true — 6轴机械臂可以做出所请求的运动。

  • false — 6轴机械臂无法进行请求的运动。

例子

// Increment the 6-Axis Arm 100 mm along the x-axis if possible
if (Arm.canArmReachInc(100, 0, 0)) {
  Arm.moveInc(100, 0, 0);
}

canEndEffectorReachTo#

canEndEffectorReachTo 返回末端执行器是否可以旋转到指定的偏航角、横滚角和俯仰角。

使用此函数在执行 moveEndEffectorTo 之前检查目标方向。

可用功能

bool canEndEffectorReachTo(
  double yaw,
  double roll = 0,
  double pitch = 0
);

范围

类型

描述

yaw

double

目标偏航角(以度为单位)。

roll

double

可选。目标横滚角,单位为度。默认值为 0。

pitch

double

可选。目标俯仰角,单位为度。默认值为 0。

返回值

返回布尔值。

  • true — 末端执行器可以达到所要求的方向。

  • false — 末端执行器无法达到所请求的方向。

例子

// Rotate the end effector to 90 degrees of roll if possible
if (Arm.canEndEffectorReachTo(0, 90, 0)) {
  Arm.moveEndEffectorTo(0, 90, 0);
}

canEndEffectorReachInc#

canEndEffectorReachInc 返回末端执行器是否可以从其当前方向旋转指定的偏航角、横滚角和俯仰角。

使用此函数在应用 moveEndEffectorInc 之前检查相对方向移动。

可用功能

bool canEndEffectorReachInc(
  double yaw,
  double roll = 0,
  double pitch = 0
);

范围

类型

描述

yaw

double

偏航角的变化量,以度为单位。

roll

double

可选。滚动角度的变化量,以度为单位。默认值为 0。

pitch

double

可选。音调变化量,以度为单位。默认值为 0。

返回值

返回布尔值。

  • true — 末端执行器可以进行所请求的旋转。

  • false — 末端执行器无法进行所请求的旋转。

例子

// Increment the end effector by 10 degrees of pitch if possible
if (Arm.canEndEffectorReachInc(0, 0, 10)) {
  Arm.moveEndEffectorInc(0, 0, 10);
}

isConnected#

isConnected 返回 6 轴机械臂是否连接到 V5 大脑。

这是一个兼容性函数,返回与 installed 相同的值。

可用功能

bool isConnected();

参数

此函数没有参数。

返回值

返回布尔值。

  • true — 6轴机械臂连接到V5大脑。

  • false — 6轴机械臂未连接到V5大脑。

例子

// Print whether the 6-Axis Arm is connected
Brain.Screen.print(Arm.isConnected());

timestamp#

timestamp 返回从 6 轴机械臂接收到的最后一个状态数据包的时间戳。

可用功能

uint32_t timestamp();

参数

此函数没有参数。

返回值

返回最后一个状态数据包的时间戳,值为 uint32_t (毫秒)。

installed#

installed 返回 6 轴机械臂是否已连接。

可用功能

bool installed();

参数

此函数没有参数。

返回值

返回布尔值。

  • true — 6轴机械臂已连接。

  • false — 6轴机械臂未连接。

回调函数#

controlStopped#

controlStopped 注册一个在启用控制停止时运行的函数。

可用功能

void controlStopped(void (* callback)(void));

范围

类型

描述

callback

void (*)(void)

启用控制停止功能时运行的函数。

返回值

此函数不返回值。

例子

// Called when the 6-Axis Arm is control stopped
void onControlStopped() {
  Brain.Screen.print("Arm control stopped");
}

int main() {
  Arm.controlStopped(onControlStopped);
}

crashed#

crashed 注册了一个函数,当 6 轴机械臂在移动过程中发生碰撞时,该函数将运行。

当检测到碰撞时,六轴机械臂会停止电机运动,并可能出现无力状态。这可以减轻机械臂的压力,并有助于保护电机免受意外损坏。

可用功能

void crashed(void (* callback)(void));

范围

类型

描述

callback

void (*)(void)

当 6 轴机械臂在移动过程中发生碰撞时运行的函数。

返回值

此函数不返回值。

例子

// Called when the 6-Axis Arm crashes while moving
void onArmCrashed() {
  Brain.Screen.print("Crash detected");
}

int main() {
  Arm.crashed(onArmCrashed);
}