惯性#

初始化惯性类#

使用以下构造函数创建惯性传感器:

The inertial constructor creates an inertial object using the EXP Brain’s internal Inertial Sensor.

范围

描述

目录

The directionType which corresponds to a positive heading value. The default is right.

// Create a new object "Inertial" with the
// inertial class.
inertial Inertial = inertial();

The inertial(port, dir) constructor creates an inertial object using the EXP Brain’s internal Inertial Sensor.

范围

描述

port

惯性传感器连接到的有效 智能端口

目录

The directionType which corresponds to a positive heading value. The default is right.

// Construct a Inertial Sensor "Inertial" with the
// inertial class.
inertial Inertial = inertial(PORT1);

This Inertial object will be used in all subsequent examples throughout this API documentation when referring to inertial class methods.

类方法#

calibrate()#

陀螺仪或惯性传感器将根据校准期间 EXP Brain 的方向自动调整其值,以便它在所有可能的 EXP Brain 方向上保持一致。

../../_images/EXP_right_orientation.png../../_images/EXP_left_orientation.png../../_images/EXP_top_orientation.png

该方法通过以下方式调用:

The calibrate() method calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving. Allow at least 2 seconds for calibration to complete.

**返回:**无。

// Start calibration.
Inertial.calibrate();

The calibrate(value) method calibrates the Inertial Sensor. Calibration should be done when the Inertial Sensor is not moving. Allow at least 2 seconds for calibration to complete.

参数

描述

价值

设置校准时间。默认值为 0。

**返回:**无。

// Start calibration with the calibration time set to 3 seconds.
Inertial.calibrate(3);

isCalibrating()#

The isCalibrating() method checks if the Inertial Sensor is currently calibrating.

Returns: true if the Inertial Sensor is calibrating. false if it is not.

// Start calibration.
Inertial.calibrate();
// Print that the Inertial Sensor is calibrating while
// waiting for it to finish calibrating.
while(Inertial.isCalibrating()){
    Brain.Screen.clear();
    Brain.Screen.print("Inertial Calibrating");
    wait(50, msec);
}

resetHeading()#

The resetHeading() method resets the heading of the Inertial Sensor to 0.

**返回:**无。

setHeading()#

The setHeading(value, units) method sets the heading of the Inertial Sensor to a specified value.

参数

描述

价值

要设置的航向值。

单位

有效的 rotationUnit

**返回:**无。

// Set the Inertial Sensor's heading to 180 degrees.
Inertial.setHeading(180);

heading()#

The heading(units) method returns the current heading of the Inertial Sensor.

参数

描述

单位

A valid rotationUnit. The default is degrees.

**返回:**以指定单位表示惯性传感器当前航向的双精度值。

// Get the current heading for the Inertial Sensor.
double value = Inertial.heading();

resetRotation()#

The resetRotation() method resets the rotation of the Inertial Sensor to 0.

**返回:**无。

setRotation()#

The setRotation(value, units) method sets the rotation of the Inertial Sensor to a specified value.

参数

描述

价值

要设置的旋转值。

单位

有效的 rotationUnit

**返回:**无。

// Set the Inertial Sensor's rotation to 180 degrees.
Inertial.setRotation(180);

rotation()#

The rotation(units) method returns the current rotation of the Inertial Sensor.

参数

描述

单位

A valid rotationUnit. The default is degrees.

返回: 以指定单位表示惯性传感器当前旋转的双精度值。

// Get the current rotation for the Inertial Sensor.
double value = Inertial.rotation();

angle()#

The angle(units) method returns the current angle of the Inertial Sensor.

参数

描述

单位

A valid rotationUnit. The default is degrees.

**返回:**以指定单位表示惯性传感器当前角度的双精度值。

// Get the current angle for the Inertial Sensor.
double value = Inertial.angle();

roll()#

The roll(units) method returns the roll angle of the Inertial Sensor.

参数

描述

单位

A valid rotationUnit. The default is degrees.

**返回:**表示惯性传感器滚动值的双精度数。

pitch()#

The pitch(units) method returns the roll angle of the Inertial Sensor.

参数

描述

单位

A valid rotationUnit. The default is degrees.

**返回:**表示惯性传感器的俯仰值的双精度数。

yaw()#

The yaw(units) method returns the yaw angle of the Inertial Sensor.

参数

描述

单位

A valid rotationUnit. The default is degrees.

**返回:**表示惯性传感器偏航值的双精度数。

orientation()#

The orientation(axis, units) method returns the orientation for one axis of the Inertial Sensor.

参数

描述

有效的 axisType

单位

有效的 rotationUnit

**返回:**以指定单位表示轴方向的双精度值。

// Get the orientation value for the X axis of the
// Inertial Sensor.
double orient = Inertial.orientation(xaxis);

gyroRate()#

The gyroRate(axis, units) method returns the gyro rate for one axis of the Inertial Sensor.

参数

描述

有效的 axisType

单位

有效的 velocityUnit

**返回:**以指定的单位表示轴的陀螺仪速率的双精度值。

// Get the gyro rate for the Z axis of the Inertial Sensor.
double zrate = Inertial.gyroRate(zaxis);

acceleration()#

The acceleration(axis) method returns the acceleration of a specific axis of the Inertial Sensor.

参数

描述

有效的 axisType

**返回:**以重力单位表示轴加速度的双精度值。

// Get the acceleration for the Z axis of the
// Inertial Sensor.
double accel = Inertial.acceleration(zaxis);

// Print the value of the current acceleration of the z-axis
// of the Inertial Sensor to the Brain's screen.
Brain.Screen.print(accel);

changed()#

The changed(callback) method registers a callback function for when the Inertial Sensor heading changes.

参数

描述

打回来

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

**返回:**事件类的一个实例。

// Define the inertialChanged function with a void return
// type, showing it doesn't return a value.
void inertialChanged() {
  // The brain will print that the Inertial Sensor changed
  // on the Brain's screen.
  Brain.Screen.print("accelerometer changed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Turn the robot right.
  Drivetrain.turn(right);

  // Run inertialChanged when the value of the
  // Inertial Sensor changes.
  Inertial.changed(inertialChanged);
}

collision()#

The collision(axis, x, y, z) method registers a callback function for when the Inertial Sensor detects a collision.

参数

描述

有效的 axisType

x

x 轴加速度值的双精度数。

y

y 轴加速度值的双精度数。

z

z 轴加速度值的双精度数。

**返回:**事件类的一个实例。

timestamp()#

The timestamp() method requests the timestamp of the last received status packet from the Inertial Sensor.

**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。

installed()#

The installed() method returns if the Inertial Sensor is installed.

Returns: true if the Inertial Sensor is installed. false if it is not.