CTE手臂#

介绍#

The arm class provides control for the 6-Axis CTE Arm, allowing precise positioning and movement of the 6-Axis Robotic Arm in 3D space. This class supports both absolute and relative positioning, end effector control, and various sensor functions for monitoring arm status and capabilities.

类构造函数#

arm( 
  int32_t index );

类析构函数#

Destroys the arm object and releases associated resources.

~arm();

参数#

范围

类型

描述

index

int32_t

A valid Smart Port that the 6-Axis Arm is connected to, written as PORTx, where x is the port number (for example, PORT1).

例子#

// Create the arm instance in Port 1
arm Arm = arm(PORT1);

成员功能#

The arm class includes the following member functions:

  • moveTo — Moves the end effector to the requested x, y, and z coordinates.

  • moveInc — Moves the end effector by the requested x, y, and z distances relative to its current position.

  • moveEndEffectorTo — Moves the end effector to the requested absolute yaw, roll, and pitch orientation.

  • moveEndEffectorInc — Moves the end effector to the requested relative yaw, roll, and pitch orientation.

  • setEndEffectorType — Sets the type of end effector attached to the 6-Axis Arm.

  • setEndEffectorMagnet — Sets the end effector magnet to enabled or disabled.

  • setPenOffset — Sets the pen end effector z-axis offset.

  • setControlStop — Disables the 6-Axis Arm and places joint motors in brake mode.

  • controlStopped — Registers a function to be called when the 6-Axis Arm control stop is enabled.

  • isCrashed — Returns if the 6-Axis Arm has crashed while moving.

  • crashed — Registers a function to be called when the 6-Axis Arm has crashed while moving.

  • canArmReachTo — Returns if the end effector can move to the requested x, y, and z coordinates.

  • canArmReachInc — Returns if the end effector can move for a distance along the x, y, and z axes.

  • canEndEffectorReachTo — Returns if the end effector can move to the requested absolute yaw, roll, and pitch orientation.

  • canEndEffectorReachInc — Returns if the end effector can move for a distance along the yaw, pitch, or roll orientations.

  • isDone – Returns the status of 6-Axis Arm movement.

  • getX – Returns the X position of the end effector.

  • getY – Returns the y-position of the end effector.

  • getZ – Returns the 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.

  • setTimeout – Sets the timeout value used when moving the Arm.

  • isConnected – Returns if the 6-Axis Arm is connected.

  • timestamp – Returns the timestamp of the last received status packet from the Arm.

  • installed – Returns if the device is connected.

moveTo#

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

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

Parameters

范围

类型

描述

x

double

要移动到的 X 坐标,单位为毫米。

y

double

要移动到的 Y 坐标,单位为毫米。

z

double

要移动到的 Z 坐标,单位为毫米。

waitForCompletion

bool

  • true (default) — The project waits until the function finishes before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for the function to finish.

Return Values

返回一个布尔值,指示 6 轴机械臂是否到达目标位置。

  • true if the 6-Axis Arm reached the target position.

  • false if the 6-Axis Arm did not reach the target position or if waitForCompletion parameter is set to false.

Examples
// Move the arm to the (200, 0, 100)
Arm.moveTo(200, 0, 100);

moveInc#

使末端执行器相对于其当前位置移动所请求的 x、y 和 z 距离。

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

Parameters

范围

类型

描述

x

double

X 轴方向的移动距离,以毫米为单位。

y

double

Y轴方向需要移动的距离,以毫米为单位。

z

double

Z 轴方向的移动距离,以毫米为单位。

waitForCompletion

bool

  • true (default) — The project waits until the function finishes before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for the function to finish.

Return Values

返回一个布尔值,指示 6 轴机械臂是否到达目标位置。

  • true if the 6-Axis Arm reached the target position.

  • false if the 6-Axis Arm did not reach the target position or if waitForCompletion parameter is set to false.

Examples
// Move the Arm +100 millimeters on the Y axis
Arm.moveInc(0, 100, 0);

moveEndEffectorTo#

将末端执行器移动到所要求的绝对偏航角、横滚角和俯仰角。

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

Parameters

范围

类型

描述

yaw

double

末端执行器应指向的绕 Z 轴的角度,以度为单位。

roll

double

末端执行器绕 X 轴的指向角度,以度为单位。默认值为 0。

pitch

double

末端执行器绕 Y 轴的指向角度,单位为度。默认值为 0。

waitForCompletion

bool

  • true (default) — The project waits until the function finishes before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for the function to finish.

Return Values

返回一个布尔值,指示末端执行器是否达到目标方向。

  • true if the end effector reached the target orientation.

  • false if the end effector did not reach the target orientation or if waitForCompletion parameter is set to false.

Examples
// Orient the end effector to point towards 
// 90 degrees around the X axis
Arm.moveEndEffectorTo(0, 90, 0);

moveEndEffectorInc#

将末端执行器移动到所要求的相对偏航角、横滚角和俯仰角。

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

Parameters

范围

类型

描述

yaw

double

末端执行器绕 Z 轴改变的角度,以度为单位。

roll

double

末端执行器绕 X 轴改变的角度,以度为单位。默认值为 0。

pitch

double

末端执行器绕 Y 轴旋转的角度,以度为单位。默认值为 0。

waitForCompletion

bool

  • true (default) — The project waits until the function finishes before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for the function to finish.

Return Values

返回一个布尔值,指示末端执行器是否达到目标方向。

  • true if the end effector reached the target orientation.

  • false if the end effector did not reach the target orientation or if waitForCompletion parameter is set to false.

Examples
// Orient the end effector -50 degrees on the Y axis
Arm.moveEndEffectorInc(0, 0, -50);

setSpeed#

设置六轴机械臂运动速度。

Available Functions
void setSpeed( 
  uint32_t speed );

Parameters

范围

类型

描述

speed

uint32_t

6轴机械臂的移动速度(单位:毫米/秒)。

Return Values

此函数不返回值。

setEndEffectorType#

设置末端执行器类型为磁铁或笔。

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

Parameters

范围

类型

描述

type

endEffectorType

An end effector type:

  • magnet
  • pen

waitForCompletion

bool

  • true (default) — The project waits until the function finishes before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for the function to finish.

Return Values

返回一个布尔值,指示是否已设置请求的类型。

  • true if the requested type was set.

  • false if the requested type was not set or if waitForCompletion parameter is set to false.

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

setEndEffectorMagnet#

设置末端执行器磁铁的启用或禁用状态。

Available Functions
void setEndEffectorMagnet( 
  bool enabled );

Parameters

范围

类型

描述

enabled

bool

  • true – enable the magnet
  • false – disable the magnet

Return Values

此函数不返回值。

Examples
// Enable the Magnet Pickup Tool
Arm.setEndEffectorMagnet(true);

setPenOffset#

设置笔端执行器 Z 轴偏移量。

Available Functions
void setPenOffset( 
  double zOffset );

Parameters

范围

类型

描述

zOffset

double

新的偏移量,单位为毫米。正的 z 值表示向上。

Return Values

此函数不返回值。

setControlStop#

禁用 6 轴机械臂并将关节电机置于制动模式。

Available Functions
void setControlStop( 
  bool state = true);

Parameters

范围

类型

描述

state

bool

  • true (default) — Disable further linear or joint moves.
  • false — Enable further linear or joint moves.

Return Values

此函数不返回值。

controlStopped#

注册一个函数,当启用 6 轴机械臂控制停止功能时,该函数将被调用。

Available Functions
void controlStopped( 
  void (* callback)(void) );

Parameters

范围

类型

描述

callback

void (*)(void)

当 6 轴机械臂停止控制时将调用的函数。

Return Values

此函数不返回值。

Examples Examples

Define the callback function (outside of int main())

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

Register the callback inside int main()

/* vexcodeInit() is only required when using VEXcode.
Remove vexcodeInit() if compiling in VS Code. */
int main() {
  vexcodeInit();

  Arm.controlStopped(onControlStopped);
}

isCrashed#

返回 6 轴机械臂在移动过程中发生碰撞的情况。

**注意:**当检测到碰撞时,六轴机械臂的电机将停止所有运动,机械臂会暂时失去动力。这是为了减少电机负荷,保护电机免受意外损坏。

Available Functions
bool isCrashed();

Parameters

此函数不接受任何参数。

Return Values

Returns true if the 6-Axis Arm has crashed while moving, false if it has not.

Examples
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

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

  // While moving check for a crash
  while (true) {
    if (Arm10.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;
    }
  }
}

crashed#

注册一个函数,当 6 轴机械臂在移动过程中发生碰撞时,该函数将被调用。

**注意:**当检测到碰撞时,六轴机械臂的电机将停止所有运动,机械臂会暂时失去动力。这是为了减少电机负荷,保护电机免受意外损坏。

Available Functions
void crashed(
  void (* callback)(void) );

Parameters

范围

类型

描述

callback

void (*)(void)

当 6 轴机械臂在移动过程中发生碰撞时,将调用此函数。

Return Values

此函数不返回值。

Examples Examples

Define the callback function (outside of int main())

// 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);
}

Register the callback inside int main()

/* vexcodeInit() is only required when using VEXcode.
Remove vexcodeInit() if compiling in VS Code. */
int main() {
  vexcodeInit();

  Arm.crashed(onArmCrashed);
}

canArmReachTo#

返回末端执行器是否可以移动到请求的 x、y 和 z 坐标。

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

Parameters

范围

类型

描述

x

double

要移动到的 X 坐标,单位为毫米。

y

double

要移动到的 Y 坐标,单位为毫米。

z

double

要移动到的 Z 坐标,单位为毫米。

Return Values

Returns true if the 6-Axis Arm can move to the requested position, false if it cannot.

Examples
// Check if the arm can move to the (100, -20, 50).
if (Arm.canArmReachTo(100, -20, 50)){
  // Move the arm to (100, -20, 50).
  Arm.moveTo(100, -20, 50);
}

canArmReachInc#

返回末端执行器能否沿 x、y 和 z 轴移动一定距离。

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

Parameters

范围

类型

描述

x

double

X 轴方向的移动距离,以毫米为单位。

y

double

Y轴方向需要移动的距离,以毫米为单位。

z

double

Z 轴方向的移动距离,以毫米为单位。

Return Values

返回一个布尔值,指示 6 轴机械臂是否可以移动到请求的位置。

  • true if the 6-Axis Arm can move to the requested position.

  • false if the 6-Axis Arm cannot move to the requested position.

Examples
// Check if the arm can increment by 100 mm along the x-axis
if (Arm.canArmReachInc(100, 0, 0)){
  // Increment the arm by 100 mm along the x-axis
  Arm.moveInc(100, 0, 0);
}

canEndEffectorReachTo#

返回末端执行器能否移动到所请求的绝对偏航角、横滚角和俯仰角。

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

Parameters

范围

类型

描述

yaw

double

末端执行器应指向的绕 Z 轴的角度,以度为单位。

roll

double

末端执行器绕 X 轴的指向角度,以度为单位。默认值为 0。

pitch

double

末端执行器绕 Y 轴的指向角度,单位为度。默认值为 0。

Return Values

返回一个布尔值,指示末端执行器是否可以移动到请求的方向。

  • true if the end effector can move to the requested orientation.

  • false if the end effector cannot move to the requested orientation.

Examples
// Check if the arm can orient 25 degrees around the z-axis
if (Arm.canEndEffectorReachTo(25, 0, 0)){
  // Orient to 25 degrees around the z-axis
  Arm.moveEndEffectorTo(25, 0, 0);
}

canEndEffectorReachInc#

返回末端执行器能否沿偏航、俯仰或横滚方向移动一段距离。

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

Parameters

范围

类型

描述

yaw

double

末端执行器绕 z 轴移动的角度,以度为单位。

roll

double

末端执行器绕 x 轴移动的角度,以度为单位。默认值为 0。

pitch

double

末端执行器绕 y 轴旋转的角度,单位为度。默认值为 0。

Return Values

返回一个布尔值,指示末端执行器是否可以移动到请求的方向。

  • true if the end effector can move to the requested orientation.

  • false if the end effector cannot move to the requested orientation.

Examples
// Check If the arm can increment its orientation 
// by 10 degrees on the X axis.
if (Arm.canEndEffectorReachInc(0, 10, 0)){
  // Move +10 degrees around the x-axis
  Arm.moveEndEffectorInc(0, 10, 0);
}

isDone#

返回 6 轴机械臂运动状态。

Available Functions
bool isDone();

Parameters

此函数没有参数。

Return Values

返回一个布尔值,指示 6 轴机械臂是否已完成其运动。

  • true if the 6-Axis Arm has completed its movement.

  • false if the 6-Axis Arm is still moving.

Examples
// Move Arm to (-100, 200, 100) and let subsequent methods execute
Arm.moveTo(-100, 200, 100, false);
// Keep repeating the methods until the Arm is done moving
while (!Arm.isDone()) {
  // Print the Arm's current Y coordinate on the Brain every .25 seconds
  Brain.Screen.print(Arm.getY());
  Brain.Screen.newLine();
  wait(0.25, seconds);
}

getX#

返回末端执行器的 X 坐标。

Available Functions
float getX();

Parameters

此函数没有参数。

Return Values

Returns a float representing the X position of the end effector in millimeters.

Examples
// Print the current x-position of the arm in degrees
Brain.Screen.print(Arm.getX());

getY#

返回末端执行器的 y 坐标。

Available Functions
float getY();

Parameters

此函数没有参数。

Return Values

Returns a float representing the y-position of the end effector in millimeters.

Examples
// Print the current y-position of the Arm in degrees
Brain.Screen.print(Arm.getY());

getZ#

返回末端执行器的 z 轴位置。

Available Functions
float getZ();

Parameters

此函数没有参数。

Return Values

Returns a float representing the z-position of the end effector in millimeters.

Examples
// Print the current z-position of the Arm in degrees
Brain.Screen.print(Arm.getZ());

getYaw#

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

Available Functions
float getYaw();

Parameters

此函数没有参数。

Return Values

Returns a float representing the current yaw of the end effector in degrees.

Examples
// Print the current yaw of the Arm in degrees
Brain.Screen.print(Arm.getYaw());

getRoll#

返回末端执行器的当前滚动方向。

Available Functions
float getRoll();

Parameters

此函数没有参数。

Return Values

Returns a float representing the current roll of the end effector in degrees.

Examples
// Print the current roll of the Arm in degrees
Brain.Screen.print(Arm.getRoll());

getPitch#

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

Available Functions
float getPitch();

Parameters

此函数没有参数。

Return Values

Returns a float representing the current pitch of the end effector in degrees.

Examples
// Print the current pitch of the Arm in degrees
Brain.Screen.print(Arm.getPitch());

setTimeout#

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

Available Functions
void setTimeout( 
  int32_t   timeout, 
  timeUnits units );

Parameters

范围

类型

描述

timeout

int32_t

新的超时值。

units

timeUnits

The unit that represents the time:

  • sec – seconds
  • msec – milliseconds

Return Values

此函数不返回值。

isConnected#

返回六轴机械臂是否已连接。这是一个兼容性函数,其返回值与 installed() 函数相同。

Available Functions
bool isConnected();

Parameters

此函数没有参数。

Return Values

返回一个布尔值,指示 6 轴机械臂是否通过关联的智能端口连接到大脑。

  • true if the 6-Axis Arm is connected to the brain on the associated smartport.

  • false if the 6-Axis Arm is not connected to the brain on the associated smartport.

timestamp#

返回从 Arm 接收到的最后一个状态数据包的时间戳。

Available Functions
uint32_t timestamp();

Parameters

此函数没有参数。

Return Values

Returns the timestamp of the last status packet as a uint32_t in milliseconds.

installed#

返回设备已连接的状态。

Available Functions
bool installed();

Parameters

此函数没有参数。

Return Values

返回一个布尔值,指示设备是否已连接。

  • true if the device is connected.

  • false if the device is not connected.