陀螺仪传感器#

介绍#

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

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

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.

例如,如果传感器已转向右侧,将航向设置为 0 度,则该右侧位置将成为新的 0 度。然后,传感器可以根据该新航向跟踪其他航向。

Usage:
gyro_sensor.set_heading(value, units)

参数

描述

value

要设置的传感器航向值,单位为度。该值可以介于 0 到 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.

例如,如果传感器向右旋转了两圈,其旋转角度将为 720 度。将旋转角度设置为 0 度会将旋转角度从 720 度重置为 0 度。然后,传感器可以根据这个新值跟踪旋转。

Usage:
gyro_sensor.set_rotation(value, units)

参数

描述

value

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.

起始航向为0度。

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.

向右转会增加旋转角度,向左转会减少旋转角度。例如,向右转两圈将得到 720 度的旋转角度。

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)