WPILib Reorganization

This is a major restructuring of the WPILib repository to simply build
procedures and remove the remnants of Maven from everything except the
eclipse plugins. Gradle files have been largely simplified or rewritten,
taking advantage of splitting up parts of the build into separate build
files for ease of reading.

The eclipse plugins are now in a separate project, as is ntcore. All
dependencies are resolved via Maven dependencies, with the
Jenkins-maintained WPILib repo. Project structures have also been
simplified: we no longer have separate subprojects inside wpilibc and
wpilibj. Where possible, these changes hav been done with git renames,
to make sure we still have full history for all repositories. Other
unrelated subprojects have also been broken out: OutlineViewer is now a
separate project.

Change-Id: Ib4e2a6e1a2f66427a14f16612b0e0d69ed661878
This commit is contained in:
Fredric Silberberg
2015-09-24 20:26:49 -04:00
parent c20d34c2b6
commit 6d854afb0e
1769 changed files with 2278 additions and 333177 deletions

View File

@@ -0,0 +1,86 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj.AnalogOutput;
/**
* @author jonathanleitschuh
*
*/
public abstract class AnalogCrossConnectFixture implements ITestFixture {
private boolean initialized = false;
private AnalogInput input;
private AnalogOutput output;
abstract protected AnalogInput giveAnalogInput();
abstract protected AnalogOutput giveAnalogOutput();
private void initialize() {
synchronized (this) {
if (!initialized) {
input = giveAnalogInput();
output = giveAnalogOutput();
initialized = true;
}
}
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#setup()
*/
@Override
public boolean setup() {
initialize();
output.setVoltage(0);
return true;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#reset()
*/
@Override
public boolean reset() {
initialize();
return true;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#teardown()
*/
@Override
public boolean teardown() {
input.free();
output.free();
return true;
}
/**
* @return
*/
final public AnalogOutput getOutput() {
initialize();
return output;
}
final public AnalogInput getInput() {
initialize();
return input;
}
}

View File

@@ -0,0 +1,185 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import java.util.logging.Logger;
import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.DigitalOutput;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Relay.Direction;
import edu.wpi.first.wpilibj.Relay.Value;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.mockhardware.FakePotentiometerSource;
/**
* @author jonathanleitschuh
*
*/
public abstract class CANMotorEncoderFixture extends MotorEncoderFixture<CANJaguar> implements
ITestFixture {
private static final Logger logger = Logger.getLogger(CANMotorEncoderFixture.class.getName());
public static final double RELAY_POWER_UP_TIME = .75;
private FakePotentiometerSource potSource;
private DigitalOutput forwardLimit;
private DigitalOutput reverseLimit;
private Relay powerCycler;
private boolean initialized = false;
protected abstract FakePotentiometerSource giveFakePotentiometerSource();
protected abstract DigitalOutput giveFakeForwardLimit();
protected abstract DigitalOutput giveFakeReverseLimit();
protected abstract Relay givePoweCycleRelay();
public CANMotorEncoderFixture() {}
private void initialize() {
synchronized (this) {
if (!initialized) {
initialized = true;// This ensures it is only initialized once
powerCycler = givePoweCycleRelay();
powerCycler.setDirection(Direction.kForward);
logger.fine("Turning on the power!");
powerCycler.set(Value.kForward);
forwardLimit = giveFakeForwardLimit();
reverseLimit = giveFakeReverseLimit();
forwardLimit.set(false);
reverseLimit.set(false);
potSource = giveFakePotentiometerSource();
Timer.delay(RELAY_POWER_UP_TIME); // Delay so the relay has time to boot
// up
}
}
}
@Override
public boolean setup() {
initialize(); // This initializes the Relay first
return super.setup();
}
@Override
public boolean reset() {
initialize();
potSource.reset();
forwardLimit.set(false);
reverseLimit.set(false);
getMotor().setPercentMode(); // Get the Jaguar into a mode where setting the
// speed means stop
return super.reset();
}
@Override
public boolean teardown() {
boolean wasNull = false;
if (potSource != null) {
potSource.free();
potSource = null;
} else
wasNull = true;
if (forwardLimit != null) {
forwardLimit.set(false);
forwardLimit.free();
forwardLimit = null;
} else
wasNull = true;
if (reverseLimit != null) {
reverseLimit.set(false);
reverseLimit.free();
reverseLimit = null;
} else
wasNull = true;
boolean superTornDown = false;
try {
superTornDown = super.teardown();
} finally {
try {
if (getMotor() != null) {
getMotor().disableControl();
getMotor().free();
} else
wasNull = true;
} finally {
if (powerCycler != null) {
powerCycler.free();
powerCycler = null;
} else
wasNull = true;
}
}
if (wasNull) {
throw new RuntimeException("CANMotorEncoderFixture had a null value at teardown");
}
return superTornDown;
}
public FakePotentiometerSource getFakePot() {
initialize();
return potSource;
}
public DigitalOutput getForwardLimit() {
initialize();
return forwardLimit;
}
public DigitalOutput getReverseLimit() {
initialize();
return reverseLimit;
}
public String printStatus() {
StringBuilder status = new StringBuilder("CAN Motor Encoder Status: ");
if (getMotor() != null) {
status.append("\t" + getMotor().getDescription() + "\n");
status.append("\tFault = " + getMotor().getFaults() + "\n");
status.append("\tValue = " + getMotor().get() + "\n");
status.append("\tOutputVoltage = " + getMotor().getOutputVoltage() + "\n");
status.append("\tPosition = " + getMotor().getPosition() + "\n");
status.append("\tForward Limit Ok = " + getMotor().getForwardLimitOK() + "\n");
status.append("\tReverse Limit Ok = " + getMotor().getReverseLimitOK() + "\n");
} else {
status.append("\t" + "CANJaguar Motor = null" + "\n");
}
if (forwardLimit != null) {
status.append("\tForward Limit Output = " + forwardLimit + "\n");
} else {
status.append("\tForward Limit Output = null" + "\n");
}
if (reverseLimit != null) {
status.append("\tReverse Limit Output = " + reverseLimit + "\n");
} else {
status.append("\tReverse Limit Output = null" + "\n");
}
return status.toString();
}
public void brownOut(double seconds) {
initialize();
powerOff();
Timer.delay(seconds);
powerOn();
}
public void powerOff() {
initialize();
powerCycler.set(Value.kOff);
}
public void powerOn() {
initialize();
powerCycler.set(Value.kForward);
}
}

View File

@@ -0,0 +1,75 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import java.util.logging.Level;
import java.util.logging.Logger;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DigitalOutput;
public class DIOCrossConnectFixture implements ITestFixture {
private static final Logger logger = Logger.getLogger(DIOCrossConnectFixture.class.getName());
private final DigitalInput input;
private final DigitalOutput output;
private boolean m_allocated;
public DIOCrossConnectFixture(DigitalInput input, DigitalOutput output) {
assert input != null;
assert output != null;
this.input = input;
this.output = output;
m_allocated = false;
}
public DIOCrossConnectFixture(Integer input, Integer output) {
assert input != null;
assert output != null;
assert !input.equals(output);
this.input = new DigitalInput(input);
this.output = new DigitalOutput(output);
m_allocated = true;
}
public DigitalInput getInput() {
return input;
}
public DigitalOutput getOutput() {
return output;
}
@Override
public boolean setup() {
return true;
}
@Override
public boolean reset() {
try {
input.cancelInterrupts();
} catch (IllegalStateException e) {
// This will happen if the interrupt has not been allocated for this test.
}
output.set(false);
return true;
}
@Override
public boolean teardown() {
logger.log(Level.FINE, "Begining teardown");
if (m_allocated) {
input.free();
output.free();
m_allocated = false;
}
return true;
}
}

View File

@@ -0,0 +1,114 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import java.util.logging.Level;
import java.util.logging.Logger;
import edu.wpi.first.wpilibj.Counter;
import edu.wpi.first.wpilibj.mockhardware.FakeCounterSource;
/**
* @author jonathanleitschuh
*
*/
public class FakeCounterFixture implements ITestFixture {
private static final Logger logger = Logger.getLogger(FakeEncoderFixture.class.getName());
private final DIOCrossConnectFixture dio;
private boolean m_allocated;
private final FakeCounterSource source;
private final Counter counter;
/**
* Constructs a FakeCounterFixture.
*$
* @param dio A previously allocated DIOCrossConnectFixture (must be freed
* outside this class)
*/
public FakeCounterFixture(DIOCrossConnectFixture dio) {
this.dio = dio;
m_allocated = false;
source = new FakeCounterSource(dio.getOutput());
counter = new Counter(dio.getInput());
}
/**
* Constructs a FakeCounterFixture using two port numbers
*$
* @param input the input port
* @param output the output port
*/
public FakeCounterFixture(int input, int output) {
this.dio = new DIOCrossConnectFixture(input, output);
m_allocated = true;
source = new FakeCounterSource(dio.getOutput());
counter = new Counter(dio.getInput());
}
/**
* Retrieves the FakeCouterSource for use
*$
* @return the FakeCounterSource
*/
public FakeCounterSource getFakeCounterSource() {
return source;
}
/**
* Gets the Counter for use
*$
* @return the Counter
*/
public Counter getCounter() {
return counter;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#setup()
*/
@Override
public boolean setup() {
return true;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#reset()
*/
@Override
public boolean reset() {
counter.reset();
return true;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#teardown()
*/
@Override
public boolean teardown() {
logger.log(Level.FINE, "Begining teardown");
counter.free();
source.free();
if (m_allocated) { // Only tear down the dio if this class allocated it
dio.teardown();
m_allocated = false;
}
return true;
}
}

View File

@@ -0,0 +1,124 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import java.util.logging.Level;
import java.util.logging.Logger;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.mockhardware.FakeEncoderSource;
/**
* @author jonathanleitschuh
*
*/
public class FakeEncoderFixture implements ITestFixture {
private static final Logger logger = Logger.getLogger(FakeEncoderFixture.class.getName());
private final DIOCrossConnectFixture m_dio1;
private final DIOCrossConnectFixture m_dio2;
private boolean m_allocated;
private final FakeEncoderSource m_source;
private int m_sourcePort[] = new int[2];
private final Encoder m_encoder;
private int m_encoderPort[] = new int[2];
/**
* Constructs a FakeEncoderFixture from two DIOCrossConnectFixture
*$
* @param dio1
* @param dio2
*/
public FakeEncoderFixture(DIOCrossConnectFixture dio1, DIOCrossConnectFixture dio2) {
assert dio1 != null;
assert dio2 != null;
this.m_dio1 = dio1;
this.m_dio2 = dio2;
m_allocated = false;
m_source = new FakeEncoderSource(dio1.getOutput(), dio2.getOutput());
m_encoder = new Encoder(dio1.getInput(), dio2.getOutput());
}
/**
* Construcst a FakeEncoderFixture from a set of Digital I/O ports
*$
* @param inputA
* @param outputA
* @param inputB
* @param outputB
*/
public FakeEncoderFixture(int inputA, int outputA, int inputB, int outputB) {
assert outputA != outputB;
assert outputA != inputA;
assert outputA != inputB;
assert outputB != inputA;
assert outputB != inputB;
assert inputA != inputB;
this.m_dio1 = new DIOCrossConnectFixture(inputA, outputA);
this.m_dio2 = new DIOCrossConnectFixture(inputB, outputB);
m_allocated = true;
m_sourcePort[0] = outputA;
m_sourcePort[1] = outputB;
m_encoderPort[0] = inputA;
m_encoderPort[1] = inputB;
m_source = new FakeEncoderSource(m_dio1.getOutput(), m_dio2.getOutput());
m_encoder = new Encoder(m_dio1.getInput(), m_dio2.getOutput());
}
public FakeEncoderSource getFakeEncoderSource() {
return m_source;
}
public Encoder getEncoder() {
return m_encoder;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#setup()
*/
@Override
public boolean setup() {
return true;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#reset()
*/
@Override
public boolean reset() {
m_dio1.reset();
m_dio2.reset();
m_encoder.reset();
return true;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#teardown()
*/
@Override
public boolean teardown() {
logger.fine("Begining teardown");
m_source.free();
logger.finer("Source freed " + m_sourcePort[0] + ", " + m_sourcePort[1]);
m_encoder.free();
logger.finer("Encoder freed " + m_encoderPort[0] + ", " + m_encoderPort[1]);
if (m_allocated) {
m_dio1.teardown();
m_dio2.teardown();
}
return true;
}
}

View File

@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import edu.wpi.first.wpilibj.test.TestBench;
/**
* Master interface for all test fixtures. This ensures that all test fixtures
* have setup and teardown methods, to ensure that the tests run properly.
*$
* Test fixtures should be modeled around the content of a test, rather than the
* actual physical layout of the testing board. They should obtain references to
* hardware from the {@link TestBench} class, which is a singleton. Testing
* Fixtures are responsible for ensuring that the hardware is in an appropriate
* state for the start of a test, and ensuring that future tests will not be
* affected by the results of a test.
*$
* @author Fredric Silberberg
*/
public interface ITestFixture {
/**
* Performs any required setup for this fixture, ensuring that all fixture
* elements are ready for testing.
*$
* @return True if the fixture is ready for testing
*/
boolean setup();
/**
* Resets the fixture back to test start state. This should be called by the
* test class in the test setup method to ensure that the hardware is in the
* default state. This differs from {@link ITestFixture#setup()} as that is
* called once, before the class is constructed, so it may need to start
* sensors. This method should not have to start anything, just reset sensors
* and ensure that motors are stopped.
*$
* @return True if the fixture is ready for testing
*/
boolean reset();
/**
* Performs any required teardown after use of the fixture, ensuring that
* future tests will not run into conflicts.
*$
* @return True if the teardown succeeded
*/
boolean teardown();
}

View File

@@ -0,0 +1,242 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import java.lang.reflect.ParameterizedType;
import java.util.logging.Logger;
import edu.wpi.first.wpilibj.Counter;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.test.TestBench;
/**
* Represents a physically connected Motor and Encoder to allow for unit tests
* on these difrent pairs<br>
* Designed to allow the user to easily setup and tear down the fixture to allow
* for reuse. This class should be explicitly instantiated in the TestBed class
* to allow any test to access this fixture. This allows tests to be mailable so
* that you can easily reconfigure the physical testbed without breaking the
* tests.
*
* @author Jonathan Leitschuh
*
*/
public abstract class MotorEncoderFixture<T extends SpeedController> implements ITestFixture {
private static final Logger logger = Logger.getLogger(MotorEncoderFixture.class.getName());
private boolean initialized = false;
private boolean tornDown = false;
protected T motor;
private Encoder encoder;
private final Counter counters[] = new Counter[2];
protected DigitalInput aSource; // Stored so it can be freed at tear down
protected DigitalInput bSource;
/**
* Default constructor for a MotorEncoderFixture
*/
public MotorEncoderFixture() {}
abstract public int getPDPChannel();
/**
* Where the implementer of this class should pass the speed controller
* Constructor should only be called from outside this class if the Speed
* controller is not also an implementation of PWM interface
*$
* @return
*/
abstract protected T giveSpeedController();
/**
* Where the implementer of this class should pass one of the digital inputs<br>
* CONSTRUCTOR SHOULD NOT BE CALLED FROM OUTSIDE THIS CLASS!
*$
* @return
*/
abstract protected DigitalInput giveDigitalInputA();
/**
* Where the implementer fo this class should pass the other digital input<br>
* CONSTRUCTOR SHOULD NOT BE CALLED FROM OUTSIDE THIS CLASS!
*$
* @return Input B to be used when this class is instantiated
*/
abstract protected DigitalInput giveDigitalInputB();
final private void initialize() {
synchronized (this) {
if (!initialized) {
initialized = true; // This ensures it is only initialized once
aSource = giveDigitalInputA();
bSource = giveDigitalInputB();
encoder = new Encoder(aSource, bSource);
counters[0] = new Counter(aSource);
counters[1] = new Counter(bSource);
logger.fine("Creating the speed controller!");
motor = giveSpeedController(); // CANJaguar throws an exception if it
// doesn't get the message
}
}
}
@Override
public boolean setup() {
initialize();
return true;
}
/**
* Gets the motor for this Object
*$
* @return the motor this object refers too
*/
public T getMotor() {
initialize();
return motor;
}
/**
* Gets the encoder for this object
*$
* @return the encoder that this object refers too
*/
public Encoder getEncoder() {
initialize();
return encoder;
}
public Counter[] getCounters() {
initialize();
return counters;
}
/**
* Retrieves the name of the motor that this object refers to
*$
* @return The simple name of the motor {@link Class#getSimpleName()}
*/
public String getType() {
initialize();
return motor.getClass().getSimpleName();
}
/**
* Checks to see if the speed of the motor is within some range of a given
* value. This is used instead of equals() because doubles can have
* inaccuracies.
*$
* @param value The value to compare against
* @param accuracy The accuracy range to check against to see if the
* @return true if the range of values between motors speed accuracy contains
* the 'value'.
*/
public boolean isMotorSpeedWithinRange(double value, double accuracy) {
initialize();
return Math.abs((Math.abs(motor.get()) - Math.abs(value))) < Math.abs(accuracy);
}
@Override
public boolean reset() {
initialize();
boolean wasReset = true;
motor.setInverted(false);
motor.set(0);
Timer.delay(TestBench.MOTOR_STOP_TIME); // DEFINED IN THE TestBench
encoder.reset();
for (Counter c : counters) {
c.reset();
}
wasReset = wasReset && motor.get() == 0;
wasReset = wasReset && encoder.get() == 0;
for (Counter c : counters) {
wasReset = wasReset && c.get() == 0;
}
return wasReset;
}
/**
* Safely tears down the MotorEncoder Fixture in a way that makes sure that
* even if an object fails to initialize the reset of the fixture can still be
* torn down and the resources deallocated
*/
@Override
public boolean teardown() {
String type;
if (motor != null) {
type = getType();
} else {
type = "null";
}
if (!tornDown) {
boolean wasNull = false;
if (motor instanceof PWM && motor != null) {
((PWM) motor).free();
motor = null;
} else if (motor == null)
wasNull = true;
if (encoder != null) {
encoder.free();
encoder = null;
} else
wasNull = true;
if (counters[0] != null) {
counters[0].free();
counters[0] = null;
} else
wasNull = true;
if (counters[1] != null) {
counters[1].free();
counters[1] = null;
} else
wasNull = true;
if (aSource != null) {
aSource.free();
aSource = null;
} else
wasNull = true;
if (bSource != null) {
bSource.free();
bSource = null;
} else
wasNull = true;
tornDown = true;
if (wasNull) {
throw new NullPointerException("MotorEncoderFixture had null params at teardown");
}
} else {
throw new RuntimeException(type + " Motor Encoder torn down multiple times");
}
return true;
}
@Override
public String toString() {
StringBuilder string = new StringBuilder("MotorEncoderFixture<");
// Get the generic type as a class
@SuppressWarnings("unchecked")
Class<T> class1 =
(Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
string.append(class1.getSimpleName());
string.append(">");
return string.toString();
}
}

View File

@@ -0,0 +1,101 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Relay.Direction;
import edu.wpi.first.wpilibj.Relay.Value;
/**
* @author jonathanleitschuh
*
*/
public abstract class RelayCrossConnectFixture implements ITestFixture {
private DigitalInput inputOne;
private DigitalInput inputTwo;
private Relay relay;
private boolean initialized = false;
private boolean freed = false;
protected abstract Relay giveRelay();
protected abstract DigitalInput giveInputOne();
protected abstract DigitalInput giveInputTwo();
private void initialize() {
synchronized (this) {
if (!initialized) {
relay = giveRelay();
inputOne = giveInputOne();
inputTwo = giveInputTwo();
initialized = true;
}
}
}
public Relay getRelay() {
initialize();
return relay;
}
public DigitalInput getInputOne() {
initialize();
return inputOne;
}
public DigitalInput getInputTwo() {
initialize();
return inputTwo;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#setup()
*/
@Override
public boolean setup() {
initialize();
return true;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#reset()
*/
@Override
public boolean reset() {
initialize();
return true;
}
/*
* (non-Javadoc)
*$
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#teardown()
*/
@Override
public boolean teardown() {
if (!freed) {
relay.free();
inputOne.free();
inputTwo.free();
freed = true;
} else {
throw new RuntimeException("You attempted to free the "
+ RelayCrossConnectFixture.class.getSimpleName() + " multiple times");
}
return true;
}
}

View File

@@ -0,0 +1,57 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
/**
* This is an example of how to use the {@link ITestFixture} interface to create
* test fixtures for a test.
*$
* @author Fredric Silberberg
*$
*/
public class SampleFixture implements ITestFixture {
/**
* {@inheritDoc}
*/
@Override
public boolean setup() {
/*
* If this fixture actually accessed the hardware, here is where it would
* set up the starting state of the test bench. For example, reseting
* encoders, ensuring motors are stopped, reseting any serial communication
* if necessary, etc.
*/
return true;
}
@Override
public boolean reset() {
/*
* This is where the fixture would reset any sensors or motors used by the
* fixture to test default state. This method should not worry about whether
* or not the sensors have been allocated correctly, that is the job of the
* setup function.
*/
return false;
}
/**
* {@inheritDoc}
*/
@Override
public boolean teardown() {
/*
* This is where the fixture would deallocate and reset back to normal
* conditions any necessary hardware. This includes ensuring motors are
* stopped, stoppable sensors are actually stopped, ensuring serial
* communications are ready for the next test, etc.
*/
return true;
}
}

View File

@@ -0,0 +1,91 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.fixtures;
import java.util.logging.Logger;
import edu.wpi.first.wpilibj.interfaces.Gyro;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.Timer;
/**
* A class to represent the a physical Camera with two servos (tilt and pan)
* designed to test to see if the gyroscope is operating normally.
*
* @author Jonathan Leitschuh
*
*/
public abstract class TiltPanCameraFixture implements ITestFixture {
public static final Logger logger = Logger.getLogger(TiltPanCameraFixture.class.getName());
public static final double RESET_TIME = 2.0;
private Gyro gyro;
private Servo tilt;
private Servo pan;
private boolean initialized = false;
protected abstract Gyro giveGyro();
protected abstract Servo giveTilt();
protected abstract Servo givePan();
/**
* Constructs the TiltPanCamera
*/
public TiltPanCameraFixture() {}
@Override
public boolean setup() {
boolean wasSetup = false;
if (!initialized) {
initialized = true;
tilt = giveTilt();
tilt.set(0);
pan = givePan();
pan.set(0);
Timer.delay(RESET_TIME);
logger.fine("Initializing the gyro");
gyro = giveGyro();
gyro.reset();
wasSetup = true;
}
return wasSetup;
}
@Override
public boolean reset() {
gyro.reset();
return true;
}
public Servo getTilt() {
return tilt;
}
public Servo getPan() {
return pan;
}
public Gyro getGyro() {
return gyro;
}
@Override
public boolean teardown() {
tilt.free();
tilt = null;
pan.free();
pan = null;
gyro.free();
gyro = null;
return true;
}
}