public static TurretState withMinimumSpeed(Translation2d initialVelocity, Translation3d target,
double tolerance) {
// System.out.println("!!! inv:" + initialVelocity + " tgt:" + target + " tlr:"
- // + tolerance);
+ // + tolerance);
// trying to calculate a shot for height=0 returns NaN
double effectiveMinHeight = Math.max(target.getZ(), 0.01);
TurretState first = cvtShot(getRequiredExitVelocity(initialVelocity, target, effectiveMinHeight),
effectiveMinHeight);
- // if the minimum velocity is below our minimum height, that's the closest we can get
+ // if the minimum velocity is below our minimum height, that's the closest we
+ // can get
if (getVelocityDiff(first, initialVelocity, target) >= 0)
return first;
// if a shot requires going up a kilometer, it's probably not doable
TurretState second = cvtShot(getRequiredExitVelocity(initialVelocity, target, 1000.), 1000.);
- if (first.pitch() > pitch + tolerance)
- return Optional.empty();
+ if (first.pitch() > pitch)
+ if (first.pitch() <= pitch + tolerance)
+ return Optional.of(first);
+ else
+ return Optional.empty();
else if (second.pitch() < pitch)
return Optional.of(second); // it's close enough
return Optional.of(guess);
// we've narrowed the range but haven't found a valid angle
// should be covered by the checks before the loop
- assert false;
+ throw new RuntimeException(
+ "Solving for angle resulted in an empty range " + range + " (pitch: " + pitch + ").");
}
if (guess.pitch() > pitch)
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import edu.wpi.first.math.geometry.Rotation2d;
}
}
- @Disabled
@Test
public void simulatedConstraintsTest() {
Random rng = new Random(6328);
// check going down breaks a constraint; we've found the minimum
var lower = ShooterPhysics.withAngle(initVel, robotToTarget, state.get().pitch() - .1);
- assertTrue(lower.isEmpty());
+ assertTrue(lower.isEmpty() || !lower.get().satisfies(constraints));
// check going up is okay
- var higher = ShooterPhysics.withAngle(initVel, robotToTarget, state.get().pitch() + .1);
- assertTrue(higher.isPresent());
+ if (state.get().pitch() + 0.1 < constraints.maxPitch()) {
+ var higher = ShooterPhysics.withAngle(initVel, robotToTarget, state.get().pitch() + .1);
+ assertTrue(higher.isPresent());
+ }
}
}
}