加速度计#
介绍#
The accelerometer class measures the acceleration of the robot along one or more axes. The sensor outputs an analog voltage that changes based on acceleration in G-forces (G).
加速度计上的跳线决定了其灵敏度范围:
2G - 测量从 -2G 到 +2G 的加速度
6G - 测量从 -6G 到 +6G 的加速度

类构造函数#
accelerometer(
triport::port &port,
bool bHighSensitivity = false);
类析构函数#
Destroys the accelerometer object and releases associated resources.
virtual ~accelerometer();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The 3-Wire Port the Accelerometer is connected to, written as |
|
|
Optional. Whether to enable high sensitivity mode on the Accelerometer:
|
示例#
// Create a 6G accelerometer instance in Port A
accelerometer Accel6GA = accelerometer(Brain.ThreeWirePort.A);
// Create a 2G accelerometer instance in Port A
accelerometer Accel2GA = accelerometer(Brain.ThreeWirePort.A, true);
成员功能#
The accelerometer class includes the following member functions:
acceleration— Returns the acceleration measured by the Accelerometer in Gs.
Before calling any accelerometer member functions, an accelerometer instance must be created, as shown below:
/* This constructor is required when using VS Code.
Accelerometer configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a 2G accelerometer instance in Port A
accelerometer Accel2GA = accelerometer(Brain.ThreeWirePort.A, true);
acceleration#
返回以 G 为单位的加速度。
Available Functionsdouble acceleration();
此函数不接受任何参数。
Return ValuesReturns a double representing the acceleration measured in Gs.
// Drive the robot forward.
Drivetrain.drive(forward);
// Get the acceleration measured by the Accelerometer.
double accelerationValue = Accel2GA.acceleration();