mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
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:
committed by
Peter Johnson
parent
64ab6e51fe
commit
a834fff7b2
@@ -18,12 +18,10 @@ import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
|
||||
/**
|
||||
* Provides a base implementation for CAN Tests that forces a test of a
|
||||
* particular mode to provide tests of a certain type. This also allows for a
|
||||
* standardized base setup for each test.
|
||||
*$
|
||||
* @author jonathanleitschuh
|
||||
* Provides a base implementation for CAN Tests that forces a test of a particular mode to provide
|
||||
* tests of a certain type. This also allows for a standardized base setup for each test.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
public abstract class AbstractCANTest extends AbstractComsSetup {
|
||||
public static final double kMotorStopTime = 2;
|
||||
@@ -36,27 +34,26 @@ public abstract class AbstractCANTest extends AbstractComsSetup {
|
||||
public static final double kStartupTime = 0.50;
|
||||
public static final double kEncoderPositionTolerance = .75;
|
||||
public static final double kPotentiometerPositionTolerance = 10.0 / 360.0; // +/-10
|
||||
// degrees
|
||||
// degrees
|
||||
public static final double kCurrentTolerance = 0.1;
|
||||
|
||||
|
||||
/**
|
||||
* Stores the status value for the previous test. This is set immediately
|
||||
* after a failure or success and before the me is torn down.
|
||||
* Stores the status value for the previous test. This is set immediately after a failure or
|
||||
* success and before the me is torn down.
|
||||
*/
|
||||
private String status = "";
|
||||
private String m_status = "";
|
||||
|
||||
/**
|
||||
* Extends the default test watcher in order to provide more information about
|
||||
* a tests failure at runtime.
|
||||
*$
|
||||
* @author jonathanleitschuh
|
||||
* Extends the default test watcher in order to provide more information about a tests failure at
|
||||
* runtime.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
public class CANTestWatcher extends DefaultTestWatcher {
|
||||
@Override
|
||||
protected void failed(Throwable e, Description description) {
|
||||
super.failed(e, description, status);
|
||||
protected void failed(Throwable exception, Description description) {
|
||||
super.failed(exception, description, m_status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,27 +62,29 @@ public abstract class AbstractCANTest extends AbstractComsSetup {
|
||||
return new CANTestWatcher();
|
||||
}
|
||||
|
||||
/** The Fixture under test */
|
||||
private CANMotorEncoderFixture me;
|
||||
/**
|
||||
* The Fixture under test.
|
||||
*/
|
||||
private CANMotorEncoderFixture m_me;
|
||||
|
||||
/**
|
||||
* Retrieves the CANMotorEncoderFixture
|
||||
*$
|
||||
* Retrieves the CANMotorEncoderFixture.
|
||||
*
|
||||
* @return the CANMotorEncoderFixture for this test.
|
||||
*/
|
||||
public CANMotorEncoderFixture getME() {
|
||||
return me;
|
||||
return m_me;
|
||||
}
|
||||
|
||||
/**
|
||||
* This runs BEFORE the setup of the inherited class
|
||||
* This runs BEFORE the setup of the inherited class.
|
||||
*/
|
||||
@Before
|
||||
public final void preSetup() {
|
||||
status = "";
|
||||
me = TestBench.getInstance().getCanJaguarPair();
|
||||
me.setup();
|
||||
me.getMotor().setSafetyEnabled(false);
|
||||
m_status = "";
|
||||
m_me = TestBench.getInstance().getCanJaguarPair();
|
||||
m_me.setup();
|
||||
m_me.getMotor().setSafetyEnabled(false);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -93,11 +92,11 @@ public abstract class AbstractCANTest extends AbstractComsSetup {
|
||||
try {
|
||||
// Stores the status data before tearing it down.
|
||||
// If the test fails unexpectedly then this could cause an exception.
|
||||
status = me.printStatus();
|
||||
m_status = m_me.printStatus();
|
||||
} finally {
|
||||
me.teardown();
|
||||
m_me.teardown();
|
||||
}
|
||||
me = null;
|
||||
m_me = null;
|
||||
}
|
||||
|
||||
protected void setCANJaguar(double seconds, double value) {
|
||||
|
||||
@@ -7,20 +7,21 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.Ignore;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
* Tests the CAN Motor Controller in Current Quad Encoder mode.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
public class CANCurrentQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static Logger logger = Logger.getLogger(CANCurrentQuadEncoderModeTest.class.getName());
|
||||
@@ -29,7 +30,7 @@ public class CANCurrentQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#stopMotor()
|
||||
*/
|
||||
protected void stopMotor() {
|
||||
@@ -38,7 +39,7 @@ public class CANCurrentQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
@@ -47,7 +48,7 @@ public class CANCurrentQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
@@ -96,7 +97,8 @@ public class CANCurrentQuadEncoderModeTest extends AbstractCANTest {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
setCANJaguar(1.0, setpoint);
|
||||
|
||||
if (Math.abs(getME().getMotor().getOutputCurrent() - Math.abs(setpoint)) <= kCurrentTolerance) {
|
||||
if (Math.abs(getME().getMotor().getOutputCurrent() - Math.abs(setpoint))
|
||||
<= kCurrentTolerance) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,18 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -14,25 +26,14 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
* The default test set to run against the CAN Motor Controllers.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
public class CANDefaultTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANDefaultTest.class.getName());
|
||||
private final PollingWait wait = new PollingWait().timeoutAfter(65, TimeUnit.MILLISECONDS)
|
||||
private final PollingWait m_wait = new PollingWait().timeoutAfter(65, TimeUnit.MILLISECONDS)
|
||||
.pollEvery(10, TimeUnit.MILLISECONDS);
|
||||
|
||||
private static final double kSpikeTime = .5;
|
||||
@@ -42,9 +43,6 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getME().getMotor().enableControl();
|
||||
@@ -55,17 +53,18 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultGet() {
|
||||
wait.until(new RunnableAssert("Waiting for CAN Jaguar get to return 0") {
|
||||
m_wait.until(new RunnableAssert("Waiting for CAN Jaguar get to return 0") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar did not initialize stopped", 0.0, getME().getMotor().get(), .01f);
|
||||
assertEquals("CAN Jaguar did not initialize stopped", 0.0, getME().getMotor().get(),
|
||||
.01f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBusVoltage() {
|
||||
wait.until(new RunnableAssert("Waiting for default bus voltage to be correct") {
|
||||
m_wait.until(new RunnableAssert("Waiting for default bus voltage to be correct") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar did not start at 14 volts", 14.0f, getME().getMotor()
|
||||
@@ -76,7 +75,7 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultOutputVoltage() {
|
||||
wait.until(new RunnableAssert("Waiting for output voltage to be correct") {
|
||||
m_wait.until(new RunnableAssert("Waiting for output voltage to be correct") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar did not start with an output voltage of 0", 0.0f, getME()
|
||||
@@ -87,7 +86,7 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultOutputCurrent() {
|
||||
wait.until(new RunnableAssert("Waiting for output current to be correct") {
|
||||
m_wait.until(new RunnableAssert("Waiting for output current to be correct") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar did not start with an output current of 0", 0.0f, getME()
|
||||
@@ -99,7 +98,7 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
@Test
|
||||
public void testDefaultTemperature() {
|
||||
final double room_temp = 18.0f;
|
||||
wait.until(new RunnableAssert("Waiting for temperature to be correct") {
|
||||
m_wait.until(new RunnableAssert("Waiting for temperature to be correct") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(
|
||||
@@ -112,11 +111,12 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
@Test
|
||||
public void testDefaultForwardLimit() {
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
wait.until(new RunnableAssert("Waiting for forward limit to not be set") {
|
||||
m_wait.until(new RunnableAssert("Waiting for forward limit to not be set") {
|
||||
@Override
|
||||
public void run() {
|
||||
getME().getMotor().set(0);
|
||||
assertTrue("CAN Jaguar did not start with the Forward Limit Switch Off", getME().getMotor()
|
||||
assertTrue("CAN Jaguar did not start with the Forward Limit Switch Off", getME()
|
||||
.getMotor()
|
||||
.getForwardLimitOK());
|
||||
}
|
||||
});
|
||||
@@ -125,11 +125,12 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
@Test
|
||||
public void testDefaultReverseLimit() {
|
||||
getME().getMotor().configLimitMode(CANJaguar.LimitMode.SwitchInputsOnly);
|
||||
wait.until(new RunnableAssert("Waiting for reverse limit to not be set") {
|
||||
m_wait.until(new RunnableAssert("Waiting for reverse limit to not be set") {
|
||||
@Override
|
||||
public void run() {
|
||||
getME().getMotor().set(0);
|
||||
assertTrue("CAN Jaguar did not start with the Reverse Limit Switch Off", getME().getMotor()
|
||||
assertTrue("CAN Jaguar did not start with the Reverse Limit Switch Off", getME()
|
||||
.getMotor()
|
||||
.getReverseLimitOK());
|
||||
}
|
||||
});
|
||||
@@ -137,7 +138,7 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultNoFaults() {
|
||||
wait.until(new RunnableAssert("Waiting for no faults") {
|
||||
m_wait.until(new RunnableAssert("Waiting for no faults") {
|
||||
@Override
|
||||
public void run() {
|
||||
assertEquals("CAN Jaguar initialized with Faults", 0, getME().getMotor().getFaults());
|
||||
@@ -146,7 +147,6 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testFakeLimitSwitchForwards() {
|
||||
// Given
|
||||
@@ -165,7 +165,8 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
public void run() throws Exception {
|
||||
getME().getMotor().set(0);
|
||||
assertFalse(
|
||||
"Setting the forward limit switch high did not cause the forward limit switch to trigger",
|
||||
"Setting the forward limit switch high did not cause the forward limit switch to "
|
||||
+ "trigger",
|
||||
getME().getMotor().getForwardLimitOK());
|
||||
}
|
||||
});
|
||||
@@ -190,7 +191,8 @@ public class CANDefaultTest extends AbstractCANTest {
|
||||
public void run() throws Exception {
|
||||
getME().getMotor().set(0);
|
||||
assertFalse(
|
||||
"Setting the reverse limit switch high did not cause the forward limit switch to trigger",
|
||||
"Setting the reverse limit switch high did not cause the forward limit switch to "
|
||||
+ "trigger",
|
||||
getME().getMotor().getReverseLimitOK());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,22 +7,27 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by Patrick Murphy on 3/30/15.
|
||||
* Tests the CAN Jaguar inverted.
|
||||
*
|
||||
* <p>Created by Patrick Murphy on 3/30/15.
|
||||
*/
|
||||
public class CANJaguarInversionTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANJaguarInversionTest.class.getName());
|
||||
private static final double motorVoltage = 2.0;
|
||||
private static final double motorPercent = 0.1;
|
||||
private static final double motorSpeed = 10;
|
||||
private static final double delayTime = 0.75;
|
||||
private static final double speedModeDelayTime = 2.0;
|
||||
private static final double m_motorVoltage = 2.0;
|
||||
private static final double m_motorPercent = 0.1;
|
||||
private static final double m_motorSpeed = 10;
|
||||
private static final double m_delayTime = 0.75;
|
||||
private static final double m_speedModeDelayTime = 2.0;
|
||||
|
||||
@Override
|
||||
protected Logger getClassLogger() {
|
||||
@@ -32,54 +37,52 @@ public class CANJaguarInversionTest extends AbstractCANTest {
|
||||
@Test
|
||||
public void testInvertingVoltageMode() {
|
||||
getME().getMotor().setVoltageMode(CANJaguar.kQuadEncoder, 360);
|
||||
InversionTest(motorVoltage, delayTime);
|
||||
inversionTest(m_motorVoltage, m_delayTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvertingPercentMode() {
|
||||
getME().getMotor().setPercentMode(CANJaguar.kQuadEncoder, 360);
|
||||
InversionTest(motorPercent, delayTime);
|
||||
inversionTest(m_motorPercent, m_delayTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvertingSpeedMode() {
|
||||
getME().getMotor().setSpeedMode(CANJaguar.kQuadEncoder, 360, 0.1, 0.003, 0.01);
|
||||
InversionTest(motorSpeed, speedModeDelayTime);
|
||||
inversionTest(m_motorSpeed, m_speedModeDelayTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an inversion test To use set the jaguar to the proper
|
||||
* mode(PercentVbus, voltage, speed)
|
||||
*$
|
||||
* @param setpoint the speed/voltage/percent to set the motor to
|
||||
* @param delayTime the amount of time to delay between starting a motor and
|
||||
* checking the encoder
|
||||
* Runs an inversion test To use set the jaguar to the proper mode(PercentVbus, voltage, speed).
|
||||
*
|
||||
* @param setPoint the speed/voltage/percent to set the motor to
|
||||
* @param delayTime the amount of time to delay between starting a motor and checking the encoder
|
||||
*/
|
||||
private void InversionTest(double setpoint, double delayTime) {
|
||||
CANJaguar jag = this.getME().getMotor();
|
||||
private void inversionTest(double setPoint, double delayTime) {
|
||||
final CANJaguar jag = getME().getMotor();
|
||||
jag.enableControl();
|
||||
jag.setInverted(false);
|
||||
jag.set(setpoint);
|
||||
jag.set(setPoint);
|
||||
Timer.delay(delayTime);
|
||||
double initialSpeed = jag.getSpeed();
|
||||
final double initialSpeed = jag.getSpeed();
|
||||
jag.set(0.0);
|
||||
jag.setInverted(true);
|
||||
jag.set(setpoint);
|
||||
jag.set(setPoint);
|
||||
Timer.delay(delayTime);
|
||||
jag.set(0.0);
|
||||
double finalSpeed = jag.getSpeed();
|
||||
final double finalSpeed = jag.getSpeed();
|
||||
assertTrue("Inverting with Positive value does not invert direction",
|
||||
Math.signum(initialSpeed) != Math.signum(finalSpeed));
|
||||
jag.set(-setpoint);
|
||||
jag.set(-setPoint);
|
||||
Timer.delay(delayTime);
|
||||
initialSpeed = jag.getSpeed();
|
||||
final double newInitialSpeed = jag.getSpeed();
|
||||
jag.set(0.0);
|
||||
jag.setInverted(false);
|
||||
jag.set(-setpoint);
|
||||
jag.set(-setPoint);
|
||||
Timer.delay(delayTime);
|
||||
finalSpeed = jag.getSpeed();
|
||||
final double newFinalSpeed = jag.getSpeed();
|
||||
jag.set(0.0);
|
||||
assertTrue("Inverting with Negative value does not invert direction",
|
||||
Math.signum(initialSpeed) != Math.signum(finalSpeed));
|
||||
Math.signum(newInitialSpeed) != Math.signum(newFinalSpeed));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,20 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
@@ -15,24 +29,12 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
* Tests the CAN motor in PercentQuadEncoderMode.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANPercentQuadEncoderModeTest.class
|
||||
.getName());
|
||||
@@ -41,7 +43,7 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#stopMotor()
|
||||
*/
|
||||
protected void stopMotor() {
|
||||
@@ -50,7 +52,7 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
@@ -59,7 +61,7 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
@@ -148,8 +150,7 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to not rotate forwards when the fake limit
|
||||
* switch is tripped
|
||||
* Test if we can limit the Jaguar to not rotate forwards when the fake limit switch is tripped.
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotRotateForwards_WhenFakeLimitSwitchForwardsIsTripped() {
|
||||
@@ -196,7 +197,7 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
|
||||
/**
|
||||
* Test if we can rotate in reverse when the limit switch
|
||||
* Test if we can rotate in reverse when the limit switch.
|
||||
*/
|
||||
@Test
|
||||
public void shouldRotateReverse_WhenFakeLimitSwitchForwardsIsTripped() {
|
||||
@@ -251,8 +252,7 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can limit the Jaguar to only moving forwards with a fake limit
|
||||
* switch.
|
||||
* Test if we can limit the Jaguar to only moving forwards with a fake limit switch.
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotRotateReverse_WhenFakeLimitSwitchReversesIsTripped() {
|
||||
@@ -301,9 +301,6 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
* Test if we can limit the Jaguar to only moving forwards with a fake limit
|
||||
* switch.
|
||||
*/
|
||||
/**
|
||||
*$
|
||||
*/
|
||||
@Test
|
||||
public void shouldRotateForward_WhenFakeLimitSwitchReversesIsTripped() {
|
||||
// Given
|
||||
@@ -368,7 +365,8 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return Math.abs((getME().getMotor().getPosition() - jagInitialPosition)
|
||||
- (getME().getEncoder().get() - encoderInitialPosition)) < kEncoderPositionTolerance;
|
||||
- (getME().getEncoder().get() - encoderInitialPosition))
|
||||
< kEncoderPositionTolerance;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -391,7 +389,8 @@ public class CANPercentQuadEncoderModeTest extends AbstractCANTest {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return Math.abs((getME().getMotor().getPosition() - jagInitialPosition)
|
||||
- (getME().getEncoder().get() - encoderInitialPosition)) < kEncoderPositionTolerance;
|
||||
- (getME().getEncoder().get() - encoderInitialPosition))
|
||||
< kEncoderPositionTolerance;
|
||||
}
|
||||
});
|
||||
assertEquals(getME().getMotor().getPosition() - jagInitialPosition, getME().getEncoder().get()
|
||||
|
||||
@@ -7,28 +7,29 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
* Tests the CAN Motor controller in Potentiometer Mode.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANPositionPotentiometerModeTest.class
|
||||
@@ -41,7 +42,7 @@ public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#stopMotor()
|
||||
*/
|
||||
protected void stopMotor() {
|
||||
@@ -50,7 +51,7 @@ public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
@@ -59,7 +60,7 @@ public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
@@ -85,13 +86,13 @@ public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
|
||||
|
||||
/**
|
||||
* NOTICE: This is using the {@link MotorEncoderFixture#getEncoder()} instead
|
||||
* of the one built into the CAN Jaguar
|
||||
* NOTICE: This is using the {@link MotorEncoderFixture#getEncoder()} instead of the one built
|
||||
* into the CAN Jaguar.
|
||||
*/
|
||||
@Ignore("Encoder is not yet wired to the FPGA")
|
||||
@Test
|
||||
public void testRotateForward() {
|
||||
int initialPosition = getME().getEncoder().get();
|
||||
final int initialPosition = getME().getEncoder().get();
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
Timer.delay(kMotorTimeSettling);
|
||||
@@ -104,13 +105,13 @@ public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTICE: This is using the {@link MotorEncoderFixture#getEncoder()} instead
|
||||
* of the one built into the CAN Jaguar
|
||||
* NOTICE: This is using the {@link MotorEncoderFixture#getEncoder()} instead of the one built
|
||||
* into the CAN Jaguar.
|
||||
*/
|
||||
@Ignore("Encoder is not yet wired to the FPGA")
|
||||
@Test
|
||||
public void testRotateReverse() {
|
||||
int initialPosition = getME().getEncoder().get();
|
||||
final int initialPosition = getME().getEncoder().get();
|
||||
/* Drive the speed controller briefly to move the encoder */
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
Timer.delay(kMotorTimeSettling);
|
||||
@@ -123,8 +124,8 @@ public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can get a position in potentiometer mode, using an analog output
|
||||
* as a fake potentiometer.
|
||||
* Test if we can get a position in potentiometer mode, using an analog output as a fake
|
||||
* potentiometer.
|
||||
*/
|
||||
@Test
|
||||
public void testFakePotentiometerPosition() {
|
||||
@@ -141,7 +142,8 @@ public class CANPositionPotentiometerModeTest extends AbstractCANTest {
|
||||
public void run() throws Exception {
|
||||
getME().getMotor().set(0);
|
||||
assertEquals(
|
||||
"CAN Jaguar should have returned the potentiometer position set by the analog output",
|
||||
"CAN Jaguar should have returned the potentiometer position set by the analog "
|
||||
+ "output",
|
||||
getME().getFakePot().getVoltage(), getME().getMotor().getPosition() * 3,
|
||||
kPotentiometerPositionTolerance * 3);
|
||||
}
|
||||
|
||||
@@ -7,21 +7,22 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
* Tests the CAN Motor Encoders in QuadEncoder mode.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
public class CANPositionQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANPositionQuadEncoderModeTest.class
|
||||
@@ -35,7 +36,7 @@ public class CANPositionQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
@@ -46,7 +47,7 @@ public class CANPositionQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
@@ -84,8 +85,7 @@ public class CANPositionQuadEncoderModeTest extends AbstractCANTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set a position and reach that position with PID control on
|
||||
* the Jaguar.
|
||||
* Test if we can set a position and reach that position with PID control on the Jaguar.
|
||||
*/
|
||||
@Test
|
||||
public void testEncoderPositionPIDForward() {
|
||||
@@ -101,8 +101,7 @@ public class CANPositionQuadEncoderModeTest extends AbstractCANTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can set a position and reach that position with PID control on
|
||||
* the Jaguar.
|
||||
* Test if we can set a position and reach that position with PID control on the Jaguar.
|
||||
*/
|
||||
@Test
|
||||
public void testEncoderPositionPIDReverse() {
|
||||
|
||||
@@ -7,30 +7,35 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
* Tests the CAN Speed controllers in quad mode.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
public class CANSpeedQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANPercentQuadEncoderModeTest.class
|
||||
.getName());
|
||||
/** The stopped value in rev/min */
|
||||
/**
|
||||
* The stopped value in rev/min.
|
||||
*/
|
||||
private static final double kStoppedValue = 0;
|
||||
/** The running value in rev/min */
|
||||
/**
|
||||
* The running value in rev/min.
|
||||
*/
|
||||
private static final double kRunningValue = 50;
|
||||
|
||||
@Override
|
||||
@@ -49,14 +54,14 @@ public class CANSpeedQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultSpeed() {
|
||||
assertEquals("CAN Jaguar did not start with an initial speed of zero", 0.0f, getME().getMotor()
|
||||
assertEquals("CAN Jaguar did not start with an initial speed of zero", 0.0f, getME()
|
||||
.getMotor()
|
||||
.getSpeed(), 0.3f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor forward in Speed mode and get a position
|
||||
* back
|
||||
* Test if we can drive the motor forward in Speed mode and get a position back.
|
||||
*/
|
||||
@Test
|
||||
public void testRotateForwardSpeed() {
|
||||
@@ -70,8 +75,7 @@ public class CANSpeedQuadEncoderModeTest extends AbstractCANTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if we can drive the motor backwards in Speed mode and get a position
|
||||
* back
|
||||
* Test if we can drive the motor backwards in Speed mode and get a position back.
|
||||
*/
|
||||
@Test
|
||||
public void testRotateReverseSpeed() {
|
||||
@@ -80,7 +84,8 @@ public class CANSpeedQuadEncoderModeTest extends AbstractCANTest {
|
||||
setCANJaguar(2 * kMotorTime, speed);
|
||||
assertEquals("The motor did not reach the required speed in speed mode", speed, getME()
|
||||
.getMotor().getSpeed(), kEncoderSpeedTolerance);
|
||||
assertThat("The motor did not move in reverse in speed mode", getME().getMotor().getPosition(),
|
||||
assertThat("The motor did not move in reverse in speed mode", getME().getMotor()
|
||||
.getPosition(),
|
||||
is(lessThan(initialPosition)));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,9 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
import edu.wpi.first.wpilibj.test.AbstractTestSuite;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
* All of the tests to cover the CAN Motor Controllers.
|
||||
*
|
||||
* @author jonathanleitschuh
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({CANCurrentQuadEncoderModeTest.class, CANDefaultTest.class,
|
||||
|
||||
@@ -7,34 +7,39 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.googlecode.junittoolbox.PollingWait;
|
||||
import com.googlecode.junittoolbox.RunnableAssert;
|
||||
|
||||
import edu.wpi.first.wpilibj.CANJaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* @author jonathanleitschuh
|
||||
* Tests the CAN motor controllers in voltage mode work correctly.
|
||||
*
|
||||
* @author Jonathan Leitschuh
|
||||
*/
|
||||
public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
private static final Logger logger = Logger.getLogger(CANVoltageQuadEncoderModeTest.class
|
||||
.getName());
|
||||
/** The stopped value in volts */
|
||||
/**
|
||||
* The stopped value in volts.
|
||||
*/
|
||||
private static final double kStoppedValue = 0;
|
||||
/** The running value in volts */
|
||||
/**
|
||||
* The running value in volts.
|
||||
*/
|
||||
private static final double kRunningValue = 4;
|
||||
|
||||
private static final double kVoltageTolerance = .25;
|
||||
@@ -44,7 +49,7 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#stopMotor()
|
||||
*/
|
||||
protected void stopMotor() {
|
||||
@@ -53,7 +58,7 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorForward()
|
||||
*/
|
||||
protected void runMotorForward() {
|
||||
@@ -62,7 +67,7 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*$
|
||||
*
|
||||
* @see edu.wpi.first.wpilibj.can.AbstractCANTest#runMotorReverse()
|
||||
*/
|
||||
protected void runMotorReverse() {
|
||||
@@ -74,8 +79,11 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
getME().getMotor().setVoltageMode(CANJaguar.kQuadEncoder, 360);
|
||||
getME().getMotor().set(kStoppedValue);
|
||||
getME().getMotor().enableControl();
|
||||
@@ -100,11 +108,10 @@ public class CANVoltageQuadEncoderModeTest extends AbstractCANTest {
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the test to have the CANJaguar running at the target voltage
|
||||
*$
|
||||
* Sets up the test to have the CANJaguar running at the target voltage.
|
||||
*
|
||||
* @param targetValue the target voltage
|
||||
* @param wait the PollingWait to to use to wait for the setup to complete
|
||||
* with
|
||||
* @param wait the PollingWait to to use to wait for the setup to complete with
|
||||
*/
|
||||
private void setupMotorVoltageForTest(final double targetValue, PollingWait wait) {
|
||||
getME().getMotor().enableControl();
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
/**
|
||||
* Provides a suite of tests to cover CANJaguar fully in all different control
|
||||
* modes and with each supported positional input. Different setup parameters
|
||||
* are provided in each Test class. All test classes that want to take advantage
|
||||
* of the default test setup frameworks in place should extend
|
||||
* {@link edu.wpi.first.wpilibj.can.AbstractCANTest AbstractCANTest}
|
||||
*$
|
||||
* Provides a suite of tests to cover CANJaguar fully in all different control modes and with each
|
||||
* supported positional input. Different setup parameters are provided in each Test class. All test
|
||||
* classes that want to take advantage of the default test setup frameworks in place should extend
|
||||
* {@link edu.wpi.first.wpilibj.can.AbstractCANTest AbstractCANTest}.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
Reference in New Issue
Block a user