控制器#
介绍#
IQ(第二代)Brain 可以连接到 IQ(第二代)或 IQ(第一代)控制器。两个控制器都配有两个模拟摇杆和多个按钮,Brain 可以使用它们来检测动作和按压。
对于下面的示例,配置的控制器将被命名为“controller”,并且在整个 API 文档的所有后续示例中引用“Controller”类方法时将使用它。
以下是所有可用方法的列表:
Actions – Turn Controller-programmed actions on or off.
remote_control_code_enabled – Enable or disable Controller configured actions.
Getters – Read button states and joystick positions.
Callback – Run code when buttons or joysticks change state.
Constructors – Manually initialize and configure the controller.
控制器 – 创建控制器。
Actions#
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!
Getters#
.pressing#
.pressing
返回一个整数,指示控制器上的特定按钮当前是否被按下。此方法必须在特定的按钮对象上调用,例如 buttonEDown
(请参阅下面的按钮对象完整列表)。
1
-指定的按钮被按下。0
——指定的按钮未被按下。
用法:
五个可用按钮对象之一可与此方法一起使用,如下所示:
按钮 |
命令 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
该方法没有参数。 |
# Example coming soon
.position#
.position
以 -100 到 100 之间的整数形式返回操纵杆指定轴的位置,表示百分比。此方法必须在特定的轴对象上调用,例如 axisA
(请参阅下文的完整轴对象列表)。
用法:
此方法可使用四个可用轴之一,如下所示:
轴 |
命令 |
---|---|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
该方法没有参数。 |
# Example coming soon
Callback#
.pressed#
.pressed
注册一个函数,当控制器上的特定按钮被按下时调用。此方法必须在特定的按钮对象上调用,例如 buttonEDown
(请参阅下文按钮对象的完整列表)。
用法:
可以使用此方法使用其中一个可用的按钮对象,如下所示:
按钮 |
命令 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
打回来 |
先前定义的在按下指定按钮时执行的 函数。 |
arg |
Optional. A tuple containing arguments to pass to the callback function. Functions with Parameters for more information. |
# Example coming soon
.released#
.released
注册一个函数,当控制器上的特定按钮被释放时调用。此方法必须在特定的按钮对象上调用,例如 buttonEDown
(请参阅下文按钮对象的完整列表)。
用法:
可以使用此方法使用其中一个可用的按钮对象,如下所示:
按钮 |
命令 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
打回来 |
先前定义的在释放指定按钮时执行的 函数。 |
arg |
Optional. A tuple containing arguments to pass to the callback function. Functions with Parameters for more information. |
# Example coming soon
.changed#
.changed
注册了一个函数,当操纵杆位置发生变化时调用。此方法必须在特定的轴对象上调用,例如 axisA
(请参阅下文的完整轴对象列表)。
用法:
可以使用此方法的四个可用轴之一,如下所示:
轴 |
命令 |
---|---|
|
|
|
|
|
|
|
|
参数 |
描述 |
---|---|
打回来 |
A function that is previously defined to execute when the axis’ value changes. |
arg |
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
# 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)
构造函数#
构造函数用于手动创建“控制器”对象,这对于在 VEXcode 之外配置控制器是必需的。
Controller#
Controller
创建一个控制器。
用法:
Controller()
参数 |
描述 |
---|---|
此构造函数没有参数。 |
# Example coming soon