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

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ả |
|---|---|---|
|
|
Cổng 3 dây mà gia tốc kế được kết nối, được viết là |
|
|
Tùy chọn. Có bật chế độ độ nhạy cao cho gia tốc kế hay không:
|
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 Functionsdouble acceleration();
Hàm này không chấp nhận bất kỳ tham số nào.
Return ValuesTrả 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();