Files
2026KPopRobotHunters/src/main/java/frc4388/robot/commands/Swerve/StayInPosition.java
T

53 lines
1.7 KiB
Java
Raw Normal View History

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){
translationX = 0.2;
2026-03-14 18:57:04 -06:00
}
2026-03-14 20:34:55 -06:00
if (translationY > 0.2){
translationY = 0.2;
2026-03-14 20:00:21 -06:00
}
if (Math.abs(translationX) < 0.01 && Math.abs(translationY) < 0.01) {
2026-03-14 18:57:04 -06:00
driveTranslation = new Translation2d();
} else {
2026-03-14 20:34:55 -06:00
driveTranslation = new Translation2d(translationX * 4.5, translationY * 4.5);
2026-03-14 18:57:04 -06:00
}
drive.driveFieldAngleSIP(driveTranslation, targetPose.getRotation());
2026-03-14 20:00:21 -06:00
// If above doesn't work
//drive.driveFieldAngle(driveTranslation, targetPose.getRotation());
2026-03-14 18:57:04 -06:00
}
@Override
public double getError() {
return 0;
}
@Override
public void runWithOutput(double output) {}
}