陀螺仪传感器#

介绍#

陀螺仪传感器测量机器人的航向和旋转。

在“设备”窗口中,只有当陀螺仪传感器作为独立组件配置,而不是作为传动系统配置的一部分时,“陀螺仪传感器”类别才会出现。

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

以下是可用方法列表:

  • calibrate – Calibrates the configured Gyro Sensor.

  • set_heading – Changes the Gyro Sensor’s current heading to a new heading.

  • set_rotation – Changes the Gyro Sensor’s current rotation to a new rotation.

  • heading – Returns the Gyro Sensor’s heading angle as a float.

  • rotation – Returns how much the Gyro Sensor has rotated since the project started as a float.

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

  • Gyro – Create a Gyro Sensor.

校准#

calibrate calibrates the Gyro Sensor. All subsequent methods 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 sensor must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.

Usage:
gyro_sensor.calibrate()

参数

描述

此方法没有参数。

设置标题#

A heading is the direction the sensor is facing, measured in degrees. set_heading changes the Gyro Sensor’s current heading to a new heading value.

For example, if the sensor has turned to face right, setting the heading to 0 degrees makes that right-facing position the new 0 degrees. Then the sensor can track other headings based on that new heading.

Usage:
gyro_sensor.set_heading(value, units)

参数

描述

价值

The heading value, in degrees, to set for the sensor. This can be a value from 0 to 359.99.

单位

Optional. The heading unit: DEGREES

设置旋转#

Rotation is how much the sensor has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation changes the Gyro Sensor’s current rotation to a new value.

For example, if the sensor has made two full turns to the right, its rotation value will be 720 degrees. Setting the rotation to 0 degrees will reset that rotation from 720 to 0 degrees. Then the sensor can track rotations based on that new value.

Usage:
gyro_sensor.set_rotation(value, units)

参数

描述

价值

The rotation value, in degrees, to set for the sensor. This can be an integer or a decimal (float).

单位

Optional. The rotation unit: DEGREES

标题#

A heading is the direction the sensor is facing, measured in degrees. heading returns that heading as a float from 0 to 359.99 degrees.

The starting heading is 0 degrees.

Usage:
gyro_sensor.heading(units)

参数

描述

单位

Optional. The heading unit: DEGREES

旋转#

Rotation is how much the sensor has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the Gyro Sensor’s current rotation.

Turning right increases the rotation, and turning left decreases the rotation. For example, making two full turns to the right will return a rotation of 720 degrees.

Usage:
gyro_sensor.rotation(units)

参数

描述

单位

Optional. The rotation unit: DEGREES

构造器#

Constructors are used to manually create Gyro objects, which are necessary for configuring a Gyro Sensor outside of VEXcode.

Gyro#

Gyro creates a Gyro Sensor.

Usage:
Gyro(port)

范围

描述

port

The 3-Wire Port that the Gyro Sensor is connected to:

  • On the EXP Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Gyro Sensor in Port A
gyro_sensor = Gyro(brain.three_wire_port.a)