import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.Constants;
import frc.robot.constants.FieldConstants;
+import frc.robot.constants.ShotInterpolation;
import frc.robot.subsystems.drivetrain.Drivetrain;
import frc.robot.subsystems.hood.Hood;
import frc.robot.subsystems.hood.HoodConstants;
import frc.robot.subsystems.shooter.Shooter;
import frc.robot.subsystems.spindexer.Spindexer;
-import frc.robot.constants.ShotInterpolation;
import frc.robot.subsystems.turret.Turret;
import frc.robot.subsystems.turret.TurretConstants;
import frc.robot.util.ShooterPhysics;
//drivepose = new Pose2d(drivepose.getTranslation(), drivepose.getRotation().plus(new Rotation2d(Math.PI)));
goalState = ShooterPhysics.getShotParams(
+ Translation2d.kZero,
FieldConstants.getHubTranslation().minus(new Translation3d(drivepose.getTranslation())),
8.0); // Random initial goalState to prevent it being null
for (int i = 0; i < 20; i++) {
Translation3d lookahead3d = new Translation3d(lookaheadPose.getX(), lookaheadPose.getY(), TurretConstants.DISTANCE_FROM_ROBOT_CENTER.getZ());
Translation3d target3d = new Translation3d(target.getX(), target.getY(), FieldConstants.getHubTranslation().getZ()); // Add if statement so that it's only when it's shooting
- goalState = ShooterPhysics.getShotParams(
+ var goalStateWithT = ShooterPhysics.getShotParamsWithT(
+ Translation2d.kZero,
target3d.minus(lookahead3d),
2.0);
+ goalState = goalStateWithT.getFirst();
- timeOfFlight = goalState.timeOfFlight();
+ timeOfFlight = goalStateWithT.getSecond();
double offsetX = turretVelocityX * timeOfFlight;
double offsetY = turretVelocityY * timeOfFlight;
lookaheadPose =
}
}
-}
\ No newline at end of file
+}
return cvtShot(exitVel, height);
}
+ // provided for backwards compatability
+ public static Pair<TurretState, Double> getShotParamsWithT(Translation2d robotVelocity, Translation3d robotToTarget,
+ double height) {
+ Translation3d exitVel = getRequiredExitVelocity(robotVelocity, robotToTarget, height);
+ double t = (-exitVel.getZ()
+ - Math.sqrt(Math.pow(exitVel.getZ(), 2) - 2 * Constants.GRAVITY_ACCELERATION * robotToTarget.getZ()))
+ / -Constants.GRAVITY_ACCELERATION;
+ return new Pair<TurretState, Double>(cvtShot(exitVel, height), t);
+ }
+
/**
* Calculates shot parameters for SOTM for a peak height using Physics™.
*