Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 4 | |
| 5 | #include "frc/BuiltInAccelerometer.h" // NOLINT(build/include_order) |
| 6 | |
| 7 | #include "frc/Timer.h" |
| 8 | #include "gtest/gtest.h" |
| 9 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 10 | static constexpr double kAccelerationTolerance = 0.1; |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 11 | |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 12 | /** |
| 13 | * There's not much we can automatically test with the on-board accelerometer, |
| 14 | * but checking for gravity is probably good enough to tell that it's working. |
| 15 | */ |
| 16 | TEST(BuiltInAccelerometerTest, Accelerometer) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 17 | frc::BuiltInAccelerometer accelerometer; |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 18 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 19 | // The testbench sometimes shakes a little from a previous test. Give it some |
| 20 | // time. |
| 21 | frc::Wait(1_s); |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 22 | |
| 23 | ASSERT_NEAR(0.0, accelerometer.GetX(), kAccelerationTolerance); |
| 24 | ASSERT_NEAR(1.0, accelerometer.GetY(), kAccelerationTolerance); |
| 25 | ASSERT_NEAR(0.0, accelerometer.GetZ(), kAccelerationTolerance); |
| 26 | } |