2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-07-31 10:04:25 -04:00
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
2018-05-24 00:31:04 -04:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.logging.Logger;
|
2014-07-31 10:04:25 -04:00
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.junit.runners.Parameterized;
|
|
|
|
|
import org.junit.runners.Parameterized.Parameters;
|
|
|
|
|
|
|
|
|
|
@RunWith(Parameterized.class)
|
2014-07-31 15:49:55 -04:00
|
|
|
public class BuiltInAccelerometerTest extends AbstractComsSetup {
|
2015-06-25 15:07:55 -04:00
|
|
|
private static final Logger logger = Logger.getLogger(BuiltInAccelerometerTest.class.getName());
|
|
|
|
|
private static final double kAccelerationTolerance = 0.1;
|
|
|
|
|
private final BuiltInAccelerometer m_accelerometer;
|
2014-07-31 10:04:25 -04:00
|
|
|
|
2023-07-18 12:52:43 -07:00
|
|
|
public BuiltInAccelerometerTest(BuiltInAccelerometer.Range range) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_accelerometer = new BuiltInAccelerometer(range);
|
|
|
|
|
}
|
2014-07-31 10:04:25 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
@BeforeClass
|
|
|
|
|
public static void waitASecond() {
|
|
|
|
|
/*
|
|
|
|
|
* The testbench sometimes shakes a little from a previous test. Give it
|
|
|
|
|
* some time.
|
|
|
|
|
*/
|
|
|
|
|
Timer.delay(1.0);
|
|
|
|
|
}
|
2014-07-31 10:04:25 -04:00
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
/** Test with all valid ranges to make sure unpacking is always done correctly. */
|
2015-06-25 15:07:55 -04:00
|
|
|
@Parameters
|
2023-07-18 12:52:43 -07:00
|
|
|
public static Collection<BuiltInAccelerometer.Range[]> generateData() {
|
2020-12-29 22:45:16 -08:00
|
|
|
return Arrays.asList(
|
2023-07-18 12:52:43 -07:00
|
|
|
new BuiltInAccelerometer.Range[][] {
|
|
|
|
|
{BuiltInAccelerometer.Range.k2G},
|
|
|
|
|
{BuiltInAccelerometer.Range.k4G},
|
|
|
|
|
{BuiltInAccelerometer.Range.k8G}
|
2020-12-29 22:45:16 -08:00
|
|
|
});
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
2014-07-31 10:04:25 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
@Override
|
|
|
|
|
protected Logger getClassLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
2014-07-31 10:04:25 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/**
|
2016-05-20 12:07:40 -04:00
|
|
|
* There's not much we can automatically test with the on-board accelerometer, but checking for
|
|
|
|
|
* gravity is probably good enough to tell that it's working.
|
2015-06-25 15:07:55 -04:00
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testAccelerometer() {
|
|
|
|
|
assertEquals(0.0, m_accelerometer.getX(), kAccelerationTolerance);
|
|
|
|
|
assertEquals(1.0, m_accelerometer.getY(), kAccelerationTolerance);
|
|
|
|
|
assertEquals(0.0, m_accelerometer.getZ(), kAccelerationTolerance);
|
|
|
|
|
}
|
2014-07-31 10:04:25 -04:00
|
|
|
}
|