public class TrenchAssist2 {
- // public void execute() {
- // trenchAlign = SmartDashboard.getBoolean("trench aligning", trenchAlign);
- // trenchAssist = SmartDashboard.getBoolean("trench aligning", trenchAssist);
-
- // SmartDashboard.putBoolean("trench aligning", trenchAlign);
- // SmartDashboard.putBoolean("trench assisting", trenchAssist);
-
- // double forwardTranslation = driver.getForwardTranslation();
- // double sideTranslation = driver.getSideTranslation();
- // double rotation = -driver.getRotation();
-
- // double slowFactor = driver.getIsSlowMode() ? DriveConstants.SLOW_DRIVE_FACTOR : 1;
-
- // forwardTranslation *= slowFactor;
- // sideTranslation *= slowFactor;
- // rotation *= driver.getIsSlowMode() ? DriveConstants.SLOW_ROT_FACTOR : 1;
-
- // int allianceReversal = Robot.getAlliance() == Alliance.Red ? 1 : -1;
- // forwardTranslation *= allianceReversal;
- // sideTranslation *= allianceReversal;
-
- // ChassisSpeeds driverInput = new ChassisSpeeds(forwardTranslation, sideTranslation, rotation);
- // ChassisSpeeds corrected = DriverAssist.calculate(drive, driverInput, drive.getDesiredPose(), true);
-
- // if (trenchAlign) {
- // for (Rectangle2d rectangle : TrenchAssistConstants.ALIGN_ZONES) {
- // if (rectangle.contains(drive.getPose().getTranslation())) {
- // drive.setIsAlign(true);
-
- // if (drive.getPose().getRotation().getDegrees() > 90
- // && drive.getPose().getRotation().getDegrees() < 270) {
- // drive.setAlignAngle(0.0);
- // } else if (drive.getPose().getRotation().getDegrees() > 270
- // && drive.getPose().getRotation().getDegrees() < 90) {
- // drive.setAlignAngle(Units.degreesToRadians(180));
- // }
- // } else {
- // drive.setIsAlign(false);
- // }
- // }
- // }
-
- // if (trenchAssist) {
- // Translation2d calculated = calculateCorrection(TrenchAssistConstants.OBSTACLES);
- // ChassisSpeeds assisted = new ChassisSpeeds(corrected.vxMetersPerSecond + calculated.getX(),
- // corrected.vyMetersPerSecond + calculated.getY(), corrected.omegaRadiansPerSecond);
-
- // drive(assisted);
- // } else {
- // drive(corrected);
- // }
-
- // }
-
- /**
- *
- * @param rectangle the rectangle that the ray should check against
- * @param point the origin point of the ray
- * @param velocity vector of the ray, magnitude is speed
- * @param time how far into the future to check
- * @return returns Optional full if intersects rectangle within time param into
- * future, time/100
- * second resolution for raymarching, returns distance that it hits it
- * at
- */
- public static Optional<Double> rayCast(Rectangle2d rectangle, Translation2d point, Translation2d velocity,
- double time) {
- // double distance = velocity.getNorm();
- // Translation2d normalized = new Translation2d(velocity.getX() / distance,
- // velocity.getY() / distance);
-
- for (int i = 0; i <= 100; i++) {
- double t = (i * time) / 100.0; // seconds into the future
- Translation2d ray = velocity.times(t).plus(point);
- if (rectangle.contains(ray)) {
- return Optional.of(t);
- }
- }
-
- return Optional.empty();
- }
-
-
-
- public static ChassisSpeeds funky(Drivetrain drive, ChassisSpeeds chassisSpeeds) {
- ChassisSpeeds speedsFieldRelative = ChassisSpeeds.fromRobotRelativeSpeeds(chassisSpeeds, drive.getYaw());
+ public static ChassisSpeeds calculate(Drivetrain drive, ChassisSpeeds chassisSpeeds) {
+ ChassisSpeeds speedsFieldRelative = ChassisSpeeds.fromRobotRelativeSpeeds(chassisSpeeds, drive.getYaw().unaryMinus()); //this singular unary minus is best we can get
ChassisSpeeds horizontalSpeeds = new ChassisSpeeds(speedsFieldRelative.vxMetersPerSecond, 0.0, speedsFieldRelative.omegaRadiansPerSecond);
Logger.recordOutput("slideTranslation", new Translation2d(horizontalSpeeds.vxMetersPerSecond, horizontalSpeeds.vyMetersPerSecond));
var x = new ChassisSpeeds(horizontalSpeeds.vxMetersPerSecond, horizontalSpeeds.vyMetersPerSecond, chassisSpeeds.omegaRadiansPerSecond);
- var y = new Translation2d(x.vxMetersPerSecond, x.vyMetersPerSecond).rotateBy(drive.getYaw().unaryMinus());
+ var y = new Translation2d(x.vxMetersPerSecond, x.vyMetersPerSecond).rotateBy(drive.getYaw());
return new ChassisSpeeds(y.getX(), y.getY(), x.omegaRadiansPerSecond);
}
- public static ChassisSpeeds calculate(Drivetrain drive, ChassisSpeeds chassisSpeeds) {
+ public static ChassisSpeeds funky(Drivetrain drive, ChassisSpeeds chassisSpeeds) {
double yawRadians = drive.getYaw().unaryMinus().getRadians();
double fieldRelativeX = chassisSpeeds.vxMetersPerSecond * Math.cos(yawRadians) - chassisSpeeds.vyMetersPerSecond * Math.sin(yawRadians);