控制器#
介绍#
IQ(第二代)Brain 可以连接到 IQ(第二代)或 IQ(第一代)控制器。两个控制器都配有两个模拟摇杆和多个按钮,Brain 可以使用它们来检测动作和按压。
For the examples below, the configured controller will be named controller
and will be used in all subsequent examples throughout this API documentation when referring to Controller
class methods.
以下是所有可用方法的列表:
操作——打开或关闭控制器编程的操作。
remote_control_code_enabled – 启用或禁用控制器配置的操作。
Getters – 读取按钮状态和操纵杆位置。
回调——当按钮或操纵杆改变状态时运行代码。
构造函数——手动初始化和配置控制器。
控制器 – 创建控制器。
行动#
remote_control_code_enabled#
remote_control_code_enabled
is a variable that can be set to a boolean that enables or disables Controller configured actions from the Devices menu. The Controller is enabled by default. It can be set to either of the following:
True
— Enable Controller configured actions.False
— Disable Controller configured actions.
Usage:
remote_control_code_enabled = False
# Example coming soon!
吸气剂#
.pressing#
.pressing
returns an integer indicating whether a specific button on the controller is currently being pressed. This method must be called on a specific button object, such as buttonEDown
(see full list of button objects below).
1
- The specified button is being pressed.0
- The specified button is not being pressed.
用法:
五个可用按钮对象之一可与此方法一起使用,如下所示:
按钮 |
命令 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
该方法没有参数。 |
# Example coming soon
.position#
.position
returns the position of the joystick’s specified axis as an integer from –100 to 100, representing a percentage. This method must be called on a specific axis object, such as axisA
(see full list of axis objects below).
用法:
此方法可使用四个可用轴之一,如下所示:
轴 |
命令 |
---|---|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
该方法没有参数。 |
# Example coming soon
打回来#
.pressed#
.pressed
registers a function to be called when a specific button on the controller is pressed. This method must be called on a specific button object, such as buttonEDown
– (see full list of button objects below).
用法:
可以使用此方法使用其中一个可用的按钮对象,如下所示:
按钮 |
命令 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
打回来 |
先前定义的在按下指定按钮时执行的 函数。 |
arg |
可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数。 |
# Example coming soon
.released#
.released
registers a function to be called when a specific button on the controller is released. This method must be called on a specific button object, such as buttonEDown
– (see full list of button objects below).
用法:
可以使用此方法使用其中一个可用的按钮对象,如下所示:
按钮 |
命令 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
打回来 |
先前定义的在释放指定按钮时执行的 函数。 |
arg |
可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数。 |
# Example coming soon
.changed#
.changed
registers a function to be called when the joystick’s position changes. This method must be called on a specific axis object, such as axisA
(see full list of axis objects below).
用法:
可以使用此方法的四个可用轴之一,如下所示:
轴 |
命令 |
---|---|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
打回来 |
先前定义的 函数,当轴的值发生变化时执行。 |
arg |
可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数。 |
# Function to display an emoji when the joystick is moved
def move_joystick():
robot.screen.show_emoji(CONFUSED)
# Run the function when the joystick is moved up or down
controller.axis1.changed(move_joystick)
构造函数#
Constructors are used to manually create Controller
objects, which are necessary for configuring a controller outside of VEXcode.
Controller#
Controller
creates a controller.
Usage:
Controller()
参数 |
描述 |
---|---|
此构造函数没有参数。 |
# Example coming soon