惯性#

介绍#

VEX IQ(第二代)大脑内置一个用于测量旋转运动的三轴陀螺仪和一个用于检测运动变化的三轴加速度计。这些传感器使机器人能够追踪其方向、航向和加速度。

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

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

方向——测量惯性传感器的旋转运动。

  • heading – 返回当前标题。

  • rotation – 返回累积旋转角度。

  • setHeading – 将惯性传感器的航向设置为指定值。

  • setRotation – 设置惯性传感器的旋转值。

  • calibrate – 校准惯性传感器以实现稳定的航向跟踪。

  • isCalibrating – 返回惯性传感器是否正在校准。

  • resetHeading – 将惯性传感器的航向设置为 0。

  • resetRotation – 将惯性传感器的旋转角度设置为 0。

运动——检测运动的变化。

  • 加速度 – 返回沿 x、y 或 z 轴的线性加速度。

  • gyroRate – 返回绕 x、y 或 z 轴的角速度。

  • orientation – 根据倾斜和旋转返回滚动、俯仰或偏航。

  • 已更改 – 注册一个函数,当惯性传感器检测到变化时调用。

构造函数——手动初始化和配置惯性传感器。

方向#

heading#

heading returns the current heading of the Inertial Sensor.

Usage:
BrainInertial.heading(units)

参数

描述

units

Optional. The units that represent the heading:

  • degrees (default)
  • turns
// Example coming soon

rotation#

rotation returns the current rotation of the Inertial Sensor.

Usage:
BrainInertial.rotation(units)

参数

描述

units

Optional. The units that represent the rotation:

  • degrees (default)
  • turns
// Example coming soon

setHeading#

setHeading sets the heading of the Inertial Sensor to a specific value.

Usage:
BrainInertial.setHeading(value, units);

参数

描述

value

要设置的航向值。

units

The unit that represents the new heading:

  • degrees
  • turns
// Example coming soon

setRotation#

setRotation sets the rotation of the Inertial Sensor to a specific value.

Usage:
BrainInertial.setRotation(value, units);

参数

描述

value

要设置的旋转值。

units

The unit that represents the new rotation:

  • degrees
  • turns
// Example coming soon

calibrate#

calibrate calibrates the Inertial Sensor. All subsequent lines will wait for the calibration to complete before executing. Calibration is an internal procedure that measures and compensates for sensor noise and drift over a specified period. During this time, the Brain must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.

../../_images/IQ_right_orientation.png../../_images/IQ_left_orientation.png../../_images/IQ_top_orientation.png

VEX 机器人会在每次项目开始时尝试自动校准。但是,如果在项目启动期间搬运或移动机器人,传感器可能无法正确校准或产生错误的校准结果。

Usage:
BrainInertial.calibrate();

范围

描述

该方法没有参数。

// Example coming soon

isCalibrating#

isCalibrating checks if the Inertial Sensor is currently calibrating.

  • 1 - The Inertial Sensor is calibrating.

  • 0 - The Inertial Sensor is not calibrating.

Usage:
isCalibrating()

范围

描述

该方法没有参数。

// Example coming soon

resetHeading#

resetHeading resets the heading of the Inertial Sensor to 0.

Usage:
BrainInertial.resetHeading();

参数

描述

该方法没有参数。

// Example coming soon

resetRotation#

resetRotation resets the rotation of the Inertial Sensor to 0.

Usage:
BrainInertial.resetRotation();

参数

描述

该方法没有参数。

// Example coming soon

运动#

acceleration#

acceleration returns the acceleration of the Inertial Sensor in terms of G (gravity).

Usage:
BrainInertial.acceleration(axis);

参数

描述

axis

The axis to return the acceleration from:

  • xaxis
  • yaxis
  • zaxis
// Example coming soon

gyroRate#

gyroRate returns the gyro rate for one axis of the Inertial Sensor.

Usage:
BrainInertial.gyroRate(axis, units);

参数

描述

axis

The axis to return the gyro rate from:

  • xaxis
  • yaxis
  • zaxis

units

The unit used to represent the gyro rate:

  • dps – degrees per second
  • rpm – rotations per minute
  • velocityUnits::pct – percent
// Example coming soon

orientation#

orientation returns the orientation for one axis of the Inertial Sensor.

Usage:
BrainInertial.orientation(type, units);

参数

描述

type

The axis to return the orientation from:

  • pitch
  • roll
  • yaw

units

The unit used to represent the orientation:

  • degrees
  • turns
// Example coming soon

changed#

changed registers a callback function for when the Inertial Sensor’s heading changes.

Usage:
BrainInertial.changed(callback);

参数

描述

callback

当惯性传感器航向改变时调用的回调函数。

// Example coming soon

构造函数#

inertial#

inertial creates an Inertial Sensor.

Usage:
inertial BrainInertial = inertial();

范围

描述

该方法没有参数。

// Example coming soon