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);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
6軸機械手臂連接的智慧型端口,記為 |
例子
// 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— 將末端執行器旋轉指定的偏航角、橫滾角和俯仰角。
變異器 — 配置移動、工具和控制設定。
setSpeed— 設定 6 軸機械手臂的運動速度。setEndEffectorType— 設定連接到 6 軸機械手臂的末端執行器的類型。setEndEffectorMagnet— 啟用或停用磁鐵拾取工具。setPenOffset— 設定筆架工具所使用的 z 軸偏移量。setControlStop— 啟用或停用 6 軸機械手臂的控制停止。setTimeout— 設定 6 軸機械手臂運動函數所使用的逾時時間。
獲取器 — 返回運動狀態、位置、方向和連接值。
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 座標(單位:毫米)。 |
|
|
目標位置的y座標(單位:毫米)。 |
|
|
目標位置的z座標(單位:毫米)。 |
|
|
可選。 0 為真 |
傳回值
返回布林值。
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 軸移動的距離(單位:毫米)。 |
|
|
沿 y 軸移動的距離(單位:毫米)。 |
|
|
沿 z 軸移動的距離,單位為毫米。 |
|
|
可選。 0 為真 |
傳回值
返回布林值。
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
);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
目標偏航角(以度為單位)。 |
|
|
可選。目標橫滾角,單位為度。預設值為 |
|
|
可選。目標俯仰角,單位為度。預設值為 |
|
|
可選。 0 為真 |
傳回值
返回布林值。
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
);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
偏航角的變化量,以度為單位。 |
|
|
可選。滾動角度的變化量,以度為單位。預設值為 |
|
|
可選。音調變化量,以度為單位。預設值為 |
|
|
可選。 0 為真 |
傳回值
返回布林值。
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);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
6軸機械手臂的移動速度,單位為毫米每秒。 |
傳回值
此函數不傳回值。
例子
// Set the 6-Axis Arm movement speed
Arm.setSpeed(100);
setEndEffectorType#
setEndEffectorType 設定連接到 6 軸機械手臂的末端執行器的類型。
當末端執行器類型改變時,6軸機械手臂會自動調整其z軸偏移量以符合所選工具。
可用功能
bool setEndEffectorType(
endEffectorType type,
bool waitForCompletion = true
);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
安裝在 6 軸臂上的工具: |
|
|
可選。 0 為真 |
傳回值
返回布林值。
true— 請求的類型已設定。false— 請求的類型未設置,或waitForCompletion設定為false。
例子
// Set the end effector type to the Magnet Pickup Tool
Arm.setEndEffectorType(magnet);
setEndEffectorMagnet#
setEndEffectorMagnet 啟用或停用磁鐵拾取工具。
可用功能
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 設定當筆架工具連接到 6 軸臂時所使用的 z 軸偏移量。
使用此功能前,請將末端執行器類型設定為 pen 如果未選擇筆架工具,此功能無效。
筆偏移量是指從筆架工具頂部到白板筆筆尖的距離。正的 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 啟用或停用 6 軸機械手臂的控制停止。
啟用控制停止功能後,6 軸機械手臂會立即停止運動,並防止進一步的線性或關節運動。
可用功能
void setControlStop(bool state = true);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
可選。 0 為真 |
傳回值
此函數不傳回值。
例子
// Stop the 6-Axis Arm and prevent further movement
Arm.setControlStop();
setTimeout#
setTimeout 設定移動 6 軸機械手臂時所使用的逾時值。
如果在逾時之前某個動作沒有完成,專案將繼續下一行程式碼。
可用功能
void setTimeout(
int32_t timeout,
timeUnits units
);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
新的超時值。 |
|
|
時間單位: |
傳回值
此函數不傳回值。
例子
// 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 座標(單位:毫米)。 |
|
|
目標位置的y座標(單位:毫米)。 |
|
|
目標位置的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 軸移動的距離(單位:毫米)。 |
|
|
沿 y 軸移動的距離(單位:毫米)。 |
|
|
沿 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
);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
目標偏航角(以度為單位)。 |
|
|
可選。目標橫滾角,單位為度。預設值為 |
|
|
可選。目標俯仰角,單位為度。預設值為 |
傳回值
返回布林值。
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
);
範圍 |
類型 |
描述 |
|---|---|---|
|
|
偏航角的變化量,以度為單位。 |
|
|
可選。滾動角度的變化量,以度為單位。預設值為 |
|
|
可選。音調變化量,以度為單位。預設值為 |
傳回值
返回布林值。
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));
範圍 |
類型 |
描述 |
|---|---|---|
|
|
啟用控制停止功能時運行的函數。 |
傳回值
此函數不傳回值。
例子
// 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));
範圍 |
類型 |
描述 |
|---|---|---|
|
|
當 6 軸機械手臂在移動過程中發生碰撞時所運行的函數。 |
傳回值
此函數不傳回值。
例子
// Called when the 6-Axis Arm crashes while moving
void onArmCrashed() {
Brain.Screen.print("Crash detected");
}
int main() {
Arm.crashed(onArmCrashed);
}