From: mixxlto Date: Thu, 15 Jan 2026 05:26:18 +0000 (-0800) Subject: Merge branch 'shooter-calcs' of https://github.com/iron-claw-972/FRC2026 into shooter... X-Git-Url: https://git.taranathan.com/?a=commitdiff_plain;h=e7653f29c260dcfe9b77d6a0c78331d8c84ce617;p=FRC2026.git Merge branch 'shooter-calcs' of https://github.com/iron-claw-972/FRC2026 into shooter-calcs --- e7653f29c260dcfe9b77d6a0c78331d8c84ce617 diff --cc src/main/java/frc/robot/util/ShooterPhysics.java index 8d0ce40,d5b6759..39170de --- a/src/main/java/frc/robot/util/ShooterPhysics.java +++ b/src/main/java/frc/robot/util/ShooterPhysics.java @@@ -59,14 -57,47 +59,47 @@@ class ShooterPhysics if (t < 0) throw new RuntimeException("Time should never be negative (got t=" + t + ")."); - // calculate x and z impulse - // x = (v_x_robot + v_x_impulse) * t - // x_target = (v_x_robot + v_x_impulse) * t_target - // v_x_robot + v_x_impulse = x_target / t_target - // v_x_impulse = x_target / t_target - v_x_robot - double xImpulse = target.getX() / t - initialVelocity.getX(); + // calculate x and z exit_vel + // x = (v_x_robot + v_x_exit_vel) * t + // x_target = (v_x_robot + v_x_exit_vel) * t_target + // v_x_robot + v_x_exit_vel = x_target / t_target + // v_x_exit_vel = x_target / t_target - v_x_robot + double xExit_vel = target.getX() / t - robotVelocity.getX(); // same for y - double yImpulse = target.getY() / t - initialVelocity.getY(); - return new Translation3d(xImpulse, yImpulse, zImpulse); + double yExit_vel = target.getY() / t - robotVelocity.getY(); + return new Translation3d(xExit_vel, yExit_vel, zExit_vel); } + + // call with default tolerance - public static Optional getImpulseForSpeed(Translation2d initialVelocity, Translation3d target, ++ public static Optional getExitVelocityForSpeed(Translation2d initialVelocity, Translation3d target, + double speed) { - return getImpulseForSpeed(initialVelocity, target, speed, 0.1); ++ return getExitVelocityForSpeed(initialVelocity, target, speed, 0.1); + } + - public static Optional getImpulseForSpeed(Translation2d initialVelocity, Translation3d target, ++ public static Optional getExitVelocityForSpeed(Translation2d initialVelocity, Translation3d target, + double speed, double tolerance) { + + // TODO: detect when the given velocity is insufficient and exit before maxIters + + // guess a peak height + double guess = 10; + int maxIters = 20; + while (maxIters >= 0) { + maxIters--; - Translation3d guessVelocity = getRequiredImpulse(initialVelocity, target, guess); ++ Translation3d guessVelocity = getRequiredExitVelocity(initialVelocity, target, guess); + double guessSpeed = guessVelocity.getNorm(); + double difference = speed - guessSpeed; + + // we've already hit zero height and are trying to go lower + if (guess <= 0 && difference < 0) + return Optional.empty(); + + if (Math.abs(difference) <= tolerance) + return Optional.of(guessVelocity); + + guess += difference * 1.7; // experimentally determined value + } + + return Optional.empty(); + } }