blob: 00f5f0058855e49b513663996c892be6eccf6a89 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// 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 Silverman8fce7482020-01-05 13:18:21 -08004
5#include "frc/BuiltInAccelerometer.h" // NOLINT(build/include_order)
6
7#include "frc/Timer.h"
8#include "gtest/gtest.h"
9
Brian Silverman8fce7482020-01-05 13:18:21 -080010static constexpr double kAccelerationTolerance = 0.1;
Austin Schuh812d0d12021-11-04 20:16:48 -070011
Brian Silverman8fce7482020-01-05 13:18:21 -080012/**
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 */
16TEST(BuiltInAccelerometerTest, Accelerometer) {
Austin Schuh812d0d12021-11-04 20:16:48 -070017 frc::BuiltInAccelerometer accelerometer;
Brian Silverman8fce7482020-01-05 13:18:21 -080018
Austin Schuh812d0d12021-11-04 20:16:48 -070019 // The testbench sometimes shakes a little from a previous test. Give it some
20 // time.
21 frc::Wait(1_s);
Brian Silverman8fce7482020-01-05 13:18:21 -080022
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}