blob: bfb5f2124fe4fbd137176192129fbbd637c0601d [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
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
13using namespace frc;
14
15static 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 */
20TEST(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}