六軸機械手臂#

介紹#

VEX 六軸機械手臂 是 CTE 工作單元中使用的一種機械手臂。在 VEXcode EXP 中,機械手臂方法允許 EXP 控制器移動六軸機械手臂、旋轉其末端執行器、檢查運動是否可行,並控制諸如磁性拾取工具或筆架工具等連接的工具。

本頁面適用於將六軸機械手臂連接到 EXP Brain 的 CTE 工作單元專案。如果您單獨使用六軸機械手臂和 CTE Tile,請改用 CTE 機械手臂 API 頁面。

本頁上的範例使用名為 arm1的配置 6 軸機械手臂。

以下是所有可用方法的清單:

動作-將六軸機械手臂移到指定位置或方向。

  • move_to — 將末端執行器移到指定的 x、y 和 z 座標。

  • move_inc — 將末端執行器從目前位置移動指定的距離。

  • move_end_effector_to — 將末端執行器旋轉到指定的偏航角、橫滾角和俯仰角方向。

  • move_end_effector_inc — 將末端執行器旋轉指定的偏航角、橫滾角和俯仰角。

變異器 — 配置移動、工具和控制設定。

獲取器 — 返回運動狀態、位置、方向和連接值。

  • is_done — 返回 6 軸機械手臂是否已完成移動。

  • is_crashed — 傳回 6 軸機械手臂在移動過程中是否發生碰撞。

  • get_x — 傳回末端執行器的目前 x 位置。

  • get_y — 傳回末端執行器的目前 y 位置。

  • get_z — 傳回末端執行器的目前 z 位置。

  • get_pitch — 傳回末端執行器的目前俯仰角。

  • get_roll — 傳回末端執行器的目前滾動角度。

  • get_yaw — 傳回末端執行器的目前偏航角。

  • can_arm_reach_to — 返回 6 軸機械手臂是否可以到達指定位置。

  • can_arm_reach_inc — 傳回 6 軸機械手臂是否可以移動指定的距離。

  • can_end_effector_reach_to — 傳回末端執行器是否可以達到指定的方向。

  • can_end_effector_reach_inc — 傳回末端執行器是否可以旋轉指定的量。

  • get_timeout — 傳回移動方法所使用的目前逾時值。

  • is_connected — 返回 6 軸機械手臂是否連接到 EXP 大腦。

回呼函數-在發生啟動事件時運行函數。

  • control_stopped — 註冊一個在啟用控制停止時要執行的函式。

  • crashed — 註冊一個在偵測到崩潰時要執行的函數。

建構函數-手動建立一個六軸機械手臂物件。

  • Arm — 建立一個 6 軸機械手臂物件。

行動#

move_to#

move_to 將 6 軸機械手臂移動到指定的 x、y 和 z 座標。

x、y 和 z 座標描述了末端執行器在三維空間中的位置。如果目標位置可能超出六軸機械手臂的可達工作空間,請在此方法之前使用 can_arm_reach_to。

Usage:
arm1.move_to(x, y, z, wait)

範圍

描述

x

目標位置的 x 座標(單位:毫米)。

y

目標位置的y座標(單位:毫米)。

z

目標位置的z座標(單位:毫米)。

wait

可選 wait=True (預設值)使項目等待移動完成後再繼續。 2 wait=False 開始移動並立即繼續下一行程式碼。

# Move the 6-Axis Arm to (40, 140, 210)
arm1.move_to(40, 140, 210)

# Start moving, then print the y-position while the arm moves
arm1.move_to(-100, 200, 100, wait=False)

while not arm1.is_done():
    brain.screen.print(arm1.get_y())
    brain.screen.next_row()
    wait(0.25, SECONDS)

move_inc#

move_inc 將 6 軸機械手臂沿著 x、y 和 z 軸從其目前位置移動指定的距離。

使用此方法相對於末端執行器目前位置進行移動。如果移動可能將六軸機械手臂置於其可達工作空間之外,請在此方法之前使用 can_arm_reach_inc。

Usage:
arm1.move_inc(x, y, z, wait)

範圍

描述

x

沿 x 軸移動的距離(單位:毫米)。

y

沿 y 軸移動的距離(單位:毫米)。

z

沿 z 軸移動的距離,單位為毫米。

wait

可選 wait=True (預設值)使項目等待移動完成後再繼續。 2 wait=False 開始移動並立即繼續下一行程式碼。

# Move the 6-Axis Arm 100 millimeters along the y-axis
arm1.move_inc(0, 100, 0)

move_end_effector_to#

move_end_effector_to 將 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.

Usage:
arm1.move_end_effector_to(yaw, roll, pitch, wait)

範圍

描述

yaw

目標偏航角,單位為度。

roll

目標滾動角,單位為度。

pitch

目標俯仰角,單位為度。

wait

可選 wait=True (預設值)使項目等待移動完成後再繼續。 2 wait=False 開始移動並立即繼續下一行程式碼。

# Rotate the end effector to 90 degrees of roll
arm1.move_end_effector_to(0, 90, 0)

move_end_effector_inc#

move_end_effector_inc 將 6 軸機械手臂的末端執行器從其目前方向旋轉指定的偏航角、橫滾角和俯仰角。

使用此方法可相對於末端執行器的目前偏航角、橫滾角或俯仰角進行旋轉。

Usage:
arm1.move_end_effector_inc(yaw, roll, pitch, wait)

範圍

描述

yaw

偏航角的變化量,以度為單位。

roll

滾動角度的變化量,以度為單位。

pitch

音調的變化,以度為單位。

wait

可選 wait=True (預設值)使項目等待移動完成後再繼續。 2 wait=False 開始移動並立即繼續下一行程式碼。

# Rotate the end effector -50 degrees in pitch
arm1.move_end_effector_inc(0, 0, -50)

突變體#

set_speed#

set_speed 設定 6 軸機械手臂在運動方式中使用的運動速度。

專案開始時,6軸機械手臂的速度設定為50%。

Usage:
arm1.set_speed(speed)

範圍

描述

speed

6軸機械手臂的運動速度,從 1 到 100%。

# Set the 6-Axis Arm speed to 30%
arm1.set_speed(30)

set_end_effector_type#

set_end_effector_type 設定連接到 6 軸機械手臂的末端執行器的類型。

當末端執行器類型變更時,六軸機械手臂會自動調整其 Z 軸偏移量以符合所選工具。專案開始時,末端執行器類型設定為 MAGNET。

Usage:
arm1.set_end_effector_type(type)

範圍

描述

type

安裝在 6 軸臂上的工具: MAGNET (磁性拾取工具)或 PEN (筆架工具)。

# Set the end effector type to the Pen Holder Tool
arm1.set_end_effector_type(PEN)

set_end_effector_magnet#

set_end_effector_magnet 接合或釋放磁性拾取工具。

The magnet state stays active until another set_end_effector_magnet method changes it. The magnet state is reset to False at the start of a project.

Usage:
arm1.set_end_effector_magnet(state)

範圍

描述

state

磁性拾取工具狀態: True 表示拾取並保持物體,或 False 表示丟棄任何已拾取的物體並停止拾取新物體。

# Pick up objects and then drop them
arm1.set_end_effector_type(MAGNET)
arm1.set_end_effector_magnet(True)
wait(2, SECONDS)
arm1.set_end_effector_magnet(False)

set_pen_offset#

set_pen_offset 設定當筆架工具連接到 6 軸臂時所使用的 z 軸偏移量。

使用此方法前,請將末端執行器類型設定為 PEN 如果未選擇筆架工具,則此方法無效。

筆偏移量是指從筆架工具頂部到白板筆筆尖的距離。在專案開始時,筆偏移量設定為 0筆偏移量為 0 時,機械手臂的 Z 軸原點位於筆架工具與六軸機械手臂連接點。

Usage:
arm1.set_pen_offset(zOffset)

範圍

描述

zOffset

筆偏移值,單位為毫米。

# Set the end effector type to the Pen Holder Tool and set the pen offset
arm1.set_end_effector_type(PEN)
arm1.set_pen_offset(25)

set_control_stop#

set_control_stop 啟用 6 軸機械手臂的控制停止功能。

啟用控制停止後,6 軸機械手臂將立即停止所有運動,並且在專案重新啟動之前不會運行任何進一步的機械手臂運動方法。

Usage:
arm1.set_control_stop(state)

範圍

描述

state

可選。 0 為真 True (預設值)啟用控制停止。 2 False 不啟用控制停止。

# Stop the 6-Axis Arm and prevent further movement
arm1.set_control_stop()

set_timeout#

set_timeout 設定移動 6 軸機械手臂時所使用的逾時值。

如果在逾時之前某個動作沒有完成,專案將繼續下一行程式碼。

Usage:
arm1.set_timeout(timeout, units)

範圍

描述

timeout

新的超時值。

units

可選。時間單位: MSEC (毫秒,預設值), SECONDS,或 SEC。

# Set the 6-Axis Arm timeout to 2 seconds
arm1.set_timeout(2, SECONDS)

獲取器#

is_done#

is_done 返回 6 軸機械手臂是否已完成移動。

在呼叫移動方法時, wait=False ,則此方法非常有用。

  • True — 6軸機械手臂已完成移動。

  • False — 6軸機械手臂仍在移動。

Usage:
arm1.is_done()

參數

描述

此方法沒有參數。

# Display the 6-Axis Arm's y-position while it moves
arm1.move_to(-100, 200, 100, wait=False)

while not arm1.is_done():
    brain.screen.print(arm1.get_y())
    brain.screen.next_row()
    wait(0.25, SECONDS)

is_crashed#

is_crashed 返回 6 軸機械手臂在移動過程中是否發生碰撞。

當偵測到碰撞時,六軸機械手臂會停止馬達運動,並可能出現無力狀態。這可以減輕機械手臂的壓力,並有助於保護馬達免受意外損壞。

  • True — 6軸機械手臂已墜毀。

  • False — 6軸機械手臂沒有發生碰撞。

Usage:
arm1.is_crashed()

參數

描述

此方法沒有參數。

# Quickly move to a new location
arm1.set_speed(100)
arm1.move_to(-30, 240, 40, wait=False)

# While moving, check for a crash
while True:
    if arm1.is_crashed():
        # Indicate a crash with the Signal Tower and Brain screen
        brain.screen.print("Crash Detected")
        signal_tower_2.set_color(SignalTower.GREEN, SignalTower.OFF)
        signal_tower_2.set_color(SignalTower.RED, SignalTower.ON)
        break

    wait(5, MSEC)

get_x#

get_x 傳回末端執行器的目前 x 位置(以毫米為單位)。

使用此方法讀取末端執行器當前緣 x 軸的位置。

Usage:
arm1.get_x()

參數

描述

此方法沒有參數。

# Print the current x position of the 6-Axis Arm
brain.screen.print(arm1.get_x())

get_y#

get_y 傳回末端執行器的目前 y 位置(以毫米為單位)。

使用此方法讀取末端執行器當前緣 y 軸的位置。

Usage:
arm1.get_y()

參數

描述

此方法沒有參數。

# Print the current y position of the 6-Axis Arm
brain.screen.print(arm1.get_y())

get_z#

get_z 傳回末端執行器的目前 z 位置(以毫米為單位)。

使用此方法讀取末端執行器當前緣 z 軸的位置。

Usage:
arm1.get_z()

參數

描述

此方法沒有參數。

# Print the current z position of the 6-Axis Arm
brain.screen.print(arm1.get_z())

get_pitch#

get_pitch 傳回末端執行器的目前俯仰角(以度為單位)。

Usage:
arm1.get_pitch()

參數

描述

此方法沒有參數。

# Print the current pitch of the end effector
brain.screen.print(arm1.get_pitch())

get_roll#

get_roll 傳回末端執行器的目前滾動角度(以度為單位)。

Usage:
arm1.get_roll()

參數

描述

此方法沒有參數。

# Print the current roll of the end effector
brain.screen.print(arm1.get_roll())

get_yaw#

get_yaw 傳回末端執行器的目前偏航角(以度為單位)。

Usage:
arm1.get_yaw()

參數

描述

此方法沒有參數。

# Print the current yaw of the end effector
brain.screen.print(arm1.get_yaw())

can_arm_reach_to#

can_arm_reach_to 回傳 6 軸機械手臂是否可以將末端執行器移動到指定的 x、y 和 z 座標。

使用此方法在執行 move_to 之前檢查目標位置。

  • True — 6軸機械手臂可以到達所要求的位置。

  • False — 6軸機械手臂無法到達要求的位置。

Usage:
arm1.can_arm_reach_to(x, y, z)

範圍

描述

x

目標位置的 x 座標(單位:毫米)。

y

目標位置的y座標(單位:毫米)。

z

目標位置的z座標(單位:毫米)。

# Move the 6-Axis Arm to (100, -20, 50) if it can reach
if arm1.can_arm_reach_to(100, -20, 50):
    arm1.move_to(100, -20, 50)

can_arm_reach_inc#

can_arm_reach_inc 返回 6 軸機械手臂是否可以將末端執行器從其目前位置移動指定的 x、y 和 z 距離。

使用此方法檢查相對移動,然後再使用 move_inc。

  • True — 6 軸機械手臂可以做出所要求的運動。

  • False — 6 軸機械手臂無法進行所要求的運動。

Usage:
arm1.can_arm_reach_inc(x, y, z)

範圍

描述

x

沿 x 軸移動的距離(單位:毫米)。

y

沿 y 軸移動的距離(單位:毫米)。

z

沿 z 軸移動的距離,單位為毫米。

# Increment the 6-Axis Arm 100 mm along the x-axis if possible
if arm1.can_arm_reach_inc(100, 0, 0):
    arm1.move_inc(100, 0, 0)

can_end_effector_reach_to#

can_end_effector_reach_to 返回末端執行器是否可以旋轉到指定的偏航角、橫滾角和俯仰角。

使用此方法檢查目標方向,然後再使用 move_end_effector_to。

  • True — 末端執行器可以達到所要求的方向。

  • False — 末端執行器無法達到所要求的方向。

Usage:
arm1.can_end_effector_reach_to(yaw, roll, pitch)

範圍

描述

yaw

目標偏航角,單位為度。

roll

目標滾動角,單位為度。

pitch

目標俯仰角,單位為度。

# Rotate the end effector to 90 degrees of roll if possible
if arm1.can_end_effector_reach_to(0, 90, 0):
    arm1.move_end_effector_to(0, 90, 0)

can_end_effector_reach_inc#

can_end_effector_reach_inc 返回末端執行器是否可以從其目前方向旋轉指定的偏航角、橫滾角和俯仰角。

使用此方法檢查相對方向運動,然後再使用 move_end_effector_inc。

  • True — 末端執行器可以進行所要求的旋轉。

  • False — 末端執行器無法進行所要求的旋轉。

Usage:
arm1.can_end_effector_reach_inc(yaw, roll, pitch)

範圍

描述

yaw

偏航角的變化量,以度為單位。

roll

滾動角度的變化量,以度為單位。

pitch

音調的變化,以度為單位。

# Increment the end effector by 10 degrees of pitch if possible
if arm1.can_end_effector_reach_inc(0, 0, 10):
    arm1.move_end_effector_inc(0, 0, 10)

get_timeout#

get_timeout 傳回 6 軸機械手臂運動方法所使用的逾時值(以毫秒為單位)。

Usage:
arm1.get_timeout()

參數

描述

此方法沒有參數。

# Print the current movement timeout in milliseconds
brain.screen.print(arm1.get_timeout())

is_connected#

is_connected 返回 6 軸機械手臂是否連接到 EXP 大腦。

  • True — 6 軸機械手臂連接到 EXP 大腦。

  • False — 6 軸機械手臂未連接到 EXP 大腦。

Usage:
arm1.is_connected()

參數

描述

此方法沒有參數。

# Print whether the 6-Axis Arm is connected
brain.screen.print(arm1.is_connected())

回呼函數#

control_stopped#

control_stopped 註冊一個在啟用控制停止時運行的函數。

此方法傳回 Event 類別的一個實例。

Usage:
arm1.control_stopped(callback, arg)

範圍

描述

callback

先前定義的 函數,當控制停止功能啟用時運作。

arg

可選。包含要傳遞給回呼函數的參數的元組。有關更多信息,請參閱使用帶參數的函數。

# Define a function to run when control stop is enabled
def when_control_stopped():
    brain.screen.print("The arm has been control stopped")

# Run when_control_stopped when the 6-Axis Arm is control stopped
arm1.control_stopped(when_control_stopped)

crashed#

crashed 註冊了一個函數,當 6 軸機械手臂在移動過程中發生碰撞時,該函數將運行。

當偵測到碰撞時,六軸機械手臂會停止馬達運動,並可能出現無力狀態。這可以減輕機械手臂的壓力,並有助於保護馬達免受意外損壞。

Usage:
arm1.crashed(callback)

範圍

描述

callback

先前定義的函數,當偵測到崩潰時運行。

# Define what happens if a crash is detected
def arm_crash():
    brain.screen.print("Crash Detected")
    signal_tower_2.set_color(SignalTower.RED, SignalTower.ON)

# Run arm_crash when the 6-Axis Arm crashes
arm1.crashed(arm_crash)

建構函數#

Arm#

Arm 建立一個 6 軸機械手臂物件。

Usage:
Arm(smartport)

範圍

描述

smartport

6軸機械手臂連接的智慧型端口,寫成 Ports.PORTx,其中 x 是端口號。

# Construct a 6-Axis Arm named arm1 with the Arm class
arm1 = Arm(Ports.PORT1)