陀螺仪传感器#
介绍#
gyro 类用于测量机器人的航向和旋转运动,从而可以跟踪其随时间推移的姿态。
类构造函数#
gyro(
triport::port &port);
类析构函数#
销毁 gyro 对象并释放相关资源。
virtual ~gyro();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
陀螺仪传感器连接的 3 线端口,写成 |
例子#
// Create a gyro instance in Port A
gyro GyroA = gyro(Brain.ThreeWirePort.A);
成员功能#
gyro 类包含以下成员函数:
calibrate— 校准陀螺仪以实现稳定的航向跟踪。setHeading— 设置陀螺仪的航向。setRotation— 设置陀螺仪的当前旋转值。heading— 返回陀螺仪的航向。rotation— 返回陀螺仪的旋转角度。
在调用任何 gyro 成员函数之前,必须先创建一个 gyro 实例,如下所示:
/* 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(
int32_t value = 0 );
参数 |
类型 |
描述 |
|---|---|---|
|
|
校准所需时间(秒)。默认值为 |
此函数不返回值。
Notescalibrate仅应在传感器不移动时调用。
// Start calibration with the calibration time set to 3 seconds.
GyroA.calibrate(3);
setHeading#
将陀螺仪传感器的航向设置为特定值。
Available Functionsvoid setHeading(
double value,
rotationUnits units );
参数 |
类型 |
描述 |
|---|---|---|
|
|
新标题要使用的值。 |
|
|
表示航向的单位:
|
此函数不返回值。
setRotation#
将陀螺仪传感器的旋转角度设置为特定值。
Available Functionsvoid setRotation(
double value,
rotationUnits units );
参数 |
类型 |
描述 |
|---|---|---|
|
|
要用于新旋转值的值。 |
|
|
表示旋转值的单位:
|
此函数不返回值。
heading#
返回陀螺仪传感器的当前航向。
Available Functionsdouble heading(
rotationUnits units = degrees );
范围 |
类型 |
描述 |
|---|---|---|
|
|
表示航向的单位:
|
返回一个 double 表示陀螺仪传感器的当前航向,单位为指定值,默认为 degrees。
// Get the current heading for the Gyro.
double value = GyroA.heading();
Brain.Screen.print(value);
rotation#
返回陀螺仪传感器的当前旋转角度。
Available Functionsdouble rotation(
rotationUnits units = degrees );
范围 |
类型 |
描述 |
|---|---|---|
|
|
表示旋转值的单位:
|
返回一个 double 表示陀螺仪传感器的当前旋转值,单位为指定值,默认为 degrees。
// Get the current rotation for the Gyro.
double value = GyroA.rotation();
Brain.Screen.print(value);