六轴机械臂#

介绍#

VEX 六轴机械臂允许程序在三维空间中移动末端执行器,并通过偏航、横滚和俯仰旋转来控制其姿态。该六轴机械臂还可以配置不同的末端执行器,例如磁性拾取工具或笔夹工具。

For the examples below, the configured 6-Axis Arm will be named arm1 and will be used in all subsequent examples throughout this API documentation when referring to Arm class methods.

以下是所有可用方法的列表:

动作 – 将六轴机械臂移动到三维空间中的指定位置或方向。

  • move_to – Moves the end effector to an absolute X, Y, Z position.

  • move_inc – Moves the end effector by a relative X, Y, Z distance.

  • move_end_effector_to – Rotates the end effector to an absolute yaw, roll, and pitch orientation.

  • move_end_effector_inc – Rotates the end effector by a relative yaw, roll, and pitch amount.

修改器 – 配置六轴机械臂的行为、工具和运动设置。

获取器 – 返回六轴机械臂的运动状态、位置、方向和配置值。

  • is_done – Returns whether the 6-Axis Arm has completed its movement.

  • is_crashed – Returns whether the 6-Axis Robotic Arm has crashed while moving.

  • get_x – Returns the current X position of the end effector.

  • get_y – Returns the current Y position of the end effector.

  • get_z – Returns the current Z position of the end effector.

  • get_pitch – Returns the current pitch orientation of the end effector.

  • get_roll – Returns the current roll orientation of the end effector.

  • get_yaw – Returns the current yaw orientation of the end effector.

  • can_arm_reach_to – Returns whether the 6-Axis Arm can reach an absolute position.

  • can_arm_reach_inc – Returns whether the 6-Axis Arm can reach a relative position.

  • can_end_effector_reach_to – Returns whether the 6-Axis Arm can reach an absolute orientation.

  • can_end_effector_reach_inc – Returns whether the 6-Axis Arm can reach a relative orientation.

  • control_stopped – Registers a function to run when the 6-Axis Arm enters control stop.

  • crashed – Registers a function to run when the 6-Axis Arm has crashed while moving.

  • get_timeout – Returns the current timeout value used by 6-Axis Arm movement methods.

  • is_connected – Returns whether the 6-Axis Arm is connected to the Brain.

构造函数 – 手动初始化和配置六轴机械臂。

  • Arm – Create a 6-Axis Arm.

行动#

move_to#

move_to moves the 6-Axis Arm to a specified x, y, and z coordinate.

该方法返回一个布尔值,指示六轴机械臂是否已到达请求的位置:

  • True — The 6-Axis Arm has reached the requested position.

  • False — The 6-Axis Arm cannot reach the requested position.

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

范围

描述

x

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

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

z

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

wait

Optional.

  • wait=True (default) – The project waits until move_to is complete before executing the next line of code.
  • wait=False – The project starts the action and moves on to the next line of code immediately without waiting for move_to to finish.

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

move_inc#

move_inc moves the 6-Axis Arm by a specified distance along the x, y, and z axes.

此方法将返回一个布尔值,指示六轴机械臂是否已到达请求的位置:

  • True — The 6-Axis Arm has reached the requested position.

  • False — The 6-Axis Arm cannot reach the requested position.

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

范围

描述

x

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

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

z

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

wait

Optional.

  • wait=True (default) – The project waits until move_inc is complete before executing the next line of code.
  • wait=False – The project starts the action and moves on to the next line of code right away, without waiting for move_inc to finish.

# Move the Arm +100 millimeters on the y-axis
arm1.move_inc(0, 100, 0)

move_end_effector_to#

move_end_effector_to rotates the 6-Axis Arm’s end effector to a specified yaw, roll, and pitch orientation.

此方法返回一个布尔值,指示末端执行器是否已达到所请求的方向:

  • True — The end effector has reached the requested orientation.

  • False — The end effector cannot reach the requested orientation.

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

范围

描述

偏航

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

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

沥青

末端执行器绕 y 轴的指向角度(以度为单位)。

wait

Optional.

  • wait=True (default) – The project waits until move_end_effector_to is complete before executing the next line of code.
  • wait=False – The project starts the action and moves on to the next line of code right away, without waiting for move_end_effector_to to finish.

# Orient the end effector to point towards
# 90 degrees around the x-axis
arm1.move_end_effector_to(0, 90, 0)

move_end_effector_inc#

move_end_effector_inc rotates the 6-Axis Arm’s end effector by a specified relative yaw, roll, and pitch amount.

此方法返回一个布尔值,指示末端执行器是否已达到所请求的方向:

  • True — The end effector has reached the requested orientation.

  • False — The end effector cannot reach the requested orientation.

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

范围

描述

偏航

绕 z 轴的角度变化,以度为单位。

绕 x 轴的角度变化,以度为单位。

沥青

绕 y 轴的角度变化,以度为单位。

wait

Optional.

  • wait=True (default) – The project waits until move_end_effector_inc is complete before executing the next line of code.
  • wait=False – The project starts the action and moves on to the next line of code right away, without waiting for move_end_effector_inc to finish.

# Rotate the end effector -50 degrees around the y-axis
arm1.move_end_effector_inc(0, 0, -50)

变异体#

set_speed#

set_speed sets the movement speed used by the 6-Axis Arm for motion commands.

Usage:
arm1.set_speed(speed)

范围

描述

速度

6轴机械臂的移动速度,以1到100的百分比表示。

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

set_end_effector_type#

set_end_effector_type sets the type of end effector attached to the 6-Axis Arm.

Usage:
arm1.set_end_effector_type(type)

范围

描述

类型

A valid end effector type:

  • MAGNET — Magnet Pickup Tool
  • PEN — Pen Holder Tool

# Set the end effector type to the Magnet Pickup Tool
arm1.set_end_effector_type(MAGNET)

set_end_effector_magnet#

set_end_effector_magnet sets the state of the Magnet Pickup Tool on the 6-Axis Arm.

Usage:
arm1.set_end_effector_magnet(state)

范围

描述

状态

The state of the Magnet Pickup Tool:

  • True — The magnet will pick up and hold objects.
  • False — The magnet will drop and no longer pick up objects.

# Pick up objects and then drop them
arm1.set_end_effector_type(MAGNET)
arm1.set_end_effector_magnet(True)
arm1.move_inc(0, 0, 100)
arm1.set_end_effector_magnet(False)

set_pen_offset#

set_pen_offset sets the z-axis offset used when the Pen Holder Tool is attached to the 6-Axis Arm.

Usage:
arm1.set_pen_offset(zOffset)

范围

描述

z偏移

笔偏移量,单位为毫米。正值表示笔的偏移量从工具安装点向上移动。

set_control_stop#

set_control_stop enables the control stop for the 6-Axis Arm.

Usage:
arm1.set_control_stop(state)

范围

描述

状态

Optional.

  • True (default) – Enables control stop and prevents further linear or joint movements.
  • False – Does not enable control stop.

set_timeout#

set_timeout sets the timeout value used when moving the 6-Axis Arm.

Usage:
arm1.set_timeout(timeout, units)

范围

描述

暂停

新的超时值。

单位

The unit to represent the time:

  • MSEC (default) — milliseconds
  • SECONDS / SEC — seconds

获取器#

is_done#

is_done returns a Boolean indicating whether the 6-Axis Arm is currently moving.

  • True — The 6-Axis Arm is not moving.

  • False — The 6-Axis Arm is still moving.

Usage:
arm1.is_done()

# Display the arm's position while it moves
arm1.move_to(-100, 200, 100, False)
while not arm1.is_done():
    brain.print(arm1.get_y())
    brain.next_row()
    wait(0.25, SECONDS)

is_crashed#

is_crashed returns a Boolean indicating whether the 6-Axis Robotic Arm has crashed while moving.

  • True — The 6-Axis Arm has crashed.

  • False — The 6-Axis Arm has not crashed.

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

Usage:
arm1.is_crashed()

# Quickly move to a new location
arm1.set_speed(100)
arm1.move_to(-30, 240, 40, 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 returns the x position of the end effector in millimeters.

Usage:
arm1.get_x()

def main():
    # Print the current x position of the Arm in millimeters
    brain.print(arm1.get_x())

get_y#

get_y returns the y position of the end effector in millimeters.

Usage:
arm1.get_y()

def main():
    # Print the current y position of the Arm in millimeters
    brain.print(arm1.get_y())

get_z#

get_z returns the z position of the end effector in in millimeters.

Usage:
arm1.get_z()

def main():
    # Print the current z position of the Arm in millimeters
    brain.print(arm1.get_z())

get_pitch#

get_pitch returns the current pitch of the end effector in degrees.

Usage:
arm1.get_pitch()

def main():
    # Print the current pitch of the Arm in degrees.
    brain.print(arm1.get_pitch())

get_roll#

get_roll returns the current roll of the end effector in degrees.

Usage:
arm1.get_roll()

def main():
    # Print the current roll of the Arm in degrees.
    brain.print(arm1.get_roll())

get_yaw#

get_yaw returns the current yaw of the end effector in degrees.

Usage:
arm1.get_yaw()

def main():
    # Print the current yaw of the Arm in degrees.
    brain.print(arm1.get_yaw())

can_arm_reach_to#

can_arm_reach_to returns a Boolean indicating whether the 6-Axis Arm can move the end effector to a specified x, y, and z coordinate.

  • True — The 6-Axis Arm can reach the requested position.

  • False — The 6-Axis Arm cannot reach the requested position.

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

范围

描述

x

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

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

z

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

# Move the 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 returns a Boolean indicating whether the 6-Axis Arm can move the end effector by a specified relative x, y, and z distance.

  • True — The 6-Axis Arm can reach the requested position.

  • False — The 6-Axis Arm cannot reach the requested position.

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

范围

描述

x

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

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

z

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

# Increment the 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 returns a Boolean indicating whether the 6-Axis Arm can move the end effector to a specified yaw, roll, and pitch orientation.

  • True — The end effector can reach the requested orientation.

  • False — The end effector cannot reach the requested orientation.

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

范围

描述

偏航

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

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

沥青

末端执行器绕 y 轴的指向角度(以度为单位)。

# Orient towards 90 degrees on the x-axis 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 returns a Boolean indicating whether the 6-Axis Arm can move the end effector by a specified relative yaw, roll, and pitch amount.

  • True — The end effector can reach the requested orientation.

  • False — The end effector cannot reach the requested orientation.

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

范围

描述

偏航

绕 z 轴的角度变化,以度为单位。

绕 x 轴的角度变化,以度为单位。

沥青

绕 y 轴的角度变化,以度为单位。

# Increment the end effector by 
# +10 degrees on the y-axis if possible
if arm1.can_end_effector_reach_inc(0, 0, 10):
    arm1.move_end_effector_inc(0, 0, 10)

control_stopped#

control_stopped registers a function that will be called when the control stop is enabled.

This method returns an instance of the Event class.

Usage:
arm1.control_stopped(callback, arg)

参数

描述

callback

先前定义的 函数,当控制停止功能启用时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅使用带参数的函数

# Define a function when_control_stopped
def when_control_stopped():
    # Print to the Brain's screen that the Arm has been
    # control stopped.
    brain.screen.print("The arm has been control stopped")

# Run when_control_stopped when the Arm is control stopped.
arm.control_stopped(when_control_stopped)

crashed#

crashed registers a function to run when the 6-Axis Arm has crashed while moving.

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

Usage:
arm1.crashed(callback)

参数

描述

callback

先前定义的 函数,当控制停止功能启用时执行。

# Define what happens in the event of a crash
def arm_crash():
    # 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)

# Listen for a crash
arm1.crashed(arm_crash)

get_timeout#

get_timeout returns the timeout value used by the 6-Axis Arm move methods in milliseconds.

Usage:
arm1.get_timeout()

is_connected#

is_connected returns a Boolean indicating whether the 6-Axis Arm is connected to the Brain.

  • True — The Arm is connected to the Brain.

  • False — The Arm is not connected to the Brain.

Usage:
arm1.is_connected()

构造函数#

Arm#

Arm create a 6-Axis Arm.

Arm(smartport)

范围

描述

smartport

The Smart Port that the 6-Axis Arm is connected to, written as Ports.PORTx where x is the number of the port.

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