陀螺仪#

介绍#

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

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

以下是所有方法的列表:

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

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

  • changed – Registers a function to call 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.

// Example coming soon

changed#

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

Usage:
Gyro1.changed(callback);

参数

描述

callback

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

// Example coming soon

修改器#

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
// Example coming soon

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
// Example coming soon

resetHeading#

resetHeading resets the heading of the Gyro Sensor to 0.

Usage:
Gyro1.resetHeading();

参数

描述

该方法没有参数。

// Example coming soon

resetRotation#

resetRotation resets the rotation of the Gyro Sensor to 0.

Usage:
Gyro1.resetRotation();

参数

描述

该方法没有参数。

// Example coming soon

吸气剂#

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
// Example coming soon

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
// Example coming soon

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 – revolutions per second
// Example coming soon

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()

参数

描述

该方法没有参数。

// Example coming soon

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(port);

范围

描述

port

Which Smart Port that the Gyro Sensor is connected to as PORT followed by the port number, ranging from 1 to 12.

// Example coming soon