mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Initial checkin of unified hierarchy of WPILib 2015
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brad
|
||||
*/
|
||||
public class DIOCrossConnect {
|
||||
|
||||
/**
|
||||
* Cross connected Digital I/O lines.
|
||||
* The A1, B1, C1, and D1 are digital module 1 and
|
||||
* A2, B2, C2, and D2 are digital module 2
|
||||
*/
|
||||
public static final int DIOCrossConnectA1 = 8;
|
||||
public static final int DIOCrossConnectA2 = 11;
|
||||
public static final int DIOCrossConnectB1 = 9;
|
||||
public static final int DIOCrossConnectB2 = 10;
|
||||
public static final int DIOCrossConnectC1 = 10;
|
||||
public static final int DIOCrossConnectC2 = 9;
|
||||
public static final int DIOCrossConnectD1 = 11;
|
||||
public static final int DIOCrossConnectD2 = 8;
|
||||
|
||||
public static DigitalOutput getOutputA() {
|
||||
return new DigitalOutput(DIOCrossConnectA1);
|
||||
}
|
||||
|
||||
public static DigitalInput getInputA() {
|
||||
return new DigitalInput(2, DIOCrossConnectA2);
|
||||
}
|
||||
|
||||
public static DigitalOutput getOutputB() {
|
||||
return new DigitalOutput(DIOCrossConnectB1);
|
||||
}
|
||||
|
||||
public static DigitalInput getInputB() {
|
||||
return new DigitalInput(2, DIOCrossConnectB2);
|
||||
}
|
||||
|
||||
public static DigitalOutput getOutputC() {
|
||||
return new DigitalOutput(DIOCrossConnectC1);
|
||||
}
|
||||
|
||||
public static DigitalInput getInputC() {
|
||||
return new DigitalInput(2, DIOCrossConnectC2);
|
||||
}
|
||||
|
||||
public static DigitalOutput getOutputD() {
|
||||
return new DigitalOutput(DIOCrossConnectD1);
|
||||
}
|
||||
|
||||
public static DigitalInput getInputD() {
|
||||
return new DigitalInput(2, DIOCrossConnectD2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. 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 Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* @file FakeCounterSource.java
|
||||
* Simulates an encoder for testing purposes
|
||||
* @author Ryan O'Meara
|
||||
*/
|
||||
public class FakeCounterSource
|
||||
{
|
||||
|
||||
private Thread m_task;
|
||||
private int m_count;
|
||||
private int m_mSec;
|
||||
private DigitalOutput m_output;
|
||||
|
||||
/**
|
||||
* Thread object that allows emulation of an encoder
|
||||
*/
|
||||
private class EncoderThread extends Thread
|
||||
{
|
||||
|
||||
FakeCounterSource m_encoder;
|
||||
|
||||
EncoderThread(FakeCounterSource encode)
|
||||
{
|
||||
m_encoder = encode;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
m_encoder.m_output.set(false);
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < m_encoder.m_count; i++)
|
||||
{
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
m_encoder.m_output.set(true);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
m_encoder.m_output.set(false);
|
||||
}
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fake encoder on a given port
|
||||
* @param port The port the encoder is supposed to be on
|
||||
*/
|
||||
public FakeCounterSource(int port)
|
||||
{
|
||||
m_output = new DigitalOutput(port);
|
||||
initEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new fake encoder on the indicated slot and port
|
||||
* @param slot Slot to create on
|
||||
* @param port THe port that the encoder is supposably on
|
||||
*/
|
||||
public FakeCounterSource(int slot, int port)
|
||||
{
|
||||
m_output = new DigitalOutput(slot, port);
|
||||
initEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Object with minimum memory leak
|
||||
*/
|
||||
public void free()
|
||||
{
|
||||
m_task = null;
|
||||
m_output.free();
|
||||
}
|
||||
|
||||
/**
|
||||
* Common initailization code
|
||||
*/
|
||||
private void initEncoder()
|
||||
{
|
||||
m_mSec = 1;
|
||||
m_task = new EncoderThread(this);
|
||||
m_output.set(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the thread execution task
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
m_task.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the thread to complete
|
||||
*/
|
||||
public void complete()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_task.join();
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
m_task = new EncoderThread(this);
|
||||
Timer.delay(.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts and completes a task set - does not return until thred has finished
|
||||
* its operations
|
||||
*/
|
||||
public void execute()
|
||||
{
|
||||
start();
|
||||
complete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the count to run encoder
|
||||
* @param count The count to emulate to the controller
|
||||
*/
|
||||
public void setCount(int count)
|
||||
{
|
||||
m_count = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the rate to send pulses
|
||||
* @param mSec The rate to send out pulses at
|
||||
*/
|
||||
public void setRate(int mSec)
|
||||
{
|
||||
m_mSec = mSec;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. 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 Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* @file FakeEncoderSource.java
|
||||
* Emulates a quadrature encoder
|
||||
* @author Ryan O'Meara
|
||||
*/
|
||||
public class FakeEncoderSource
|
||||
{
|
||||
|
||||
private Thread m_task;
|
||||
private int m_count;
|
||||
private int m_mSec;
|
||||
private boolean m_forward;
|
||||
private DigitalOutput m_outputA, m_outputB;
|
||||
private boolean allocatedOutputs;
|
||||
|
||||
/**
|
||||
* Thread object that allows emulation of a quadrature encoder
|
||||
*/
|
||||
private class QuadEncoderThread extends Thread
|
||||
{
|
||||
|
||||
FakeEncoderSource m_encoder;
|
||||
|
||||
QuadEncoderThread(FakeEncoderSource encode)
|
||||
{
|
||||
m_encoder = encode;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
|
||||
DigitalOutput lead, lag;
|
||||
|
||||
m_encoder.m_outputA.set(false);
|
||||
m_encoder.m_outputB.set(false);
|
||||
|
||||
if (m_encoder.isForward())
|
||||
{
|
||||
lead = m_encoder.m_outputA;
|
||||
lag = m_encoder.m_outputB;
|
||||
} else
|
||||
{
|
||||
lead = m_encoder.m_outputB;
|
||||
lag = m_encoder.m_outputA;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < m_encoder.m_count; i++)
|
||||
{
|
||||
lead.set(true);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
lag.set(true);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
lead.set(false);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
lag.set(false);
|
||||
Thread.sleep(m_encoder.m_mSec);
|
||||
}
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FakeEncoderSource(int slotA, int portA, int slotB, int portB)
|
||||
{
|
||||
m_outputA = new DigitalOutput(slotA, portA);
|
||||
m_outputB = new DigitalOutput(slotB, portB);
|
||||
allocatedOutputs = true;
|
||||
initQuadEncoder();
|
||||
}
|
||||
|
||||
public FakeEncoderSource(int portA, int portB)
|
||||
{
|
||||
m_outputA = new DigitalOutput(portA);
|
||||
m_outputB = new DigitalOutput(portB);
|
||||
allocatedOutputs = true;
|
||||
initQuadEncoder();
|
||||
}
|
||||
|
||||
public FakeEncoderSource(DigitalOutput iA, DigitalOutput iB)
|
||||
{
|
||||
m_outputA = iA;
|
||||
m_outputB = iB;
|
||||
allocatedOutputs = false;
|
||||
initQuadEncoder();
|
||||
}
|
||||
|
||||
public void free()
|
||||
{
|
||||
m_task = null;
|
||||
if (allocatedOutputs) {
|
||||
m_outputA.free();
|
||||
m_outputB.free();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Common initialization code
|
||||
*/
|
||||
private void initQuadEncoder()
|
||||
{
|
||||
m_mSec = 1;
|
||||
m_forward = true;
|
||||
m_task = new QuadEncoderThread(this);
|
||||
m_outputA.set(false);
|
||||
m_outputB.set(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the thread
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
m_task.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for thread to end
|
||||
*/
|
||||
public void complete()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_task.join();
|
||||
} catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
m_task = new QuadEncoderThread(this);
|
||||
Timer.delay(.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs and waits for thread to end before returning
|
||||
*/
|
||||
public void execute()
|
||||
{
|
||||
start();
|
||||
complete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rate of pulses to send
|
||||
* @param mSec Pulse Rate
|
||||
*/
|
||||
public void setRate(int mSec)
|
||||
{
|
||||
m_mSec = mSec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of pulses to simulate
|
||||
* @param count Pulse count
|
||||
*/
|
||||
public void setCount(int count)
|
||||
{
|
||||
m_count = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which direction the encoder simulates motion in
|
||||
* @param isForward Whether to simulate forward motion
|
||||
*/
|
||||
public void setForward(boolean isForward)
|
||||
{
|
||||
m_forward = isForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accesses whether the encoder is simulating forward motion
|
||||
* @return Whether the simulated motion is in the forward direction
|
||||
*/
|
||||
public boolean isForward()
|
||||
{
|
||||
return m_forward;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogChannel;
|
||||
import edu.wpi.first.wpilibj.Counter;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Jaguar;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brad
|
||||
*/
|
||||
public class MagneticRotaryAssembly {
|
||||
|
||||
public static Jaguar getJaguar() {
|
||||
return new Jaguar(1, 6);
|
||||
}
|
||||
|
||||
public static DigitalOutput getLimitSWFwd() {
|
||||
return new DigitalOutput(2, 13);
|
||||
}
|
||||
|
||||
public static DigitalOutput getLimitSWRev() {
|
||||
return new DigitalOutput(2, 14);
|
||||
}
|
||||
|
||||
public static Counter getGTS() {
|
||||
return new Counter(1, 5);
|
||||
}
|
||||
|
||||
public static Encoder getEncoder() {
|
||||
return new Encoder(1, 6, 1, 7);
|
||||
}
|
||||
|
||||
public static Counter getHallEffect() {
|
||||
return new Counter(1, 1);
|
||||
}
|
||||
|
||||
public AnalogChannel getMagneticEncoder() {
|
||||
return new AnalogChannel(2, 6);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package Assemblies;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogChannel;
|
||||
import edu.wpi.first.wpilibj.Counter;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Jaguar;
|
||||
import edu.wpi.first.wpilibj.Victor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Fred
|
||||
*/
|
||||
public class PotentiometerAssembly {
|
||||
|
||||
public static Jaguar getJaguar(){
|
||||
return new Jaguar(1,5);
|
||||
}
|
||||
|
||||
public static DigitalOutput getLimSWFwd(){
|
||||
return new DigitalOutput(1, 13);
|
||||
}
|
||||
|
||||
public static DigitalOutput getLimSWRev(){
|
||||
return new DigitalOutput(1, 14);
|
||||
}
|
||||
|
||||
public static Victor getVictor(){
|
||||
return new Victor(1, 2);
|
||||
}
|
||||
|
||||
public static AnalogChannel getPotentiometer(){
|
||||
return new AnalogChannel(1, 3);
|
||||
}
|
||||
|
||||
public static Counter getHallEffect(){
|
||||
return new Counter(1, 4);
|
||||
}
|
||||
|
||||
public static Counter getGearTooth(){
|
||||
return new Counter(2, 7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package Assemblies;
|
||||
|
||||
import edu.wpi.first.testing.SlowServo;
|
||||
import edu.wpi.first.wpilibj.Gyro;
|
||||
import edu.wpi.first.wpilibj.Servo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mwills
|
||||
*/
|
||||
public class RCAssembly {
|
||||
|
||||
public static Servo getServo(){
|
||||
return new SlowServo(1, 1);
|
||||
}
|
||||
|
||||
public static Gyro getGyro(){
|
||||
return new Gyro(1, 1);
|
||||
}
|
||||
|
||||
/*public static SPIAccelerometer getAccelerometer(){
|
||||
return new SPIAccelerometer(2, 1, 2, 3, 4, 5, 6);
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
package edu.wpi.first.testing;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brad
|
||||
*/
|
||||
public interface Connections {
|
||||
|
||||
/**
|
||||
* Grey Jaguar, Victor and associated motor and sensors
|
||||
*/
|
||||
public static final int GreyJagPWM = 5;
|
||||
public static final int GreyJagBrakeCoast = 12;
|
||||
public static final int GreyJagLimitFWD = 13;
|
||||
public static final int GreyJagLimitRev = 14;
|
||||
public static final int VictorPWM = 2;
|
||||
public static final int VictorBrakeCoast = 2;
|
||||
public static final int GreyJagGearTooth = 7; // DSC module 2
|
||||
public static final int ContinuousTurnPot = 3;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final int DIOCrossConnectA1 = 8;
|
||||
public static final int DIOCrossConnectA2 = 11;
|
||||
public static final int DIOCrossConnectB1 = 9;
|
||||
public static final int DIOCrossConnectB2 = 10;
|
||||
public static final int DIOCrossConnectC1 = 10;
|
||||
public static final int DIOCrossConnectC2 = 9;
|
||||
public static final int DIOCrossConnectD1 = 11;
|
||||
public static final int DIOCrossConnectD2 = 8;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2011. 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.testing;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dtjones
|
||||
*/
|
||||
public class Failure {
|
||||
TestFailure failure;
|
||||
Failure(TestFailure failure) {
|
||||
this.failure = failure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string represention of the failed test.
|
||||
* @return A string representation of the failed test.
|
||||
*/
|
||||
public String toString() {
|
||||
return getTest() + " " + getTestClass() + " : " + failure.getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the test that failed.
|
||||
* @return The name of the test that failed.
|
||||
*/
|
||||
public String getTest() {
|
||||
return failure.getTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the test class that failed.
|
||||
* @return The name of the test class that failed.
|
||||
*/
|
||||
public String getTestClass() {
|
||||
return failure.getTestClass();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package edu.wpi.first.testing;
|
||||
|
||||
import edu.wpi.first.wpilibj.Servo;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* Servo which moves very slowly.
|
||||
*
|
||||
* In order to support testing a gyroscope using a hobby servo, we must slow
|
||||
* down the turn rate of the hobby servo. Otherwise, the hobby servo would
|
||||
* rotate at a speed much higher than that that the gyroscope can measure.
|
||||
*
|
||||
* @author pmalmsten
|
||||
*/
|
||||
public class SlowServo extends Servo {
|
||||
|
||||
public SlowServo(int port) {
|
||||
super(port);
|
||||
}
|
||||
|
||||
public SlowServo(int module, int port) {
|
||||
super(module, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the servo position moving at a slow rate of speed and block
|
||||
* until it gets there.
|
||||
*
|
||||
* Servo values range from 0.0 to 1.0 corresponding to the range of full left to full right.
|
||||
*
|
||||
* @param value Position from 0.0 to 1.0.
|
||||
*/
|
||||
public void setPosition(double position) {
|
||||
double posToGo = position - getPosition();
|
||||
|
||||
for(int i = 0; i < Math.floor(Math.abs(posToGo) / 0.05); i++) {
|
||||
// Apply step
|
||||
super.setPosition(getPosition() + ((posToGo > 0)? 0.05:-0.05));
|
||||
|
||||
System.out.println(" At: " + getPosition() + " Going to: " + posToGo);
|
||||
|
||||
// Wait
|
||||
Timer.delay(0.5);
|
||||
}
|
||||
|
||||
// Apply remainder
|
||||
super.setPosition(position);
|
||||
|
||||
System.out.println(" At: " + getPosition() + " Going to: " + posToGo);
|
||||
|
||||
// Wait
|
||||
Timer.delay(0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the servo position directly and does not block. Should not be used
|
||||
* during testing (but may be useful for preparing a test).
|
||||
*
|
||||
* Servo values range from 0.0 to 1.0 corresponding to the range of full left to full right.
|
||||
*
|
||||
* @param value Position from 0.0 to 1.0.
|
||||
*/
|
||||
public void fastSet(double position) {
|
||||
super.set(position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2011. 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.testing;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
|
||||
/**
|
||||
* This class should be extended by test classes. Make sure to call the
|
||||
* constructor for each subclass once so that the class is added to the master
|
||||
* hashtable
|
||||
* @author dtjones
|
||||
*/
|
||||
public abstract class TestClass {
|
||||
static Hashtable testClassesByName = new Hashtable();
|
||||
static Hashtable testClassesByTag = new Hashtable();
|
||||
Hashtable tests = new Hashtable();
|
||||
static Vector failedTests = new Vector();
|
||||
|
||||
|
||||
static {
|
||||
Reflections reflections = new Reflections("edu.wpi.first.wpilibj.unittests");
|
||||
|
||||
Set<Class<? extends TestClass>> tests = reflections.getSubTypesOf(TestClass.class);
|
||||
for (Class<? extends TestClass> test : tests) {
|
||||
try {
|
||||
test.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the test class and add it to the master table
|
||||
* of test classes
|
||||
*/
|
||||
public TestClass () {
|
||||
testClassesByName.put(getName(), this);
|
||||
|
||||
String[] tags = getTags();
|
||||
for(int i = 0; i < tags.length; i++) {
|
||||
if(testClassesByTag.containsKey(tags[i])) {
|
||||
// The tag exists; add ourself to it
|
||||
((Vector) testClassesByTag.get(tags[i])).addElement(this);
|
||||
} else {
|
||||
// The tag does not already exist; create it
|
||||
Vector testClassVector = new Vector();
|
||||
testClassesByTag.put(tags[i], testClassVector);
|
||||
|
||||
// Add ourself to it
|
||||
testClassVector.addElement(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should be extended within subclasses of each TestClass to
|
||||
* add a test. In the constructor for the TestClass you could put :
|
||||
* new Test() {
|
||||
* public String getName() { return "Sample"; }
|
||||
* public void run() {
|
||||
* //your test here
|
||||
* assertFail("I don't work");
|
||||
* }
|
||||
* };
|
||||
*/
|
||||
public abstract class Test {
|
||||
private String testName;
|
||||
/**
|
||||
* Create a new Test and add it to the master classes table of tests
|
||||
* @param name The name for this test, This should be unique for this TestClass.
|
||||
*/
|
||||
public Test(String name) {
|
||||
this.testName = name;
|
||||
tests.put(getName(), this);
|
||||
}
|
||||
/**
|
||||
* Get the name of this test, should be unique within this test class.
|
||||
* @return the name of the test
|
||||
*/
|
||||
public String getName () { return this.testName;};
|
||||
/**
|
||||
* The code to test. Failure is triggered using one of the assert methods
|
||||
*/
|
||||
public abstract void run ();
|
||||
/**
|
||||
* Setup code to run before this test is run
|
||||
*/
|
||||
public void setup() {}
|
||||
/**
|
||||
* Teardown code to run after the test is run
|
||||
*/
|
||||
public void teardown() {}
|
||||
|
||||
/**
|
||||
* Return a string representing this Test.
|
||||
* @return The name of the Test.
|
||||
*/
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs this test case.
|
||||
*/
|
||||
final void test() {
|
||||
try {
|
||||
setup();
|
||||
run();
|
||||
onPass();
|
||||
} catch (TestFailure e) {
|
||||
onFailure(e);
|
||||
} finally {
|
||||
teardown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default failure hook called when a test fails. May be
|
||||
* overridden.
|
||||
*
|
||||
* @param e The TestFailure to report.
|
||||
*/
|
||||
protected void onFailure(TestFailure e) {
|
||||
// System.out.println(" " + getName() + " failed : " + e.getMessage());
|
||||
System.out.println("!!! TEST FAILED: " + getName() + " with: " + e.getMessage());
|
||||
System.out.print(" ");
|
||||
e.print(System.out);
|
||||
System.out.println();
|
||||
e.setTestName(
|
||||
TestClass.this.getName(),
|
||||
this.getName());
|
||||
failedTests.addElement(new Failure(e));
|
||||
}
|
||||
|
||||
/**
|
||||
* Default pass hook called when a test passes. May be overridden.
|
||||
*/
|
||||
public void onPass() {
|
||||
System.out.println(" " + getName() + " passed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A test which does not emit a test failure sentinel to the console
|
||||
* when it fails, such that an automated test harness like Hudson does
|
||||
* not mark the build as unstable.
|
||||
*/
|
||||
public abstract class TestUnderDevelopment extends Test {
|
||||
public TestUnderDevelopment(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void onFailure(TestFailure e) {
|
||||
System.out.println("### " + getName() + " failed : " + e.getMessage());
|
||||
System.out.print(" ");
|
||||
e.print(System.out);
|
||||
System.out.println();
|
||||
e.setTestName(
|
||||
TestClass.this.getName(),
|
||||
this.getName());
|
||||
failedTests.addElement(new Failure(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this TestClass. This should be unique within the testClassesByName
|
||||
* @return The name of this test class
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Returns an array of tag names for which this class is associated.
|
||||
*
|
||||
* @return An array of tag names that this class is associated with.
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return new String[] {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup code to run before the tests within this class are run
|
||||
*/
|
||||
public void setup() {}
|
||||
/**
|
||||
* Teardown code to run after the tests within this class are run
|
||||
*/
|
||||
public void teardown() {}
|
||||
|
||||
/**
|
||||
* Get a list of all the failed tests.
|
||||
* @return A list of all of the failed tests.
|
||||
*/
|
||||
public static Failure[] getFailures() {
|
||||
Failure[] failures = new Failure[failedTests.size()];
|
||||
failedTests.copyInto(failures);
|
||||
return failures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representing this TestClass.
|
||||
* @return The name of this test class.
|
||||
*/
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
final void test() {
|
||||
System.out.println("Running: " + getName());
|
||||
setup();
|
||||
Enumeration elements = tests.elements();
|
||||
while(elements.hasMoreElements())
|
||||
((Test)elements.nextElement()).test();
|
||||
teardown();
|
||||
}
|
||||
|
||||
final void test(String test) {
|
||||
System.out.println("Running: " + getName());
|
||||
setup();
|
||||
((Test)tests.get(test)).test();
|
||||
teardown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the tests within the class name given
|
||||
* @param clas The name of the TestClass to run
|
||||
*/
|
||||
public static void run(String clas) {
|
||||
TestClass testCase = (TestClass)testClassesByName.get(clas);
|
||||
testCase.test();
|
||||
System.out.println("Completed: " + testCase.getName());
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given test within the given class
|
||||
* @param clas The name of the class to run.
|
||||
* @param test The name of the test to run.
|
||||
*/
|
||||
public static void run(String clas, String test) {
|
||||
TestClass testCase = (TestClass)testClassesByName.get(clas);
|
||||
testCase.test(test);
|
||||
System.out.println("Completed: " + testCase.getName());
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all of the tests in all of the classes.
|
||||
*/
|
||||
public static void runAll () {
|
||||
Enumeration elements = testClassesByName.elements();
|
||||
while(elements.hasMoreElements())
|
||||
((TestClass)elements.nextElement()).test();
|
||||
System.out.println("Tests complete");
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all tests within test classes whose getTags() result contains the
|
||||
* given string.
|
||||
*
|
||||
* @param tagName The tag name for which all associated tests should run.
|
||||
*/
|
||||
public static void runAllWithTag(String tagName) {
|
||||
Vector tests = (Vector) testClassesByTag.get(tagName);
|
||||
|
||||
if(tests != null) {
|
||||
Enumeration elements = tests.elements();
|
||||
while(elements.hasMoreElements())
|
||||
((TestClass)elements.nextElement()).test();
|
||||
System.out.println("Tests complete");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test.
|
||||
* @param msg A message descibing the failure.
|
||||
*/
|
||||
protected void assertFail (String msg) {
|
||||
throw new TestFailure(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test if the given items are not the same
|
||||
* @param expected The expected value.
|
||||
* @param actual The actual value.
|
||||
*/
|
||||
protected void assertEquals (Object expected, Object actual) {
|
||||
if ((null == expected) ^ (null == actual))
|
||||
throw new TestFailure("Expected " + expected + " got " + actual);
|
||||
if (!expected.equals(actual))
|
||||
throw new TestFailure("Expected " + expected + " got " + actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test if the given items are not the same
|
||||
* @param expected The expected value.
|
||||
* @param actual The actual value.
|
||||
*/
|
||||
protected void assertEquals (long expected, long actual) {
|
||||
if (expected != actual)
|
||||
throw new TestFailure("Expected " + expected + " got " + actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test if the given items are not the same
|
||||
* @param expected The expected value.
|
||||
* @param actual The actual value.
|
||||
*/
|
||||
protected void assertEquals (double expected, double actual) {
|
||||
if (expected != actual)
|
||||
throw new TestFailure("Expected " + expected + " got " + actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test if the given items are not the same
|
||||
* @param expected The expected value.
|
||||
* @param actual The actual value.
|
||||
* @param tolerance The amount by which the values must match
|
||||
*/
|
||||
protected void assertEquals (double expected, double actual, double tolerance) {
|
||||
if (Math.abs(expected - actual) > tolerance)
|
||||
throw new TestFailure("Expected " + expected + " got " + actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test if the given value is false.
|
||||
* @param value Boolean value that must be true for success
|
||||
*/
|
||||
protected void assertTrue (boolean value) {
|
||||
if ( ! value )
|
||||
throw new TestFailure("Assertion was false");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test if the given value is true.
|
||||
* @param value Boolean value that must be false for success
|
||||
*/
|
||||
protected void assertFalse (boolean value) {
|
||||
if ( value )
|
||||
throw new TestFailure("Assertion was true");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2011. 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.testing;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
|
||||
/**
|
||||
* This Exception is thrown when a test fails.
|
||||
* @author dtjones
|
||||
*/
|
||||
class TestFailure extends RuntimeException {
|
||||
private String testClass = null;
|
||||
private String test = null;
|
||||
/**
|
||||
* An execution point representing the line where the assertion that failed
|
||||
* was called.
|
||||
*/
|
||||
protected final StackTraceElement failedTest;
|
||||
/**
|
||||
* Create a new TestFailure exception to fail the currently runningt test.
|
||||
* @param msg The message to pass with the exception explaining what failed
|
||||
* in the test
|
||||
*/
|
||||
protected TestFailure (String msg) {
|
||||
super(msg);
|
||||
failedTest = Thread.currentThread().getStackTrace()[3];
|
||||
// failedTest = VM.reifyCurrentStack(-1)[3];
|
||||
}
|
||||
|
||||
void setTestName(String testClass, String test) {
|
||||
this.testClass = testClass;
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the test class
|
||||
* @return the name of the test class
|
||||
*/
|
||||
public String getTestClass() {
|
||||
return testClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the test
|
||||
* @return the name of the test
|
||||
*/
|
||||
public String getTest() {
|
||||
return test;
|
||||
}
|
||||
|
||||
public void print(PrintStream out) {
|
||||
out.print(failedTest.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.testing;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author alex
|
||||
*/
|
||||
public class Utils {
|
||||
public static int[] combine(int[] a, int[] b) {
|
||||
int[] out = new int[a.length+b.length];
|
||||
System.arraycopy(a, 0, out, 0, a.length);
|
||||
System.arraycopy(b, 0, out, a.length, b.length);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>WPI Test Utilities</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=MacRoman">
|
||||
</head>
|
||||
<body>
|
||||
Test utility classes used by WPILibJ testing. See WPILibJ/tests for examples.
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.buttons.InternalButton;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mitchell
|
||||
*/
|
||||
public class ButtonTest extends TestClass{
|
||||
|
||||
public String getName() {
|
||||
return "Button Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.COMMANDBASED };
|
||||
}
|
||||
|
||||
private InternalButton button1;
|
||||
private InternalButton button2;
|
||||
public void setup() {
|
||||
button1 = new InternalButton();
|
||||
button2 = new InternalButton();
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
new Test("Simple Button Test") {
|
||||
|
||||
public void run() {
|
||||
TestCommand command1 = new TestCommand();
|
||||
TestCommand command2 = new TestCommand();
|
||||
TestCommand command3 = new TestCommand();
|
||||
TestCommand command4 = new TestCommand();
|
||||
|
||||
button1.whenPressed(command1);
|
||||
button1.whenReleased(command2);
|
||||
button1.whileHeld(command3);
|
||||
button2.whileHeld(command4);
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command4, 0, 0, 0, 0, 0);
|
||||
button1.setPressed(true);
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command4, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command4, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command4, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command4, 0, 0, 0, 0, 0);
|
||||
button2.setPressed(true);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 1, 3, 3, 0, 0);
|
||||
assertCommandState(command4, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 4, 4, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 1, 4, 4, 0, 0);
|
||||
assertCommandState(command4, 1, 1, 1, 0, 0);
|
||||
button1.setPressed(false);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 5, 5, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command4, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 6, 6, 0, 0);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command3, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command4, 1, 3, 3, 0, 0);
|
||||
button2.setPressed(false);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 7, 7, 0, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command3, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command4, 1, 3, 3, 0, 1);
|
||||
command1.cancel();
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 7, 7, 0, 1);
|
||||
assertCommandState(command2, 1, 3, 3, 0, 0);
|
||||
assertCommandState(command3, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command4, 1, 3, 3, 0, 1);
|
||||
command2.setHasFinished(true);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 7, 7, 0, 1);
|
||||
assertCommandState(command2, 1, 4, 4, 1, 0);
|
||||
assertCommandState(command3, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command4, 1, 3, 3, 0, 1);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 7, 7, 0, 1);
|
||||
assertCommandState(command2, 1, 4, 4, 1, 0);
|
||||
assertCommandState(command3, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command4, 1, 3, 3, 0, 1);
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private int testCount = 1;
|
||||
public void assertCommandState(TestCommand command, int initialize, int execute, int isFinished, int end, int interrupted) {
|
||||
//System.out.println("Test Command Initialize "+(testCount++));
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
//System.out.println("Test Command Execute");
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
//System.out.println("Test Command IsFinished");
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
//System.out.println("Test Command End");
|
||||
assertEquals(end, command.getEndCount());
|
||||
//System.out.println("Test Command Interrupted");
|
||||
assertEquals(interrupted, command.getInterruptedCount());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mitchell
|
||||
*/
|
||||
public class CommandParallelGroupTest extends TestClass{
|
||||
|
||||
public String getName() {
|
||||
return "Command Parallel Group Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.COMMANDBASED };
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
}
|
||||
|
||||
private class ASubsystem extends Subsystem {
|
||||
protected void initDefaultCommand(){
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Simple Parallel Command Group With 2 commands one command terminates first") {
|
||||
|
||||
public void run() {
|
||||
TestCommand command1 = new TestCommand();
|
||||
TestCommand command2 = new TestCommand();
|
||||
|
||||
CommandGroup commandGroup = new CommandGroup();
|
||||
commandGroup.addParallel(command1);
|
||||
commandGroup.addParallel(command2);
|
||||
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
commandGroup.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
command1.setHasFinished(true);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 3, 3, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 4, 4, 0, 0);
|
||||
command2.setHasFinished(true);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 5, 5, 1, 0);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Simple Parallel Command Group With 2 commands. The group is canceled") {
|
||||
|
||||
public void run() {
|
||||
TestCommand command1 = new TestCommand();
|
||||
TestCommand command2 = new TestCommand();
|
||||
|
||||
CommandGroup commandGroup = new CommandGroup();
|
||||
commandGroup.addParallel(command1);
|
||||
commandGroup.addParallel(command2);
|
||||
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
commandGroup.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
commandGroup.cancel();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private int testCount = 1;
|
||||
public void assertCommandState(TestCommand command, int initialize, int execute, int isFinished, int end, int interrupted) {
|
||||
//System.out.println("Test Command Initialize "+(testCount++));
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
//System.out.println("Test Command Execute");
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
//System.out.println("Test Command IsFinished");
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
//System.out.println("Test Command End");
|
||||
assertEquals(end, command.getEndCount());
|
||||
//System.out.println("Test Command Interrupted");
|
||||
assertEquals(interrupted, command.getInterruptedCount());
|
||||
}
|
||||
|
||||
public void sleep(long time){
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException ex) {
|
||||
assertFail("Sleep Interrupted!?!?!?!?");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mwills
|
||||
*/
|
||||
public class CommandScheduleTest extends TestClass{
|
||||
public String getName() {
|
||||
return "Command Schedule Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.COMMANDBASED };
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Simple scheduling of a command and making sure the command is run and successfully terminates") {
|
||||
public void run() {
|
||||
TestCommand command = new TestCommand();
|
||||
command.start();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 2, 2, 0, 0);
|
||||
command.setHasFinished(true);
|
||||
assertCommandState(command, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 3, 3, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 3, 3, 1, 0);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
{
|
||||
new Test("Simple scheduling of a command and making sure the command is run and cancels correctly") {
|
||||
public void run() {
|
||||
TestCommand command = new TestCommand();
|
||||
command.start();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 3, 3, 0, 0);
|
||||
command.cancel();
|
||||
assertCommandState(command, 1, 3, 3, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 3, 3, 0, 1);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 3, 3, 0, 1);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void assertCommandState(TestCommand command, int initialize, int execute, int isFinished, int end, int interrupted){
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
assertEquals(end, command.getEndCount());
|
||||
assertEquals(interrupted, command.getInterruptedCount());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mitchell
|
||||
*/
|
||||
public class CommandSequentialGroupTest extends TestClass{
|
||||
|
||||
public String getName() {
|
||||
return "Command Sequential Group Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.COMMANDBASED };
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
}
|
||||
|
||||
private class ASubsystem extends Subsystem {
|
||||
protected void initDefaultCommand(){
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Simple Command Group With 3 commands that all depend on a subsystem") {
|
||||
|
||||
public void run() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
TestCommand command1 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
TestCommand command2 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
TestCommand command3 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
CommandGroup commandGroup = new CommandGroup();
|
||||
commandGroup.addSequential(command1);
|
||||
commandGroup.addSequential(command2);
|
||||
commandGroup.addSequential(command3);
|
||||
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
commandGroup.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
command1.setHasFinished(true);
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
command2.setHasFinished(true);
|
||||
assertCommandState(command1, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command3, 1, 1, 1, 0, 0);
|
||||
command3.setHasFinished(true);
|
||||
assertCommandState(command1, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command3, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command3, 1, 2, 2, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 1, 0);
|
||||
assertCommandState(command3, 1, 2, 2, 1, 0);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
{
|
||||
new Test("Simple Command Group With 3 commands that all depend on a subsystem. Some commands have a timeout") {
|
||||
|
||||
public void run() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
TestCommand command1 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
TestCommand command2 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
TestCommand command3 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
CommandGroup commandGroup = new CommandGroup();
|
||||
commandGroup.addSequential(command1, 1.0);
|
||||
commandGroup.addSequential(command2, 2.0);
|
||||
commandGroup.addSequential(command3);
|
||||
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
commandGroup.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
sleep(1000);//command 1 timeout
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
sleep(2000);//command 2 timeout
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 1 ,1, 0, 0);
|
||||
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 2, 2, 0, 0);
|
||||
command3.setHasFinished(true);
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 3, 3, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 3, 3, 1, 0);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private int testCount = 1;
|
||||
public void assertCommandState(TestCommand command, int initialize, int execute, int isFinished, int end, int interrupted) {
|
||||
//System.out.println("Test Command Initialize "+(testCount++));
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
//System.out.println("Test Command Execute");
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
//System.out.println("Test Command IsFinished");
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
//System.out.println("Test Command End");
|
||||
assertEquals(end, command.getEndCount());
|
||||
//System.out.println("Test Command Interrupted");
|
||||
assertEquals(interrupted, command.getInterruptedCount());
|
||||
}
|
||||
|
||||
public void sleep(long time){
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException ex) {
|
||||
assertFail("Sleep Interrupted!?!?!?!?");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mitchell
|
||||
*/
|
||||
public class CommandSupercedeTest extends TestClass{
|
||||
|
||||
public String getName() {
|
||||
return "Command Supercede Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.COMMANDBASED };
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
}
|
||||
|
||||
private class ASubsystem extends Subsystem {
|
||||
protected void initDefaultCommand(){
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Testing one command superceeding another because of dependancies") {
|
||||
|
||||
public void run() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
TestCommand command1 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
TestCommand command2 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
command1.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
command2.start();
|
||||
assertCommandState(command1, 1, 3, 3, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command2, 1, 1, 1 , 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command2, 1, 3, 3, 0, 0);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
{
|
||||
new Test("Testing one command failing superceeding another because of dependancies because the first command cannot be interrupted") {
|
||||
|
||||
public void run() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
TestCommand command1 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
setInterruptible(false);
|
||||
}
|
||||
};
|
||||
|
||||
TestCommand command2 = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
command1.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
command2.start();
|
||||
assertCommandState(command1, 1, 3, 3, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 4, 4, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private int testCount = 1;
|
||||
public void assertCommandState(TestCommand command, int initialize, int execute, int isFinished, int end, int interrupted) {
|
||||
//System.out.println("Test Command Initialize "+(testCount++));
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
//System.out.println("Test Command Execute");
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
//System.out.println("Test Command IsFinished");
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
//System.out.println("Test Command End");
|
||||
assertEquals(end, command.getEndCount());
|
||||
//System.out.println("Test Command Interrupted");
|
||||
assertEquals(interrupted, command.getInterruptedCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.testing.TestClass.Test;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mitchell
|
||||
*/
|
||||
public class CommandTimeoutTest extends TestClass{
|
||||
|
||||
public String getName() {
|
||||
return "Command Timeout Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.COMMANDBASED };
|
||||
}
|
||||
|
||||
|
||||
public void setup() {
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
}
|
||||
|
||||
private class ASubsystem extends Subsystem {
|
||||
protected void initDefaultCommand(){
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Command 2 second Timeout Test") {
|
||||
|
||||
public void run() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
TestCommand command = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
setTimeout(2);
|
||||
}
|
||||
public boolean isFinished(){
|
||||
return super.isFinished() || isTimedOut();
|
||||
}
|
||||
};
|
||||
|
||||
command.start();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 3, 3, 0, 0);
|
||||
sleep(2000);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 4, 4, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 4, 4, 1, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private int testCount = 1;
|
||||
public void assertCommandState(TestCommand command, int initialize, int execute, int isFinished, int end, int interrupted) {
|
||||
//System.out.println("Test Command Initialize "+(testCount++));
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
//System.out.println("Test Command Execute");
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
//System.out.println("Test Command IsFinished");
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
//System.out.println("Test Command End");
|
||||
assertEquals(end, command.getEndCount());
|
||||
//System.out.println("Test Command Interrupted");
|
||||
assertEquals(interrupted, command.getInterruptedCount());
|
||||
}
|
||||
|
||||
public void sleep(long time){
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException ex) {
|
||||
assertFail("Sleep Interrupted!?!?!?!?");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import Assemblies.DIOCrossConnect;
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
|
||||
/**
|
||||
* Tests the crossed DIO lines between the two digital sidecars on the
|
||||
* version 2.1 test stand by Chris Jennings.
|
||||
*
|
||||
* @author Paul
|
||||
*/
|
||||
public class DIOToDIOTest extends TestClass {
|
||||
private DigitalOutput m_AOut;
|
||||
private DigitalInput m_AIn;
|
||||
|
||||
public String getName() {
|
||||
return "DIOToDIOTest";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] {RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.DIGITAL};
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
m_AOut = DIOCrossConnect.getOutputA();
|
||||
m_AIn = DIOCrossConnect.getInputA();
|
||||
}
|
||||
|
||||
{
|
||||
new Test("SignalALowDetected") {
|
||||
|
||||
public void run() {
|
||||
m_AOut.set(false);
|
||||
assertFalse(m_AIn.get());
|
||||
}
|
||||
};
|
||||
|
||||
new Test("SignalAHighDetected") {
|
||||
|
||||
public void run() {
|
||||
m_AOut.set(true);
|
||||
assertTrue(m_AIn.get());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
m_AIn.free();
|
||||
m_AOut.free();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.testing.TestClass.Test;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mwills
|
||||
*/
|
||||
public class DefaultCommandsTest extends TestClass {
|
||||
|
||||
public String getName() {
|
||||
return "Default Commands Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.COMMANDBASED };
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
}
|
||||
|
||||
private class ASubsystem extends Subsystem {
|
||||
Command command;
|
||||
protected void initDefaultCommand(){
|
||||
setDefaultCommand(command);
|
||||
}
|
||||
public void init(Command command) {
|
||||
this.command = command;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Testing of default commands where the interrupting command is ends itself") {
|
||||
|
||||
public void run() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
TestCommand defaultCommand = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
TestCommand anotherCommand = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
|
||||
subsystem.init(defaultCommand);
|
||||
|
||||
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 2, 2, 0, 0);
|
||||
|
||||
anotherCommand.start();
|
||||
assertCommandState(defaultCommand, 1, 2, 2, 0, 0);
|
||||
assertCommandState(anotherCommand, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 0);
|
||||
anotherCommand.setHasFinished(true);
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 3, 3, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 2, 4, 4, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 3, 3, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 2, 5, 5, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 3, 3, 1, 0);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Testing of default commands where the interrupting command is canceled") {
|
||||
|
||||
public void run() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
TestCommand defaultCommand = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
TestCommand anotherCommand = new TestCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
|
||||
subsystem.init(defaultCommand);
|
||||
subsystem.initDefaultCommand();
|
||||
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 2, 2, 0, 0);
|
||||
|
||||
anotherCommand.start();
|
||||
assertCommandState(defaultCommand, 1, 2, 2, 0, 0);
|
||||
assertCommandState(anotherCommand, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 0);
|
||||
anotherCommand.cancel();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 1);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 2, 4, 4, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 1);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(defaultCommand, 2, 5, 5, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 1);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void assertCommandState(TestCommand command, int initialize, int execute, int isFinished, int end, int interrupted) {
|
||||
//System.out.println("Test Command Initialize");
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
//System.out.println("Test Command Execute");
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
//System.out.println("Test Command IsFinished");
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
//System.out.println("Test Command End");
|
||||
assertEquals(end, command.getEndCount());
|
||||
//System.out.println("Test Command Interrupted");
|
||||
assertEquals(interrupted, command.getInterruptedCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import Assemblies.MagneticRotaryAssembly;
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.Counter;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Jaguar;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brad
|
||||
*/
|
||||
public class EncoderTest extends TestClass {
|
||||
|
||||
private Encoder encoder;
|
||||
private Jaguar jag;
|
||||
private DigitalOutput fwdLimit;
|
||||
private DigitalOutput revLimit;
|
||||
private Counter gts;
|
||||
|
||||
public String getName() {
|
||||
return "Encoder test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.DIGITAL,
|
||||
RunTests.Tags.Type.PWM,
|
||||
};
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
encoder = MagneticRotaryAssembly.getEncoder();
|
||||
jag = MagneticRotaryAssembly.getJaguar();
|
||||
fwdLimit = MagneticRotaryAssembly.getLimitSWFwd();
|
||||
revLimit = MagneticRotaryAssembly.getLimitSWRev();
|
||||
gts = MagneticRotaryAssembly.getGTS();
|
||||
fwdLimit.set(false);
|
||||
revLimit.set(false);
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
encoder.free();
|
||||
jag.free();
|
||||
fwdLimit.free();
|
||||
revLimit.free();
|
||||
gts.free();
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Compare Encoder with Geartooth sensor") {
|
||||
|
||||
/**
|
||||
* Drive forward for a fixed time
|
||||
*/
|
||||
private int driveForward(double time) {
|
||||
encoder.reset();
|
||||
encoder.start();
|
||||
jag.set(1);
|
||||
Timer.delay(time);
|
||||
jag.set(0);
|
||||
return encoder.get();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
gts.reset();
|
||||
gts.start();
|
||||
driveForward(2);
|
||||
Timer.delay(2);
|
||||
System.out.println("Gear tooth sensor: " + gts.get());
|
||||
System.out.println("Encoder: " + encoder.get());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Drive forward then backward") {
|
||||
|
||||
/**
|
||||
* Drive forward for a fixed time
|
||||
*/
|
||||
private int driveForward(double time) {
|
||||
encoder.reset();
|
||||
encoder.start();
|
||||
jag.set(1);
|
||||
Timer.delay(time);
|
||||
jag.set(0);
|
||||
return encoder.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drive forward then let the motor stop, then drive forward again. Compare the results.
|
||||
* Then drive backwards, and see that the results have gone back near zero.
|
||||
*
|
||||
* This is pretty cheesy, and needs to be replaced with a test that compares the gear tooth
|
||||
* sensor with the encoder.
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
int pass1 = driveForward(1);
|
||||
assertEquals(1064, pass1, 50);
|
||||
|
||||
Timer.delay(2); // wait for motor to stop
|
||||
|
||||
int pass2 = driveForward(1);
|
||||
assertEquals(0, pass1-pass2, (int)(pass1*0.05));
|
||||
|
||||
jag.set(-1);
|
||||
Timer.delay(1);
|
||||
jag.set(0);
|
||||
assertEquals(0, encoder.get(), (int)(pass1*0.10));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. 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.unittests;
|
||||
|
||||
import Assemblies.FakeCounterSource;
|
||||
import edu.wpi.first.testing.Connections;
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.Counter;
|
||||
|
||||
/**
|
||||
* @file FakeEncoderTest.java
|
||||
* Test the fake encoder classes to verify they are valid for future test use
|
||||
* @author Ryan O'Meara
|
||||
*/
|
||||
public class FakeEncoderTest extends TestClass implements Connections
|
||||
{
|
||||
private Counter counter;
|
||||
private FakeCounterSource fakeEncoder;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return "FakeEncoder Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.DIGITAL };
|
||||
}
|
||||
|
||||
public void setup()
|
||||
{
|
||||
counter = new Counter(DIOCrossConnectD1);
|
||||
fakeEncoder = new FakeCounterSource(2, DIOCrossConnectD2);
|
||||
}
|
||||
|
||||
public void teardown()
|
||||
{
|
||||
counter.free();
|
||||
fakeEncoder.free();
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
new Test("Counting accuracy")
|
||||
{
|
||||
|
||||
public void run()
|
||||
{
|
||||
final int MAXCOUNT = 500;
|
||||
counter.reset();
|
||||
counter.start();
|
||||
|
||||
fakeEncoder.setCount(MAXCOUNT);
|
||||
fakeEncoder.setRate(1);
|
||||
fakeEncoder.execute();
|
||||
assertEquals(counter.get(), MAXCOUNT);
|
||||
counter.stop();
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. 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.unittests;
|
||||
|
||||
import Assemblies.FakeEncoderSource;
|
||||
import edu.wpi.first.testing.Connections;
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.Counter;
|
||||
|
||||
/**
|
||||
* @file FakeEncoderTest.java
|
||||
* Test the fake encoder classes to verify they are valid for future test use
|
||||
* @author Ryan O'Meara
|
||||
*/
|
||||
public class FakeQuadEncoderTest extends TestClass implements Connections
|
||||
{
|
||||
|
||||
private final int MAXCOUNT = 500;
|
||||
private Counter counter;
|
||||
private Counter counter2;
|
||||
private FakeEncoderSource fakeQEncoder;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return "FakeQuadEncoder Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.DIGITAL };
|
||||
}
|
||||
|
||||
public void setup()
|
||||
{
|
||||
counter = new Counter(DIOCrossConnectA1);
|
||||
counter2 = new Counter(DIOCrossConnectB1);
|
||||
fakeQEncoder = new FakeEncoderSource(2, DIOCrossConnectA2, 2, DIOCrossConnectB2);
|
||||
}
|
||||
|
||||
public void teardown()
|
||||
{
|
||||
counter.free();
|
||||
counter2.free();
|
||||
fakeQEncoder.free();
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
new Test("Forward counting")
|
||||
{
|
||||
|
||||
public void run()
|
||||
{
|
||||
counter.reset();
|
||||
counter2.reset();
|
||||
|
||||
fakeQEncoder.setCount(MAXCOUNT);
|
||||
fakeQEncoder.setRate(1);
|
||||
counter.start();
|
||||
counter2.start();
|
||||
fakeQEncoder.execute();
|
||||
assertEquals(counter.get(), MAXCOUNT);
|
||||
assertEquals(counter2.get(), MAXCOUNT);
|
||||
}
|
||||
};
|
||||
|
||||
new Test("Reverse counting")
|
||||
{
|
||||
|
||||
public void run()
|
||||
{
|
||||
counter.reset();
|
||||
counter2.reset();
|
||||
fakeQEncoder.setForward(false);
|
||||
fakeQEncoder.setCount(MAXCOUNT);
|
||||
fakeQEncoder.setRate(1);
|
||||
counter.start();
|
||||
counter2.start();
|
||||
fakeQEncoder.execute();
|
||||
|
||||
assertEquals(counter.get(), MAXCOUNT);
|
||||
assertEquals(counter2.get(), MAXCOUNT);
|
||||
|
||||
counter.stop();
|
||||
counter2.stop();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import Assemblies.RCAssembly;
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.Gyro;
|
||||
import edu.wpi.first.wpilibj.Servo;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mwills
|
||||
*/
|
||||
public class GyroTest extends TestClass{
|
||||
private Gyro gyro;
|
||||
private Servo servo;
|
||||
public String getName() {
|
||||
return "Gyro Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INDEVEL,
|
||||
RunTests.Tags.Type.ANALOG };
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
gyro = RCAssembly.getGyro();
|
||||
servo = RCAssembly.getServo();
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
gyro.free();
|
||||
servo.free();
|
||||
}
|
||||
|
||||
{
|
||||
new TestUnderDevelopment("Gyro connected to servo panning one way") {
|
||||
public void run() {
|
||||
servo.set(0);
|
||||
Timer.delay(3);
|
||||
gyro.reset();
|
||||
servo.set(1);
|
||||
Timer.delay(3);
|
||||
assertEquals(138, gyro.getAngle(), 1);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
new TestUnderDevelopment("Gyro connected to servo panning back and forth once") {
|
||||
public void run() {
|
||||
servo.set(0);
|
||||
Timer.delay(3);
|
||||
gyro.reset();
|
||||
servo.set(1);
|
||||
Timer.delay(3);
|
||||
servo.set(0);
|
||||
Timer.delay(3);
|
||||
|
||||
assertEquals(0, gyro.getAngle(), .3);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
new TestUnderDevelopment("Gyro connected to servo panning back and forth 5 times") {
|
||||
public void run() {
|
||||
servo.set(0);
|
||||
Timer.delay(3);
|
||||
gyro.reset();
|
||||
for(int i = 0; i<5; ++i){
|
||||
servo.set(1);
|
||||
Timer.delay(3);
|
||||
servo.set(0);
|
||||
Timer.delay(3);
|
||||
}
|
||||
|
||||
assertEquals(0, gyro.getAngle(), 1);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
new TestUnderDevelopment("Gyro connected to servo panning back and forth to many positions") {
|
||||
public void run() {
|
||||
servo.set(0);
|
||||
Timer.delay(3);
|
||||
gyro.reset();
|
||||
|
||||
servo.set(0.5);
|
||||
Timer.delay(1);
|
||||
servo.set(0.75);
|
||||
Timer.delay(1);
|
||||
servo.set(0.25);
|
||||
Timer.delay(1);
|
||||
servo.set(1);
|
||||
Timer.delay(1);
|
||||
servo.set(0);
|
||||
Timer.delay(3);
|
||||
|
||||
assertEquals(0, gyro.getAngle(), 1.2);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.Connections;
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.Counter;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import edu.wpi.first.wpilibj.Victor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author brad
|
||||
*/
|
||||
public class JaguarTest extends TestClass implements Connections {
|
||||
|
||||
Victor victor;
|
||||
Counter gts;
|
||||
|
||||
public String getName() {
|
||||
return "JaguarTest";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.DIGITAL,
|
||||
RunTests.Tags.Type.PWM
|
||||
};
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
victor = new Victor(2);
|
||||
gts = new Counter(2, GreyJagGearTooth); // need to encode this slot number
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
victor.free();
|
||||
gts.free();
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Drive forward") {
|
||||
|
||||
public void run() {
|
||||
gts.reset();
|
||||
gts.start();
|
||||
victor.set(1);
|
||||
Timer.delay(1);
|
||||
victor.set(0);
|
||||
System.out.println("Counter output: " + gts.get());
|
||||
|
||||
assertEquals(0.0, 0.1, 0.1);
|
||||
}
|
||||
};
|
||||
|
||||
new Test("Drive backward") {
|
||||
|
||||
public void run() {
|
||||
victor.set(-1);
|
||||
Timer.delay(1);
|
||||
victor.set(0);
|
||||
|
||||
assertEquals(0.0, 0.1, 0.1);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import Assemblies.MagneticRotaryAssembly;
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import edu.wpi.first.wpilibj.Jaguar;
|
||||
import edu.wpi.first.wpilibj.PIDController;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Fred
|
||||
*/
|
||||
public class PIDEncoderTest extends TestClass {
|
||||
|
||||
private Encoder encoder;
|
||||
private Jaguar jag;
|
||||
private PIDController PID;
|
||||
private DigitalOutput fwdLimit;
|
||||
private DigitalOutput revLimit;
|
||||
|
||||
public String getName() {
|
||||
return "PID Encoder Test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.DIGITAL, RunTests.Tags.Type.PWM };
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
encoder = MagneticRotaryAssembly.getEncoder();
|
||||
jag = MagneticRotaryAssembly.getJaguar();
|
||||
encoder.setPIDSourceParameter(Encoder.PIDSourceParameter.kDistance);
|
||||
PID = new PIDController(.01, 0, 0, encoder, jag);
|
||||
fwdLimit = MagneticRotaryAssembly.getLimitSWFwd();
|
||||
revLimit = MagneticRotaryAssembly.getLimitSWRev();
|
||||
fwdLimit.set(false);
|
||||
revLimit.set(false);
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
encoder.free();
|
||||
jag.free();
|
||||
PID.disable();
|
||||
fwdLimit.free();
|
||||
revLimit.free();
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Set PID Setpoint to 1000 and confirm running forward") {
|
||||
private void runPID() {
|
||||
PID.setSetpoint(1000);
|
||||
Timer.delay(3);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
encoder.reset();
|
||||
encoder.start();
|
||||
PID.reset();
|
||||
PID.enable();
|
||||
runPID();
|
||||
// while (true) {
|
||||
// System.out.println("Setpoint: " + PID.getSetpoint()
|
||||
// + " Value: " + PID.get() + " Encoder: "
|
||||
// + encoder.getDistance() + " Jaguar: " + jag.get());
|
||||
// }
|
||||
assertEquals(1000, encoder.getDistance(), 15);
|
||||
}
|
||||
};
|
||||
new Test("Set PID Setpoint to 0 and confirm running backwards") {
|
||||
private void reversePID() {
|
||||
PID.setSetpoint(0);
|
||||
Timer.delay(3);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
reversePID();
|
||||
assertEquals(0, encoder.getDistance(), 15);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.Preferences;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Fred
|
||||
*/
|
||||
public class PreferencesTest extends TestClass {
|
||||
|
||||
private Preferences pref;
|
||||
private long check;
|
||||
|
||||
public String getName() {
|
||||
return "Preferences test";
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return new String[] { RunTests.Tags.Lifecycle.INPRODUCTION,
|
||||
RunTests.Tags.Type.PREFERENCES };
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
try {
|
||||
File file = new File("file:///wpilib-preferences.ini");
|
||||
file.mkdirs();
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
file.createNewFile();
|
||||
OutputStream output = new FileOutputStream(file);
|
||||
output.write("checkedValueInt = 2\ncheckedValueDouble = .2\ncheckedValueFloat = 3.14\ncheckedValueLong = 172\ncheckedValueString =\"hello \nHow are you ?\"\ncheckedValueBoolean = false"
|
||||
.getBytes());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
pref = Preferences.getInstance();
|
||||
check = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
}
|
||||
|
||||
{
|
||||
new Test("Check preferences file operations") {
|
||||
|
||||
public void remove() {
|
||||
pref.remove("checkedValueLong");
|
||||
pref.remove("checkedValueDouble");
|
||||
pref.remove("checkedValueString");
|
||||
pref.remove("checkedValueInt");
|
||||
pref.remove("checkedValueFloat");
|
||||
pref.remove("checkedValueBoolean");
|
||||
}
|
||||
|
||||
public void addCheckedValue() {
|
||||
pref.putLong("checkedValueLong", check);
|
||||
pref.putDouble("checkedValueDouble", 1);
|
||||
pref.putString("checkedValueString", "checked");
|
||||
pref.putInt("checkedValueInt", 1);
|
||||
pref.putFloat("checkedValueFloat", 1);
|
||||
pref.putBoolean("checkedValueBoolean", true);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
assertEquals(pref.getLong("checkedValueLong", 0), 172);
|
||||
assertEquals(pref.getDouble("checkedValueDouble", 0), .2);
|
||||
assertEquals(pref.getString("checkedValueString", ""),
|
||||
"hello \nHow are you ?");
|
||||
assertEquals(pref.getInt("checkedValueInt", 0), 2);
|
||||
assertEquals(pref.getFloat("checkedValueFloat", 0), 3.14, .001);
|
||||
assertFalse(pref.getBoolean("checkedValueBoolean", true));
|
||||
remove();
|
||||
assertEquals(pref.getLong("checkedValueLong", 0), 0);
|
||||
assertEquals(pref.getDouble("checkedValueDouble", 0), 0);
|
||||
assertEquals(pref.getString("checkedValueString", ""), "");
|
||||
assertEquals(pref.getInt("checkedValueInt", 0), 0);
|
||||
assertEquals(pref.getFloat("checkedValueFloat", 0), 0);
|
||||
assertFalse(pref.getBoolean("checkedValueBoolean", false));
|
||||
addCheckedValue();
|
||||
pref.save();
|
||||
assertEquals(check, pref.getLong("checkedValueLong", 0));
|
||||
assertEquals(pref.getDouble("checkedValueDouble", 0), 1);
|
||||
assertEquals(pref.getString("checkedValueString", ""),
|
||||
"checked");
|
||||
assertEquals(pref.getInt("checkedValueInt", 0), 1);
|
||||
assertEquals(pref.getFloat("checkedValueFloat", 0), 1);
|
||||
assertTrue(pref.getBoolean("checkedValueBoolean", false));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. 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.unittests;
|
||||
|
||||
import edu.wpi.first.testing.TestClass;
|
||||
import edu.wpi.first.wpilibj.SimpleRobot;
|
||||
|
||||
|
||||
/**
|
||||
* The VM is configured to automatically run this class, and to call the
|
||||
* functions corresponding to each mode, as described in the SimpleRobot
|
||||
* documentation. If you change the name of this class or the package after
|
||||
* creating this project, you must also update the manifest file in the resource
|
||||
* directory.
|
||||
*/
|
||||
public class RunTests extends SimpleRobot {
|
||||
public class Tags {
|
||||
// Test life-cycle
|
||||
public class Lifecycle {
|
||||
public static final String INDEVEL = "in-dev";
|
||||
public static final String INTEST = "in-test";
|
||||
public static final String INPRODUCTION = "in-production";
|
||||
public static final String DEPRECATED = "deprecated";
|
||||
}
|
||||
|
||||
// Type of test
|
||||
public class Type {
|
||||
public static final String DIGITAL = "digital";
|
||||
public static final String ANALOG = "analog";
|
||||
public static final String COMMANDBASED = "command-based-robot";
|
||||
public static final String PWM = "pwm";
|
||||
public static final String PREFERENCES = "preferences";
|
||||
public static final String NETWORKTABLES = "networktables";
|
||||
}
|
||||
}
|
||||
|
||||
public void robotInit() {
|
||||
System.out.println("!!! WAITING FOR ENABLE");
|
||||
}
|
||||
/**
|
||||
* This function is called once each time the robot enters autonomous mode.
|
||||
*/
|
||||
public void autonomous() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called once each time the robot enters operator control.
|
||||
*/
|
||||
public void operatorControl() {
|
||||
System.out.println("!!! TESTS BEGINNING");
|
||||
|
||||
runTests();
|
||||
|
||||
System.out.println("!!! TESTS COMPLETE");
|
||||
}
|
||||
|
||||
private void runTests() {
|
||||
// Uncomment line below to run tests that are not yet trustworthy
|
||||
// Do not check this in!
|
||||
//TestClass.runAllWithTag(Tags.Lifecycle.INDEVEL);
|
||||
// Uncomment line below to run tests related to networktables
|
||||
// Do not check this in!
|
||||
//TestClass.runAllWithTag(Tags.Type.NETWORKTABLES);
|
||||
TestClass.runAllWithTag(Tags.Lifecycle.INTEST);
|
||||
TestClass.runAllWithTag(Tags.Lifecycle.INPRODUCTION);
|
||||
|
||||
System.out.println("##### The following tests (if any) are deprecated #####");
|
||||
//TestClass.runAllWithTag(Tags.Lifecycle.DEPRECATED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package edu.wpi.first.wpilibj.unittests;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
|
||||
/**
|
||||
* A class to simulate a simple command
|
||||
* The command keeps track of how many times each method was called
|
||||
*
|
||||
* @author mwills
|
||||
*/
|
||||
public class TestCommand extends Command{
|
||||
private int initializeCount = 0;
|
||||
private int executeCount = 0;
|
||||
private int isFinishedCount = 0;
|
||||
private boolean hasFinished = false;
|
||||
private int endCount = 0;
|
||||
private int interruptedCount = 0;
|
||||
|
||||
protected void initialize() {
|
||||
++initializeCount;
|
||||
}
|
||||
|
||||
protected void execute() {
|
||||
++executeCount;
|
||||
}
|
||||
|
||||
protected boolean isFinished() {
|
||||
++isFinishedCount;
|
||||
return isHasFinished();
|
||||
}
|
||||
|
||||
protected void end() {
|
||||
++endCount;
|
||||
}
|
||||
|
||||
protected void interrupted() {
|
||||
++interruptedCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return how many times the initialize method has been called
|
||||
*/
|
||||
public int getInitializeCount() {
|
||||
return initializeCount;
|
||||
}
|
||||
/**
|
||||
* @return if the initialize method has been called at least once
|
||||
*/
|
||||
public boolean hasInitialized(){
|
||||
return getInitializeCount()>0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many time the execute method has been called
|
||||
*/
|
||||
public int getExecuteCount() {
|
||||
return executeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many times the isFinished method has been called
|
||||
*/
|
||||
public int getIsFinishedCount() {
|
||||
return isFinishedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return what value the isFinished method will return
|
||||
*/
|
||||
public boolean isHasFinished() {
|
||||
return hasFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param set what value the isFinished method will return
|
||||
*/
|
||||
public void setHasFinished(boolean hasFinished) {
|
||||
this.hasFinished = hasFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many times the end method has been called
|
||||
*/
|
||||
public int getEndCount() {
|
||||
return endCount;
|
||||
}
|
||||
/**
|
||||
* @return if the end method has been called at least once
|
||||
*/
|
||||
public boolean hasEnd(){
|
||||
return getEndCount()>0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many times the interrupted method has been called
|
||||
*/
|
||||
public int getInterruptedCount() {
|
||||
return interruptedCount;
|
||||
}
|
||||
/**
|
||||
* @return if the interrupted method has been called at least once
|
||||
*/
|
||||
public boolean hasInterrupted(){
|
||||
return getInterruptedCount()>0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user