加速度计#

介绍#

The accelerometer class measures acceleration detected by the Accelerometer at different sensitivities.

类构造函数#

accelerometer( 
  triport::port &port, 
  bool           bHighSensitivity = false);

类析构函数#

Destroys the accelerometer object and releases associated resources.

virtual ~accelerometer();

参数#

范围

类型

描述

port

triport::port &

The 3-Wire Port the Accelerometer is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

bHighSensitivity

bool

Sets the created Accelerometer to either a 2G or 6G Accelerometer by setting the high sensitivity mode:

  • false (default) — Creates a 2G Accelerometer
  • true — Creates a 6G Accelerometer

示例#

// Create a 2G accelerometer instance in Port A
accelerometer Accel2GA = accelerometer(Brain.ThreeWirePort.A);

// Create a 6G accelerometer instance in Port A
accelerometer Accel6GA = accelerometer(Brain.ThreeWirePort.A, true);

成员功能#

The accelerometer class includes the following member functions:

  • acceleration — Returns the acceleration detected by the Accelerometer.

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 6G accelerometer instance in Port A
accelerometer Accel6GA = accelerometer(Brain.ThreeWirePort.A, true);

acceleration#

返回加速度计的重力单位换算值。

Available Functions
double acceleration();

Parameters

此函数不接受任何参数。

Return Values

对于 6G 加速度计,返回范围为 +/- 6G 的双精度浮点数;对于 2G 加速度计,返回范围为 +/-2G 的双精度浮点数。

// Drive the robot forward.
Drivetrain.drive(forward);

// Get the acceleration of accel in the range +/- 6G.
double accelerationValue = Accel6GA.acceleration();