Skip to content

Commit

Permalink
fixed one test case...
Browse files Browse the repository at this point in the history
  • Loading branch information
maxspier committed Nov 22, 2023
1 parent 08f3f74 commit dec3fa8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AutomaticShooterPowerCalibration {
private double latestDistance = -1;
private double lastDistance = 0;

private boolean first = true;


public AutomaticShooterPowerCalibration(int tagId) {
Expand Down Expand Up @@ -58,9 +59,8 @@ public double shootAndCalculate() {
double power = 0;

if(powersTried.size() == 0){
if(powersWork.size() <= 1){
power = Math.random();
}else{

//Find a value near the current distance in the distancesWork array
//Then compute a new value for power according to what works
double closestOnMin = distancesWork.get(0);
Expand All @@ -86,7 +86,7 @@ public double shootAndCalculate() {
double differenceFromMin = distance - closestOnMin;

power = powersWork.get(indexMin) + (differenceFromMin / difference) * powerDifference;
}

} else {
if(powersTried.size() == 1){
if(wasTooLong.get(0)){
Expand Down Expand Up @@ -149,13 +149,8 @@ public double shootAndCalculate(double givenDistance) {

double power = 0;

if(powersTried.size() == 0){
if(powersWork.size() <= 1){
power = Math.random();
}else{
//Find a value near the current distance in the distancesWork array
//Then compute a new value for power according to what works
double closestOnMin = distancesWork.get(0);
if(first && distancesWork.size() > 2){
double closestOnMin = distancesWork.get(0);
double closestOnMax = distancesWork.get(0);

int indexMin = 0;
Expand All @@ -178,7 +173,13 @@ public double shootAndCalculate(double givenDistance) {
double differenceFromMin = distance - closestOnMin;

power = powersWork.get(indexMin) + (differenceFromMin / difference) * powerDifference;
}

powersTried.add(power);
return power;
}

if(powersTried.size() == 0){
power = Math.random();
} else {
if(powersTried.size() == 1){
if(wasTooLong.get(0)){
Expand Down Expand Up @@ -225,7 +226,7 @@ public double shootAndCalculate(double givenDistance) {

}
powersTried.add(power);
Robot.shooter.shoot(power); //TODO: Make sure this runs for ample time so ball can actually be shot
// commented for tests Robot.shooter.shoot(power); //TODO: Make sure this runs for ample time so ball can actually be shot


return power;
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/com/team766/shooter/ShooterTestCase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.team766.shooter;

import static org.junit.Assert.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
Expand All @@ -13,19 +14,20 @@

import edu.wpi.first.wpilibj.Filesystem;

public abstract class ShooterTestCase extends junit.framework.TestCase {

ArrayList<Double> distancesToTest = new ArrayList<Double>();
ArrayList<Double> powersThatWork = new ArrayList<Double>();
public class ShooterTestCase{

AutomaticShooterPowerCalibration calibration;
static ArrayList<Double> distancesToTest = new ArrayList<Double>();
static ArrayList<Double> powersThatWork = new ArrayList<Double>();

static AutomaticShooterPowerCalibration calibration;
Scanner input;

//@Rule
//public ExpectedException exception = ExpectedException.none();

@BeforeAll
public void setUp() throws Exception {
public static void setUp() throws Exception {


calibration = new AutomaticShooterPowerCalibration(3);
Expand Down Expand Up @@ -94,7 +96,7 @@ protected void isCorrect(){
for(int i = 0; i < ((distancesToTest.size() * 2) - 1); i+=2){
double distance = input.nextDouble();

assertEquals("Distances tested need to equal each other", distancesToTest.get(i), distance);
assertEquals("Distances tested need to equal each other", (double)distancesToTest.get(i), distance);

double power = input.nextDouble();
System.out.println(power);
Expand Down

0 comments on commit dec3fa8

Please sign in to comment.