陀螺仪传感器#
介绍#
The gyro class is used to measure the robot’s heading and rotational movement, allowing tracking of orientation over time.
类构造函数#
gyro(
triport::port &port);
类析构函数#
Destroys the gyro object and releases associated resources.
virtual ~gyro();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The 3-Wire Port that the Gyro Sensor is connected to, written as |
例子#
// Create a gyro instance in Port A
gyro GyroA = gyro(Brain.ThreeWirePort.A);
成员功能#
The gyro class includes the following member functions:
calibrate— Calibrates the gyro for stable heading tracking.setHeading— Sets the heading of the gyro.setRotation— Sets the current rotation value of the gyro.heading— Returns the heading of the gyro.rotation— Returns the rotation of the gyro.
Before calling any gyro member functions, a gyro instance must be created, as shown below:
/* This constructor is required when using VS Code.
Gyro Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a gyro instance in Port A
gyro GyroA = gyro(Brain.ThreeWirePort.A);
calibrate#
校准陀螺仪传感器。
Available Functionsvoid calibrate();
此函数不接受任何参数。
Return Values此函数不返回值。
Notescalibrateshould only be called when the sensor is not moving.
// Start calibration with the calibration time set to 3 seconds.
GyroA.calibrate(3);
setHeading#
将陀螺仪传感器的航向设置为特定值。
Available Functionsvoid setHeading(
double value,
rotationUnits units );
参数 |
类型 |
描述 |
|---|---|---|
|
|
新标题要使用的值。 |
|
|
The unit that represents the heading:
|
此函数不返回值。
setRotation#
将陀螺仪传感器的旋转角度设置为特定值。
Available Functionsvoid setRotation(
double value,
rotationUnits units );
参数 |
类型 |
描述 |
|---|---|---|
|
|
要用于新旋转值的值。 |
|
|
The unit that represents the rotation value:
|
此函数不返回值。
heading#
返回陀螺仪传感器的当前航向。
Available Functionsdouble heading(
rotationUnits units = degrees );
| Parameter | Type | Description |
| :—————-: | :————————————– |
| units | rotationUnits | The unit that represents the heading:
degrees(default)turns
- |
Return Values
Returns a double representing the current heading of the Gyro Sensor in the specified units, defaulting to degrees.
// Get the current heading for the Gyro.
double value = GyroA.heading();
Brain.Screen.print(value);
rotation#
返回陀螺仪传感器的当前旋转角度。
Available Functionsdouble rotation(
rotationUnits units = degrees );
| Parameter | Type | Description |
| :—————-: | :————————————– |
| units | rotationUnits | The unit that represents the rotation value:
degrees(default)turns
- |
Return Values
Returns a double representing the current rotation value of the Gyro Sensor in the specified units, defaulting to degrees.
// Get the current rotation for the Gyro.
double value = GyroA.rotation();
Brain.Screen.print(value);