Gia tốc kế#

Giới thiệu#

Gia tốc kế loại accelerometer , đo gia tốc của robot dọc theo một hoặc nhiều trục. Cảm biến xuất ra điện áp tương tự thay đổi dựa trên gia tốc tính bằng lực G (G).

Một cầu nối trên cảm biến gia tốc xác định phạm vi độ nhạy của nó:

  • 2G - Đo gia tốc từ -2G đến +2G

  • 6G - Đo gia tốc từ -6G đến +6G

Gia tốc kế tương tự VEX EXP.

Hàm tạo lớp#

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

Lớp Destructor#

Destroys the accelerometer object and releases associated resources.

virtual ~accelerometer();

Thông số#

Tham số

Kiểu

Sự miêu tả

port

triport::port &

Cổng 3 dây mà gia tốc kế được kết nối, được viết là Brain.ThreeWirePort.X hoặc ExpanderName.X, trong đó X là ký tự của cổng (ví dụ: Brain.ThreeWirePort.A hoặc Expander1.A).

bHighSensitivity

bool

Tùy chọn. Có bật chế độ độ nhạy cao cho gia tốc kế hay không:

  • true - Bật độ nhạy cao (+/- 2G).
  • false (mặc định) - Bật độ nhạy thấp (+/- 6G).

Ví dụ#

// 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);

Chức năng thành viên#

Lớp gia tốc kế accelerometer bao gồm các hàm thành viên sau:

  • acceleration — Trả về gia tốc được đo bởi Gia tốc kế tính bằng G.

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#

Trả về gia tốc được đo bằng G.

Available Functions
double acceleration();

Parameters

Hàm này không chấp nhận bất kỳ tham số nào.

Return Values

Trả về giá trị double double biểu thị gia tốc đo được bằng G.

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

// Get the acceleration measured by the Accelerometer.
double accelerationValue = Accel2GA.acceleration();