陀螺仪#
介绍#
陀螺仪传感器提供跟踪和改变机器人方向的方法。这些方法允许机器人大脑跟踪其方向和航向。
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);
参数 |
描述 |
|---|---|
|
One of the valid calibration types:
|
|
Optional. Whether or not to wait before executing the next command:
|
changed#
changed registers a callback function for when the Gyro Sensor’s heading changes.
Usage:
Gyro1.changed(callback);
参数 |
描述 |
|---|---|
|
先前定义的当陀螺仪传感器的航向改变时执行的函数。 |
修改器#
setHeading#
setHeading sets the heading of the Gyro Sensor to a specific value.
Usage:
Gyro1.setHeading(value, units);
参数 |
描述 |
|---|---|
|
要设置的航向值。 |
|
The unit that represents the new heading:
|
setRotation#
setRotation sets the rotation of the Gyro Sensor to a specific value.
Usage:
Gyro1.setRotation(value, units);
参数 |
描述 |
|---|---|
|
要设置的旋转值。 |
|
The unit that represents the new rotation:
|
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)
参数 |
描述 |
|---|---|
|
Optional. The unit that represents the heading:
|
rotation#
rotation returns the current rotation of the Gyro Sensor.
Usage:
Gyro1.rotation(units)
参数 |
描述 |
|---|---|
|
Optional. The unit that represents the rotation:
|
rate#
rate returns the current rate of change of the Gyro Sensor’s rotation.
Usage:
Gyro1.rate(units)
参数 |
描述 |
|---|---|
|
Optional. The unit used to represent the gyro rate:
|
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);
范围 |
描述 |
|---|---|
|
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);
}