Skip to content
This repository has been archived by the owner on Dec 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #43 from HappyBlueberry/master
Browse files Browse the repository at this point in the history
ImproveWheelSystemTest and change ramping constant to 0.6
  • Loading branch information
LoadingPleaseWait committed Feb 24, 2016
2 parents 288107e + 82d0517 commit ae13655
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/org/impact2585/frc2016/systems/WheelSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class WheelSystem implements RobotSystem, Runnable{
private double currentRampForward;
private double rotationValue;
public static final double DEADZONE = 0.15;
public static final double RAMP = 0.5;
public static final double RAMP = 0.6;
private InputMethod input;
private boolean inverted;
private boolean prevInvert;
Expand Down
135 changes: 91 additions & 44 deletions test/org/impact2585/frc2016/tests/WheelSystemTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.impact2585.frc2016.tests;


import org.impact2585.frc2016.input.InputMethod;
import org.impact2585.frc2016.systems.WheelSystem;
import org.junit.Assert;
Expand All @@ -17,8 +16,18 @@ public class WheelSystemTest {
private double currentRampForward;
private double rotate;
private boolean invert;



/**
* method to calculate the ramping
* @return correct ramping
*/
public double rampForward() {
double realRampForward = (currentRampForward - driveForward) * WheelSystem.RAMP + currentRampForward;
if (driveForward < WheelSystem.DEADZONE && driveForward > -WheelSystem.DEADZONE)
realRampForward = 0;
return -realRampForward;
}

/**
* Initializes the test wheel system and input
*/
Expand All @@ -38,92 +47,121 @@ public void setUp() {
*/
@Test
public void test() {

//tests if the robot isn't moving at the start

// tests if the robot isn't moving at the start
double ramp = rampForward();
ramp = rampForward();
drivetrain.run();
Assert.assertTrue(currentRampForward == 0 && rotate == 0);
//tests deadzone

// tests deadzone
driveForward = 0.14;
rotate = 0.14;
ramp = rampForward();
drivetrain.run();
Assert.assertTrue(currentRampForward == 0 && rotate == 0);
//tests forward driving

// tests forward driving
driveForward = -0.5;
ramp = rampForward();
drivetrain.run();
Assert.assertTrue(-0.25 == currentRampForward && rotate == 0);

//tests turning and if currentRampForward immediately goes to 0 if the input is 0
Assert.assertTrue(ramp == currentRampForward && rotate == 0);

// tests turning and if currentRampForward immediately goes to 0 if the input is 0

rotate = 1;
driveForward = 0;
ramp = rampForward();
drivetrain.run();
Assert.assertTrue(currentRampForward == 0 && rotate == 1);

//tests turning and driving simultaneously


// tests turning and driving simultaneously
rotate = 1;
driveForward = 0.5;
drivetrain.setCurrentRampForward(0);
ramp = rampForward();
drivetrain.run();
Assert.assertTrue(currentRampForward == 0.25 && rotate == 1);
//tests invert
Assert.assertTrue(currentRampForward == ramp && rotate == 1);

// tests invert
invert = true;
rotate = -0.5;
driveForward = 0.5;
ramp = rampForward();
drivetrain.run();
Assert.assertTrue(currentRampForward == -0.125 && rotate == -0.5);
//tests if it does not invert if the button is still pressed
Assert.assertTrue(currentRampForward == ramp && rotate == -0.5);


// tests if it does not invert if the button is still pressed
invert = true;
rotate = -0.5;
driveForward = 0.5;
drivetrain.setCurrentRampForward(0.5);
ramp = rampForward();
drivetrain.setCurrentRampForward(-0.5);
drivetrain.run();
Assert.assertTrue(currentRampForward == -0.3125 && rotate == -0.5);
//tests if drivetrain continues to be inverted
Assert.assertTrue(currentRampForward == ramp && rotate == -0.5);

// tests if drivetrain continues to be inverted
invert = false;
rotate = -0.5;
driveForward = 0.5;
drivetrain.setCurrentRampForward(0.5);
ramp = rampForward();
drivetrain.setCurrentRampForward(-0.5);
drivetrain.run();
Assert.assertTrue(currentRampForward == -0.40625 && rotate == -0.5);
//tests if it inverts to the original position
Assert.assertTrue(currentRampForward == ramp && rotate == -0.5);

// tests if it inverts to the original position
invert = true;
rotate = 0.7;
driveForward = 0.5;
drivetrain.setCurrentRampForward(0.5);
ramp = rampForward();
drivetrain.setCurrentRampForward(0.5);
drivetrain.run();
Assert.assertTrue(currentRampForward == 0.046875 && rotate == 0.7);
Assert.assertTrue(currentRampForward == -ramp && rotate == 0.7);

// see if movement and rotation go back to 0 again
rotate = driveForward = 0;
drivetrain.setCurrentRampForward(0.5);
ramp = rampForward();
drivetrain.setCurrentRampForward(0.5);
drivetrain.run();
Assert.assertTrue(currentRampForward == 0 && rotate == 0);
Assert.assertTrue(currentRampForward == ramp && rotate == 0);
}

/**
* testable version of wheelsystem
*/
private class TestWheelSystem extends WheelSystem {

/* (non-Javadoc)
* @see org.impact2585.frc2016.systems.WheelSystem#setInput(org.impact2585.frc2016.input.InputMethod)
/*
* (non-Javadoc)
*
* @see
* org.impact2585.frc2016.systems.WheelSystem#setInput(org.impact2585.
* frc2016.input.InputMethod)
*/
@Override
protected synchronized void setInput(InputMethod controller) {
super.setInput(controller);
}

/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.impact2585.frc2016.systems.WheelSystem#getInput()
*/
@Override
public InputMethod getInput() {
return super.getInput();
}

/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.impact2585.frc2016.systems.WheelSystem#drive(double, double)
*/
@Override
Expand All @@ -132,46 +170,55 @@ public void drive(double movement, double currentRotate) {
rotate = currentRotate;
}

/* (non-Javadoc)
* @see org.impact2585.frc2016.systems.WheelSystem#setCurrentRampForward(double)
/*
* (non-Javadoc)
*
* @see
* org.impact2585.frc2016.systems.WheelSystem#setCurrentRampForward(
* double)
*/
@Override
public void setCurrentRampForward(double rampForward) {
super.setCurrentRampForward(rampForward);
currentRampForward = rampForward;
}

}

/**
* input version for testing
*/
private class InputTest extends InputMethod {

/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.impact2585.frc2016.input.InputMethod#forwardMovement()
*/
@Override
public double forwardMovement() {
return driveForward;
}

/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.impact2585.frc2016.input.InputMethod#getInvert()
*/
@Override
public boolean invert() {
return invert;
}

/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.impact2585.frc2016.input.InputMethod#rotationValue()
*/
@Override
public double rotationValue() {
return rotate;
}

}
}

0 comments on commit ae13655

Please sign in to comment.