2014-07-31 10:04:25 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2014-07-31 10:04:25 -04:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* the project. */
|
2014-07-31 10:04:25 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-07-31 10:04:25 -04:00
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
|
|
|
|
|
2016-05-20 12:07:40 -04:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
2014-07-31 10:04:25 -04:00
|
|
|
@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
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
public BuiltInAccelerometerTest(Accelerometer.Range range) {
|
|
|
|
|
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
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
/**
|
|
|
|
|
* Test with all valid ranges to make sure unpacking is always done correctly.
|
|
|
|
|
*/
|
|
|
|
|
@Parameters
|
|
|
|
|
public static Collection<Accelerometer.Range[]> generateData() {
|
2016-05-20 12:07:40 -04:00
|
|
|
return Arrays.asList(new Accelerometer.Range[][]{{Accelerometer.Range.k2G},
|
2017-05-07 02:22:16 -04:00
|
|
|
{Accelerometer.Range.k4G}, {Accelerometer.Range.k8G}});
|
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
|
|
|
|
|
|
|
|
}
|