陀螺仪#

介绍#

陀螺仪传感器提供跟踪和改变机器人方向的方法。这些方法允许机器人大脑跟踪其方向和航向。

This page uses Gyro1 as the example Gyro Sensor name. Replace it with your own configured name as needed.

以下是所有方法的列表:

动作——使用陀螺仪传感器校准并检测方向变化。

  • calibrate – Calibrates the Gyro Sensor for stable heading tracking.

  • changed – Registers a function to be called when the Gyro Sensor detects change.

变异器——修改陀螺仪传感器的航向和旋转。

  • setHeading – Sets the Gyro Sensor’s heading to a specified value.

  • setRotation – Sets the Gyro Sensor’s rotation value.

  • resetHeading – Sets the heading of the Gyro Sensor to 0.

  • resetRotation – Sets the rotation of the Gyro Sensor to 0.

Getters – 使用陀螺仪传感器返回方向和运动数据。

  • heading – Returns the current heading.

  • rotation – Returns the cumulative rotation.

  • rat – Returns the angular velocity around the x, y, or z axis.

  • isCalibrating – Returns whether or not the Gyro Sensor is calibrating.

  • installed – Returns whether or not a Gyro Sensor is connected to the Brain.

构造函数——手动初始化陀螺仪传感器。

  • gyro – Create a Gyro Sensor.

行动#

calibrate#

calibrate calibrates the Gyro Sensor. Calibration should be used when the Gyro Sensor is not moving.

Usage:
Gyro1.calibrate(time, wait);

参数

描述

time

One of the valid calibration types:

  • calExtended – An extended calibration.
  • calNormal – Normal calibration speed.
  • calSlow – Slow calibration speed.

wait

Optional. Whether or not to wait before executing the next command:

  • true – Wait before executing the next command.
  • false – Do not wait before executing the next command.

changed#

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

Usage:
Gyro1.changed(callback);

参数

描述

callback

先前定义的当陀螺仪传感器的航向改变时执行的函数。

修改器#

setHeading#

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

Usage:
Gyro1.setHeading(value, units);

参数

描述

value

要设置的航向值。

units

The unit that represents the new heading:

  • degrees
  • turns

setRotation#

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

Usage:
Gyro1.setRotation(value, units);

参数

描述

value

要设置的旋转值。

units

The unit that represents the new rotation:

  • degrees
  • turns

resetHeading#

resetHeading resets the heading of the Gyro Sensor to 0.

Usage:
Gyro1.resetHeading();

参数

描述

该方法没有参数。

resetRotation#

resetRotation resets the rotation of the Gyro Sensor to 0.

Usage:
Gyro1.resetRotation();

参数

描述

该方法没有参数。

吸气剂#

heading#

heading returns the current heading of the Gyro Sensor.

Usage:
Gyro1.heading(units)

参数

描述

units

Optional. The unit that represents the heading:

  • degrees (default)
  • turns

rotation#

rotation returns the current rotation of the Gyro Sensor.

Usage:
Gyro1.rotation(units)

参数

描述

units

Optional. The unit that represents the rotation:

  • degrees (default)
  • turns

rate#

rate returns the current rate of change of the Gyro Sensor’s rotation.

Usage:
Gyro1.rate(units)

参数

描述

units

Optional. The unit used to represent the gyro rate:

  • dps (default) - degrees per second
  • rateUnits::rps – rotations per second

isCalibrating#

isCalibrating returns a Boolean indicating if the Gyro Sensor is currently calibrating.

  • true - The Gyro Sensor is calibrating.

  • false - The Gyro Sensor is not calibrating.

Usage:
Gyro1.isCalibrating()

参数

描述

该方法没有参数。

installed#

installed returns a Boolean indicating whether the Gyro Sensor is connected to the Brain.

  • true - The Gyro Sensor is connected to the Brain.

  • false - The Gyro Sensor is not connected to the Brain.

Usage:
Gyro1.installed()

参数

描述

该方法没有参数。

构造函数#

gyro#

gyro creates an object of the gyro Class in the specified port.

Usage:
gyro Gyro1 = gyro(smartport);

范围

描述

smartport

The Smart Port that the Gyro Sensor is connected to, written as PORTx where x is the number of the port.

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

  // Create a Gyro on Port 3
  gyro myyro = gyro(PORT3);
}