2026-03-10 08:39:05 -06:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
|
|
|
|
package frc4388.robot.commands.Swerve;
|
|
|
|
|
|
2026-03-14 20:00:21 -06:00
|
|
|
import org.littletonrobotics.junction.Logger;
|
|
|
|
|
import org.littletonrobotics.junction.AutoLogOutput;
|
|
|
|
|
|
2026-03-10 08:39:05 -06:00
|
|
|
import edu.wpi.first.math.geometry.Pose2d;
|
|
|
|
|
import edu.wpi.first.math.geometry.Translation2d;
|
|
|
|
|
import frc4388.robot.commands.PID;
|
|
|
|
|
import frc4388.robot.subsystems.swerve.SwerveDrive;
|
|
|
|
|
|
|
|
|
|
public class StayInPosition extends PID {
|
2026-03-14 18:57:04 -06:00
|
|
|
SwerveDrive drive;
|
2026-03-14 20:00:21 -06:00
|
|
|
Translation2d driveTranslation = new Translation2d();
|
2026-03-14 18:57:04 -06:00
|
|
|
|
|
|
|
|
public StayInPosition(SwerveDrive drive) {
|
|
|
|
|
super(0.3, 0.0, 0.0, 0.0, 1);
|
|
|
|
|
this.drive = drive;
|
|
|
|
|
addRequirements(drive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void goToTargetPose(Pose2d targetPose) {
|
|
|
|
|
Pose2d currentPose = drive.getCurrentPose();
|
|
|
|
|
double translationX = targetPose.getX() - currentPose.getX();
|
|
|
|
|
double translationY = targetPose.getY() - currentPose.getY();
|
2026-03-14 20:34:55 -06:00
|
|
|
if (translationX > 0.2){
|
2026-03-14 20:39:45 -06:00
|
|
|
//If below is changed make this change too so it never goes over 1
|
2026-03-14 20:34:55 -06:00
|
|
|
translationX = 0.2;
|
2026-03-14 18:57:04 -06:00
|
|
|
}
|
2026-03-14 20:34:55 -06:00
|
|
|
if (translationY > 0.2){
|
2026-03-14 20:39:45 -06:00
|
|
|
//Same here
|
2026-03-14 20:34:55 -06:00
|
|
|
translationY = 0.2;
|
2026-03-14 20:00:21 -06:00
|
|
|
}
|
2026-03-20 15:40:07 -06:00
|
|
|
if (Math.abs(translationX) < 0.08 && Math.abs(translationY) < 0.08) {
|
2026-03-14 18:57:04 -06:00
|
|
|
driveTranslation = new Translation2d();
|
|
|
|
|
} else {
|
2026-03-14 20:39:45 -06:00
|
|
|
//TODO: Tweak for best corrector against another bot
|
|
|
|
|
driveTranslation = new Translation2d(translationX * 4.5, translationY * 4.5);
|
2026-03-14 18:57:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drive.driveFieldAngleSIP(driveTranslation, targetPose.getRotation());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double getError() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void runWithOutput(double output) {}
|
|
|
|
|
}
|