Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "frc/BuiltInAccelerometer.h" // NOLINT(build/include_order) |
| 9 | |
| 10 | #include "frc/Timer.h" |
| 11 | #include "gtest/gtest.h" |
| 12 | |
| 13 | using namespace frc; |
| 14 | |
| 15 | static constexpr double kAccelerationTolerance = 0.1; |
| 16 | /** |
| 17 | * There's not much we can automatically test with the on-board accelerometer, |
| 18 | * but checking for gravity is probably good enough to tell that it's working. |
| 19 | */ |
| 20 | TEST(BuiltInAccelerometerTest, Accelerometer) { |
| 21 | BuiltInAccelerometer accelerometer; |
| 22 | |
| 23 | /* The testbench sometimes shakes a little from a previous test. Give it |
| 24 | some time. */ |
| 25 | Wait(1.0); |
| 26 | |
| 27 | ASSERT_NEAR(0.0, accelerometer.GetX(), kAccelerationTolerance); |
| 28 | ASSERT_NEAR(1.0, accelerometer.GetY(), kAccelerationTolerance); |
| 29 | ASSERT_NEAR(0.0, accelerometer.GetZ(), kAccelerationTolerance); |
| 30 | } |