Applies Google Styleguide to Java parts of the library (#23)

This was partially applied to simulation but
simulation is a bit of a mess and has a lot of duplicated code.
This commit is contained in:
Jonathan Leitschuh
2016-05-20 12:07:40 -04:00
committed by Peter Johnson
parent 64ab6e51fe
commit a834fff7b2
266 changed files with 15574 additions and 14718 deletions

View File

@@ -7,18 +7,6 @@
package edu.wpi.first.wpilibj;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -28,29 +16,43 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.logging.Logger;
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
import edu.wpi.first.wpilibj.test.TestBench;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* Test that covers the {@link PIDController}.
*
* @author Kacper Puczydlowski
* @author Jonathan Leitschuh
*
*/
@RunWith(Parameterized.class)
public class PIDTest extends AbstractComsSetup {
private static final Logger logger = Logger.getLogger(PIDTest.class.getName());
private NetworkTable table;
private NetworkTable m_table;
private static final double absoluteTolerance = 50;
private static final double outputRange = 0.25;
private PIDController controller = null;
private PIDController m_controller = null;
private static MotorEncoderFixture me = null;
@SuppressWarnings({"MemberName", "EmptyLineSeparator", "MultipleVariableDeclarations"})
private final Double k_p, k_i, k_d;
@Override
@@ -59,10 +61,12 @@ public class PIDTest extends AbstractComsSetup {
}
@SuppressWarnings({"ParameterName", "JavadocMethod"})
public PIDTest(Double p, Double i, Double d, MotorEncoderFixture mef) {
logger.fine("Constructor with: " + mef.getType());
if (PIDTest.me != null && !PIDTest.me.equals(mef))
if (PIDTest.me != null && !PIDTest.me.equals(mef)) {
PIDTest.me.teardown();
}
PIDTest.me = mef;
this.k_p = p;
this.k_i = i;
@@ -78,7 +82,7 @@ public class PIDTest extends AbstractComsSetup {
double ki = 0.0005;
double kd = 0.0;
for (int i = 0; i < 1; i++) {
data.addAll(Arrays.asList(new Object[][] {
data.addAll(Arrays.asList(new Object[][]{
{kp, ki, kd, TestBench.getInstance().getTalonPair()},
{kp, ki, kd, TestBench.getInstance().getVictorPair()},
{kp, ki, kd, TestBench.getInstance().getJaguarPair()}}));
@@ -86,15 +90,10 @@ public class PIDTest extends AbstractComsSetup {
return data;
}
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
public static void setUpBeforeClass() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
logger.fine("TearDownAfterClass: " + me.getType());
@@ -102,36 +101,30 @@ public class PIDTest extends AbstractComsSetup {
me = null;
}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
logger.fine("Setup: " + me.getType());
me.setup();
table = NetworkTable.getTable("TEST_PID");
controller = new PIDController(k_p, k_i, k_d, me.getEncoder(), me.getMotor());
controller.initTable(table);
m_table = NetworkTable.getTable("TEST_PID");
m_controller = new PIDController(k_p, k_i, k_d, me.getEncoder(), me.getMotor());
m_controller.initTable(m_table);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
logger.fine("Teardown: " + me.getType());
controller.disable();
controller.free();
controller = null;
m_controller.disable();
m_controller.free();
m_controller = null;
me.reset();
}
private void setupAbsoluteTolerance() {
controller.setAbsoluteTolerance(absoluteTolerance);
m_controller.setAbsoluteTolerance(absoluteTolerance);
}
private void setupOutputRange() {
controller.setOutputRange(-outputRange, outputRange);
m_controller.setOutputRange(-outputRange, outputRange);
}
@Test
@@ -139,14 +132,15 @@ public class PIDTest extends AbstractComsSetup {
setupAbsoluteTolerance();
setupOutputRange();
double setpoint = 2500.0;
controller.setSetpoint(setpoint);
assertFalse("PID did not begin disabled", controller.isEnable());
assertEquals("PID.getError() did not start at " + setpoint, setpoint, controller.getError(), 0);
assertEquals(k_p, table.getNumber("p"), 0);
assertEquals(k_i, table.getNumber("i"), 0);
assertEquals(k_d, table.getNumber("d"), 0);
assertEquals(setpoint, table.getNumber("setpoint"), 0);
assertFalse(table.getBoolean("enabled"));
m_controller.setSetpoint(setpoint);
assertFalse("PID did not begin disabled", m_controller.isEnable());
assertEquals("PID.getError() did not start at " + setpoint, setpoint,
m_controller.getError(), 0);
assertEquals(k_p, m_table.getNumber("p"), 0);
assertEquals(k_i, m_table.getNumber("i"), 0);
assertEquals(k_d, m_table.getNumber("d"), 0);
assertEquals(setpoint, m_table.getNumber("setpoint"), 0);
assertFalse(m_table.getBoolean("enabled"));
}
@Test
@@ -154,15 +148,15 @@ public class PIDTest extends AbstractComsSetup {
setupAbsoluteTolerance();
setupOutputRange();
double setpoint = 2500.0;
controller.setSetpoint(setpoint);
controller.enable();
m_controller.setSetpoint(setpoint);
m_controller.enable();
Timer.delay(.5);
assertTrue(table.getBoolean("enabled"));
assertTrue(controller.isEnable());
assertTrue(m_table.getBoolean("enabled"));
assertTrue(m_controller.isEnable());
assertThat(0.0, is(not(me.getMotor().get())));
controller.reset();
assertFalse(table.getBoolean("enabled"));
assertFalse(controller.isEnable());
m_controller.reset();
assertFalse(m_table.getBoolean("enabled"));
assertFalse(m_controller.isEnable());
assertEquals(0, me.getMotor().get(), 0);
}
@@ -171,10 +165,11 @@ public class PIDTest extends AbstractComsSetup {
setupAbsoluteTolerance();
setupOutputRange();
Double setpoint = 2500.0;
controller.disable();
controller.setSetpoint(setpoint);
controller.enable();
assertEquals("Did not correctly set set-point", setpoint, new Double(controller.getSetpoint()));
m_controller.disable();
m_controller.setSetpoint(setpoint);
m_controller.enable();
assertEquals("Did not correctly set set-point", setpoint, new Double(m_controller
.getSetpoint()));
}
@Test(timeout = 10000)
@@ -182,26 +177,26 @@ public class PIDTest extends AbstractComsSetup {
setupAbsoluteTolerance();
setupOutputRange();
double setpoint = 1000.0;
assertEquals(pidData() + "did not start at 0", 0, controller.get(), 0);
controller.setSetpoint(setpoint);
assertEquals(pidData() + "did not start at 0", 0, m_controller.get(), 0);
m_controller.setSetpoint(setpoint);
assertEquals(pidData() + "did not have an error of " + setpoint, setpoint,
controller.getError(), 0);
controller.enable();
m_controller.getError(), 0);
m_controller.enable();
Timer.delay(5);
controller.disable();
assertTrue(pidData() + "Was not on Target. Controller Error: " + controller.getError(),
controller.onTarget());
m_controller.disable();
assertTrue(pidData() + "Was not on Target. Controller Error: " + m_controller.getError(),
m_controller.onTarget());
}
private String pidData() {
return me.getType() + " PID {P:" + controller.getP() + " I:" + controller.getI() + " D:"
+ controller.getD() + "} ";
return me.getType() + " PID {P:" + m_controller.getP() + " I:" + m_controller.getI() + " D:"
+ m_controller.getD() + "} ";
}
@Test(expected = RuntimeException.class)
public void testOnTargetNoToleranceSet() {
setupOutputRange();
controller.onTarget();
m_controller.onTarget();
}
}