CTE手臂#
介绍#
The arm class provides control for the 6-Axis Arm used in the CTE Workcell. In VEX EXP C++, the 6-Axis Arm can move an end effector to positions in three-dimensional space, rotate the end effector, check whether movements are possible, and control attached tools such as the Magnet Pickup Tool or Pen Holder Tool.
The examples on this page use a configured 6-Axis Arm named Arm.
构造函数#
arm#
arm creates a 6-Axis Arm object.
可用功能
arm(int32_t index);
范围 |
类型 |
描述 |
|---|---|---|
|
|
The Smart Port that the 6-Axis Arm is connected to, written as |
例子
// Create a 6-Axis Arm named Arm on Port 1
arm Arm = arm(PORT1);
毁灭者#
~arm#
~arm destroys the arm object and releases associated resources.
可用功能
~arm();
成员功能#
The arm class includes the following member functions:
动作——将六轴机械臂移动到指定位置或方向。
moveTo— Moves the end effector to a specified x, y, and z coordinate.moveInc— Moves the end effector by a specified distance from its current position.moveEndEffectorTo— Rotates the end effector to a specified yaw, roll, and pitch orientation.moveEndEffectorInc— Rotates the end effector by a specified yaw, roll, and pitch amount.
变异器 — 配置移动、工具和控制设置。
setSpeed— Sets the movement speed used by the 6-Axis Arm.setEndEffectorType— Sets the type of end effector attached to the 6-Axis Arm.setEndEffectorMagnet— Enables or disables the Magnet Pickup Tool.setPenOffset— Sets the z-axis offset used with the Pen Holder Tool.setControlStop— Enables or disables control stop for the 6-Axis Arm.setTimeout— Sets the timeout used by 6-Axis Arm movement functions.
获取器 — 返回运动状态、位置、方向和连接值。
isDone— Returns whether the 6-Axis Arm has finished moving.isCrashed— Returns whether the 6-Axis Arm has crashed while moving.getX— Returns the current x position of the end effector.getY— Returns the current y position of the end effector.getZ— Returns the current z position of the end effector.getYaw— Returns the current yaw of the end effector.getRoll— Returns the current roll of the end effector.getPitch— Returns the current pitch of the end effector.canArmReachTo— Returns whether the 6-Axis Arm can reach a specified position.canArmReachInc— Returns whether the 6-Axis Arm can move by a specified distance.canEndEffectorReachTo— Returns whether the end effector can reach a specified orientation.canEndEffectorReachInc— Returns whether the end effector can rotate by a specified amount.isConnected— Returns whether the 6-Axis Arm is connected to the EXP Brain.timestamp— Returns the timestamp of the last received status packet from the 6-Axis Arm.installed— Returns whether the 6-Axis Arm is connected.
回调函数——在发生起动事件时运行函数。
controlStopped— Registers a function to run when control stop is enabled.crashed— Registers a function to run when a crash is detected.
行动#
moveTo#
moveTo moves the 6-Axis Arm to a specified x, y, and z coordinate.
The x, y, and z coordinates describe the position of the end effector in three-dimensional space. Use canArmReachTo before this function if the target position may be outside the 6-Axis Arm’s reachable workspace.
可用功能
bool moveTo(
double x,
double y,
double z,
bool waitForCompletion = true
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
目标位置的 x 坐标(单位:毫米)。 |
|
|
目标位置的y坐标(单位:毫米)。 |
|
|
目标位置的z坐标(单位:毫米)。 |
|
|
Optional. |
返回值
返回布尔值。
true— The 6-Axis Arm reached the target position.false— The 6-Axis Arm did not reach the target position, orwaitForCompletionwas set tofalse.
示例
// 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 moves the 6-Axis Arm by a specified distance from its current position along the x, y, and z axes.
Use this function to move relative to where the end effector is now. Use canArmReachInc before this function if the movement may place the 6-Axis Arm outside its reachable workspace.
可用功能
bool moveInc(
double x,
double y,
double z,
bool waitForCompletion = true
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
沿 x 轴移动的距离(单位:毫米)。 |
|
|
沿 y 轴移动的距离(单位:毫米)。 |
|
|
沿 z 轴移动的距离,单位为毫米。 |
|
|
Optional. |
返回值
返回布尔值。
true— The 6-Axis Arm reached the requested position.false— The 6-Axis Arm did not reach the requested position, orwaitForCompletionwas set tofalse.
例子
// Move the 6-Axis Arm 100 millimeters along the y-axis
Arm.moveInc(0, 100, 0);
moveEndEffectorTo#
moveEndEffectorTo rotates the 6-Axis Arm’s end effector to a specified yaw, roll, and pitch orientation.
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
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
目标偏航角(以度为单位)。 |
|
|
Optional. The target roll angle in degrees. The default is |
|
|
Optional. The target pitch angle in degrees. The default is |
|
|
Optional. |
返回值
返回布尔值。
true— The end effector reached the target orientation.false— The end effector did not reach the target orientation, orwaitForCompletionwas set tofalse.
例子
// Rotate the end effector to 90 degrees of roll
Arm.moveEndEffectorTo(0, 90, 0);
moveEndEffectorInc#
moveEndEffectorInc rotates the 6-Axis Arm’s end effector by a specified yaw, roll, and pitch amount from its current orientation.
使用此功能可相对于末端执行器的当前偏航角、横滚角或俯仰角进行旋转。
可用功能
bool moveEndEffectorInc(
double yaw,
double roll = 0,
double pitch = 0,
bool waitForCompletion = true
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
偏航角的变化量,以度为单位。 |
|
|
Optional. The change in roll, in degrees. The default is |
|
|
Optional. The change in pitch, in degrees. The default is |
|
|
Optional. |
返回值
返回布尔值。
true— The end effector reached the requested orientation.false— The end effector did not reach the requested orientation, orwaitForCompletionwas set tofalse.
例子
// Rotate the end effector -50 degrees in pitch
Arm.moveEndEffectorInc(0, 0, -50);
变异体#
setSpeed#
setSpeed sets the movement speed used by the 6-Axis Arm.
可用功能
void setSpeed(uint32_t speed);
范围 |
类型 |
描述 |
|---|---|---|
|
|
6轴机械臂的移动速度,单位为毫米每秒。 |
返回值
此函数不返回值。
例子
// Set the 6-Axis Arm movement speed
Arm.setSpeed(100);
setEndEffectorType#
setEndEffectorType sets the type of end effector attached to the 6-Axis Arm.
当末端执行器类型改变时,6轴机械臂会自动调整其z轴偏移量以匹配所选工具。
可用功能
bool setEndEffectorType(
endEffectorType type,
bool waitForCompletion = true
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
The tool attached to the 6-Axis Arm: |
|
|
Optional. |
返回值
返回布尔值。
true— The requested type was set.false— The requested type was not set, orwaitForCompletionwas set tofalse.
例子
// Set the end effector type to the Magnet Pickup Tool
Arm.setEndEffectorType(magnet);
setEndEffectorMagnet#
setEndEffectorMagnet enables or disables the Magnet Pickup Tool.
可用功能
void setEndEffectorMagnet(bool enabled);
范围 |
类型 |
描述 |
|---|---|---|
|
|
|
返回值
此函数不返回值。
例子
// Pick up objects and then drop them
Arm.setEndEffectorType(magnet);
Arm.setEndEffectorMagnet(true);
wait(2, seconds);
Arm.setEndEffectorMagnet(false);
setPenOffset#
setPenOffset sets the z-axis offset used when the Pen Holder Tool is attached to the 6-Axis Arm.
Set the end effector type to pen before using this function. If the Pen Holder Tool is not selected, this function has no effect.
笔偏移量是指从笔架工具顶部到白板笔笔尖的距离。正的 z 值会使偏移量从工具安装点向上移动。
可用功能
void setPenOffset(double zOffset);
范围 |
类型 |
描述 |
|---|---|---|
|
|
笔偏移值,单位为毫米。 |
返回值
此函数不返回值。
例子
// Set the end effector type to the Pen Holder Tool and set the pen offset
Arm.setEndEffectorType(pen);
Arm.setPenOffset(25);
setControlStop#
setControlStop enables or disables control stop for the 6-Axis Arm.
启用控制停止功能后,6 轴机械臂会立即停止运动,并防止进一步的线性或关节运动。
可用功能
void setControlStop(bool state = true);
范围 |
类型 |
描述 |
|---|---|---|
|
|
Optional. |
返回值
此函数不返回值。
例子
// Stop the 6-Axis Arm and prevent further movement
Arm.setControlStop();
setTimeout#
setTimeout sets the timeout value used when moving the 6-Axis Arm.
如果在超时之前某个动作没有完成,项目将继续执行下一行代码。
可用功能
void setTimeout(
int32_t timeout,
timeUnits units
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
新的超时值。 |
|
|
The time unit: |
返回值
此函数不返回值。
例子
// Set the 6-Axis Arm timeout to 2 seconds
Arm.setTimeout(2, sec);
获取器#
isDone#
isDone returns whether the 6-Axis Arm has finished moving.
This function is useful after a movement function is called with waitForCompletion set to false.
可用功能
bool isDone();
参数
此函数没有参数。
返回值
返回布尔值。
true— The 6-Axis Arm has finished moving.false— The 6-Axis Arm is still moving.
例子
// 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 returns whether the 6-Axis Arm has crashed while moving.
当检测到碰撞时,六轴机械臂会停止电机运动,并可能出现无力状态。这可以减轻机械臂的压力,并有助于保护电机免受意外损坏。
可用功能
bool isCrashed();
参数
此函数没有参数。
返回值
返回布尔值。
true— The 6-Axis Arm has crashed.false— The 6-Axis Arm has not crashed.
例子
// 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 Signal Tower and Brain screen
Brain.Screen.print("Crash Detected");
SignalTower6.setColor(signaltower::green, signaltower::off);
SignalTower6.setColor(signaltower::red, signaltower::on);
break;
}
wait(5, msec);
}
getX#
getX returns the current x position of the end effector in millimeters.
使用此函数读取末端执行器当前沿 x 轴的位置。
可用功能
float getX();
参数
此函数没有参数。
返回值
Returns a float representing the x position of the end effector in millimeters.
例子
// Print the current x position of the 6-Axis Arm
Brain.Screen.print(Arm.getX());
getY#
getY returns the current y position of the end effector in millimeters.
使用此函数读取末端执行器当前沿 y 轴的位置。
可用功能
float getY();
参数
此函数没有参数。
返回值
Returns a float representing the y position of the end effector in millimeters.
例子
// Print the current y position of the 6-Axis Arm
Brain.Screen.print(Arm.getY());
getZ#
getZ returns the current z position of the end effector in millimeters.
使用此函数读取末端执行器当前沿 z 轴的位置。
可用功能
float getZ();
参数
此函数没有参数。
返回值
Returns a float representing the z position of the end effector in millimeters.
例子
// Print the current z position of the 6-Axis Arm
Brain.Screen.print(Arm.getZ());
getYaw#
getYaw returns the current yaw of the end effector in degrees.
可用功能
float getYaw();
参数
此函数没有参数。
返回值
Returns a float representing the current yaw of the end effector in degrees.
例子
// Print the current yaw of the end effector
Brain.Screen.print(Arm.getYaw());
getRoll#
getRoll returns the current roll of the end effector in degrees.
可用功能
float getRoll();
参数
此函数没有参数。
返回值
Returns a float representing the current roll of the end effector in degrees.
例子
// Print the current roll of the end effector
Brain.Screen.print(Arm.getRoll());
getPitch#
getPitch returns the current pitch of the end effector in degrees.
可用功能
float getPitch();
参数
此函数没有参数。
返回值
Returns a float representing the current pitch of the end effector in degrees.
例子
// Print the current pitch of the end effector
Brain.Screen.print(Arm.getPitch());
canArmReachTo#
canArmReachTo returns whether the 6-Axis Arm can move the end effector to a specified x, y, and z coordinate.
Use this function to check a target position before using moveTo.
可用功能
bool canArmReachTo(
double x,
double y,
double z
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
目标位置的 x 坐标(单位:毫米)。 |
|
|
目标位置的y坐标(单位:毫米)。 |
|
|
目标位置的z坐标(单位:毫米)。 |
返回值
返回布尔值。
true— The 6-Axis Arm can reach the requested position.false— The 6-Axis Arm cannot reach the requested position.
例子
// 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 returns whether the 6-Axis Arm can move the end effector by a specified x, y, and z distance from its current position.
Use this function to check a relative movement before using moveInc.
可用功能
bool canArmReachInc(
double x,
double y,
double z
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
沿 x 轴移动的距离(单位:毫米)。 |
|
|
沿 y 轴移动的距离(单位:毫米)。 |
|
|
沿 z 轴移动的距离,单位为毫米。 |
返回值
返回布尔值。
true— The 6-Axis Arm can make the requested movement.false— The 6-Axis Arm cannot make the requested movement.
例子
// 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 returns whether the end effector can rotate to a specified yaw, roll, and pitch orientation.
Use this function to check a target orientation before using moveEndEffectorTo.
可用功能
bool canEndEffectorReachTo(
double yaw,
double roll = 0,
double pitch = 0
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
目标偏航角(以度为单位)。 |
|
|
Optional. The target roll angle in degrees. The default is |
|
|
Optional. The target pitch angle in degrees. The default is |
返回值
返回布尔值。
true— The end effector can reach the requested orientation.false— The end effector cannot reach the requested orientation.
例子
// Rotate the end effector to 90 degrees of roll if possible
if (Arm.canEndEffectorReachTo(0, 90, 0)) {
Arm.moveEndEffectorTo(0, 90, 0);
}
canEndEffectorReachInc#
canEndEffectorReachInc returns whether the end effector can rotate by a specified yaw, roll, and pitch amount from its current orientation.
Use this function to check a relative orientation movement before using moveEndEffectorInc.
可用功能
bool canEndEffectorReachInc(
double yaw,
double roll = 0,
double pitch = 0
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
偏航角的变化量,以度为单位。 |
|
|
Optional. The change in roll, in degrees. The default is |
|
|
Optional. The change in pitch, in degrees. The default is |
返回值
返回布尔值。
true— The end effector can make the requested rotation.false— The end effector cannot make the requested rotation.
例子
// Increment the end effector by 10 degrees of pitch if possible
if (Arm.canEndEffectorReachInc(0, 0, 10)) {
Arm.moveEndEffectorInc(0, 0, 10);
}
isConnected#
isConnected returns whether the 6-Axis Arm is connected to the EXP Brain.
This is a compatibility function that returns the same value as installed.
可用功能
bool isConnected();
参数
此函数没有参数。
返回值
返回布尔值。
true— The 6-Axis Arm is connected to the EXP Brain.false— The 6-Axis Arm is not connected to the EXP Brain.
例子
// Print whether the 6-Axis Arm is connected
Brain.Screen.print(Arm.isConnected());
timestamp#
timestamp returns the timestamp of the last received status packet from the 6-Axis Arm.
可用功能
uint32_t timestamp();
参数
此函数没有参数。
返回值
Returns the timestamp of the last status packet as a uint32_t in milliseconds.
installed#
installed returns whether the 6-Axis Arm is connected.
可用功能
bool installed();
参数
此函数没有参数。
返回值
返回布尔值。
true— The 6-Axis Arm is connected.false— The 6-Axis Arm is not connected.
回调函数#
controlStopped#
controlStopped registers a function that runs when control stop is enabled.
可用功能
void controlStopped(void (* callback)(void));
范围 |
类型 |
描述 |
|---|---|---|
|
|
启用控制停止功能时运行的函数。 |
返回值
此函数不返回值。
例子
// Called when the 6-Axis Arm is control stopped
void onControlStopped() {
Brain.Screen.print("Arm control stopped");
}
int main() {
vexcodeInit();
Arm.controlStopped(onControlStopped);
}
crashed#
crashed registers a function that runs when the 6-Axis Arm has crashed while moving.
当检测到碰撞时,六轴机械臂会停止电机运动,并可能出现无力状态。这可以减轻机械臂的压力,并有助于保护电机免受意外损坏。
可用功能
void crashed(void (* callback)(void));
范围 |
类型 |
描述 |
|---|---|---|
|
|
当 6 轴机械臂在移动过程中发生碰撞时运行的函数。 |
返回值
此函数不返回值。
例子
// Called when the 6-Axis Arm crashes while moving
void onArmCrashed() {
Brain.Screen.print("Crash detected");
SignalTower6.setColor(signaltower::green, signaltower::off);
SignalTower6.setColor(signaltower::red, signaltower::on);
}
int main() {
vexcodeInit();
Arm.crashed(onArmCrashed);
}