2014-06-18 11:02:23 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2008-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-06-18 11:02:23 -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-06-18 11:02:23 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-06-18 11:02:23 -04:00
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
2016-05-20 12:07:40 -04:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
2014-06-18 11:02:23 -04:00
|
|
|
import edu.wpi.first.wpilibj.fixtures.AnalogCrossConnectFixture;
|
|
|
|
|
import edu.wpi.first.wpilibj.mockhardware.FakePotentiometerSource;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
|
|
|
|
import edu.wpi.first.wpilibj.test.TestBench;
|
|
|
|
|
|
2016-05-20 12:07:40 -04:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
2014-06-18 11:02:23 -04:00
|
|
|
/**
|
2016-05-20 12:07:40 -04:00
|
|
|
* Tests the {@link AnalogPotentiometer}.
|
2014-06-18 11:02:23 -04:00
|
|
|
*/
|
|
|
|
|
public class AnalogPotentiometerTest extends AbstractComsSetup {
|
2015-06-25 15:07:55 -04:00
|
|
|
private static final Logger logger = Logger.getLogger(AnalogPotentiometerTest.class.getName());
|
2016-05-20 12:07:40 -04:00
|
|
|
private AnalogCrossConnectFixture m_analogIO;
|
|
|
|
|
private FakePotentiometerSource m_potSource;
|
|
|
|
|
private AnalogPotentiometer m_pot;
|
2014-06-18 11:02:23 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private static final double DOUBLE_COMPARISON_DELTA = 2.0;
|
2014-06-18 11:02:23 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
@Before
|
|
|
|
|
public void setUp() throws Exception {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_analogIO = TestBench.getAnalogCrossConnectFixture();
|
|
|
|
|
m_potSource = new FakePotentiometerSource(m_analogIO.getOutput(), 360);
|
|
|
|
|
m_pot = new AnalogPotentiometer(m_analogIO.getInput(), 360.0, 0);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void tearDown() throws Exception {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_potSource.reset();
|
2018-05-22 23:33:17 -07:00
|
|
|
m_pot.close();
|
2016-05-20 12:07:40 -04:00
|
|
|
m_analogIO.teardown();
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Logger getClassLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInitialSettings() {
|
2016-05-20 12:07:40 -04:00
|
|
|
assertEquals(0, m_pot.get(), DOUBLE_COMPARISON_DELTA);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testRangeValues() {
|
|
|
|
|
for (double i = 0.0; i < 360.0; i = i + 1.0) {
|
2016-05-20 12:07:40 -04:00
|
|
|
m_potSource.setAngle(i);
|
|
|
|
|
m_potSource.setMaxVoltage(ControllerPower.getVoltage5V());
|
2015-06-25 15:07:55 -04:00
|
|
|
Timer.delay(.02);
|
2016-05-20 12:07:40 -04:00
|
|
|
assertEquals(i, m_pot.get(), DOUBLE_COMPARISON_DELTA);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-18 11:02:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|