Controller#

介绍#

The IQ (2nd gen) Brain can connect to either an IQ (2nd gen) or IQ (1st gen) Controller. Both controllers have two analog joysticks and multiple buttons that the Brain can use to detect movements and presses.

For the examples below, the configured Distance Sensors will be named Controller, and will be used in all subsequent examples throughout this API documentation when referring to Controller class methods.

以下是可用方法的列表:

操作 - 启用或禁用控制器。

Getters——从控制器操纵杆和按钮返回值。

  • pressing – 返回指定按钮是否被按下。

  • position – 返回操纵杆指定轴的位置。

回调——通过回调方法与控制器交互。

  • pressed – 按下指定按钮时调用一个函数。

  • released – 当指定按钮被释放时调用一个函数。

  • 已更改 – 当操纵杆的轴发生变化时调用一个函数。

构造函数——手动初始化控制器。

行动#

远程控制代码已启用#

RemoteControlCodeEnabled 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 — 启用控制器配置的操作。

  • false — 禁用控制器配置的操作。

Usage:
RemoteControlCodeEnabled = false;

// Example coming soon

吸气剂#

紧迫#

“pressing” 返回一个整数,指示控制器上的特定按钮当前是否被按下。此方法必须在特定的按钮对象上调用,例如“ButtonEDown”(请参阅下文的完整按钮对象列表)。

  • 1-指定的按钮被按下。

  • 0——指定的按钮未被按下。

用法:
十个可用按钮对象之一可用于此方法,如下所示:

按钮

命令

按钮向下

Controller.ButtonEDown.pressing()E Down 按钮

ButtonEUp

Controller.ButtonEUp.pressing()E 向上 按钮

ButtonFDown

Controller.ButtonFDown.pressing()F Down 按钮

ButtonFUp

Controller.ButtonFUp.pressing()F 向上 按钮

ButtonL3

Controller.ButtonL3.pressing() — The Left Joystick button
IQ (2nd gen) Controller only

ButtonLDown

Controller.ButtonLDown.pressing()L 向下 按钮

ButtonLUp

Controller.ButtonLUp.pressing()L 向上 按钮

ButtonR3

Controller.ButtonR3.pressing() — The Right Joystick button
IQ (2nd gen) Controller only

ButtonRDown

Controller.ButtonRDown.pressing()R 向下 按钮

ButtonRUp

Controller.ButtonRUp.pressing()R 向上 按钮

settings

参数

描述

该方法没有参数。

// Example coming soon

位置#

position 返回操纵杆指定轴的位置,以 -100 到 100 之间的整数表示,代表百分比。此方法必须在特定的轴对象上调用,例如 AxisA(请参阅下文的完整轴对象列表)。

用法:
可以使用此方法的四个可用轴之一,如下所示:

命令

AxisA

Controller.AxisA.position()左操纵杆的垂直轴

AxisB

Controller.AxisB.position()左操纵杆的水平轴

AxisC

Controller.AxisC.position()右操纵杆的水平轴

AxisD

Controller.AxisD.position()右操纵杆的垂直轴

settings

参数

描述

该方法没有参数。

// Example coming soon

打回来#

按下#

pressed 注册了一个函数,当控制器上的特定按钮被按下时会调用该函数。此方法必须在特定的按钮对象上调用,例如 ButtonEDown(请参阅下文的完整按钮对象列表)。

用法:
十个可用按钮对象之一可用于此方法,如下所示:

按钮

命令

按钮向下

Controller.ButtonEDown.pressed(callback); — The E Down button

ButtonEUp

Controller.ButtonEUp.pressed(callback); — The E Up button

ButtonFDown

Controller.ButtonFDown.pressed(callback); — The F Down button

ButtonFUp

Controller.ButtonFUp.pressed(callback); — The F Up button

ButtonL3

Controller.ButtonL3.pressed(callback); — The Left Joystick button
IQ (2nd gen) Controller only

ButtonLDown

Controller.ButtonLDown.pressed(callback); — The L Down button

ButtonLUp

Controller.ButtonLUp.pressed(callback); — The L Up button

ButtonR3

Controller.ButtonR3.pressed(callback); — The Right Joystick button
IQ (2nd gen) Controller only

ButtonRDown

Controller.ButtonRDown.pressed(callback); — The R Down button

ButtonRUp

Controller.ButtonRUp.pressed(callback); — The R Up button

范围

描述

callback

The callback function to be called when the specified button is pressed.

// Example coming soon

发布#

released 注册了一个函数,当控制器上的特定按钮被释放时调用。此方法必须在特定的按钮对象上调用,例如 ButtonEDown(请参阅下文的完整按钮对象列表)。

用法:
十个可用按钮对象之一可用于此方法,如下所示:

按钮

命令

按钮向下

Controller.ButtonEDown.released(callback); — The E Down button

ButtonEUp

Controller.ButtonEUp.released(callback); — The E Up button

ButtonFDown

Controller.ButtonFDown.released(callback); — The F Down button

ButtonFUp

Controller.ButtonFUp.released(callback); — The F Up button

ButtonL3

Controller.ButtonL3.released(callback); — The Left Joystick button
IQ (2nd gen) Controller only

ButtonLDown

Controller.ButtonLDown.released(callback); — The L Down button

ButtonLUp

Controller.ButtonLUp.released(callback); — The L Up button

ButtonR3

Controller.ButtonR3.released(callback); — The Right Joystick button
IQ (2nd gen) Controller only

ButtonRDown

Controller.ButtonRDown.released(callback); — The R Down button

ButtonRUp

Controller.ButtonRUp.released(callback); — The R Up button

范围

描述

callback

The callback function to be called when the specified button is released.

// Example coming soon

改变#

changed 注册了一个函数,当操纵杆位置发生变化时会调用该函数。此方法必须在特定的轴对象上调用,例如 AxisA(请参阅下文的完整轴对象列表)。

用法:
可以使用此方法的四个可用轴之一,如下所示:

命令

AxisA

Controller.AxisA.changed(callback); — The Left Joystick’s vertical axis

AxisB

Controller.AxisB.changed(callback); — The Left Joystick’s horizontal axis

AxisC

Controller.AxisC.changed(callback); — The Right Joystick’s horizontal axis

AxisD

Controller.AxisD.changed(callback); — The Right Joystick’s vertical axis

settings

参数

描述

callback

The callback function to be called when the specified axis’s position changes.

// Example coming soon

构造函数#

控制器#

controller 创建一个控制器对象。

Usage:
controller Controller = controller();

范围

描述

该方法没有参数。

// Example coming soon