|
| 1 | +package frc.robot.vision.commands; |
| 2 | + |
| 3 | +import static edu.wpi.first.units.Units.MetersPerSecond; |
| 4 | +import static edu.wpi.first.units.Units.MetersPerSecondPerSecond; |
| 5 | +import static edu.wpi.first.units.Units.RadiansPerSecond; |
| 6 | +import static edu.wpi.first.units.Units.RadiansPerSecondPerSecond; |
| 7 | + |
| 8 | +import com.ctre.phoenix6.swerve.SwerveRequest; |
| 9 | +import com.ctre.phoenix6.swerve.SwerveModule.DriveRequestType; |
| 10 | +import com.ctre.phoenix6.swerve.SwerveModule.SteerRequestType; |
| 11 | + |
| 12 | +import edu.wpi.first.math.controller.ProfiledPIDController; |
| 13 | +import edu.wpi.first.math.estimator.PoseEstimator; |
| 14 | +import edu.wpi.first.math.geometry.Pose2d; |
| 15 | +import edu.wpi.first.math.trajectory.TrapezoidProfile; |
| 16 | +import edu.wpi.first.wpilibj2.command.Command; |
| 17 | +import edu.wpi.first.wpilibj2.command.WaitCommand; |
| 18 | +import frc.robot.vision.PoseEstimatorSubsystem; |
| 19 | +import frc.robot.vision.VisionConfig; |
| 20 | + |
| 21 | +public class VisionCommands { |
| 22 | + |
| 23 | + public Command executeLineup() { |
| 24 | + Pose2d estimatedPose = PoseEstimatorSubsystem.getInstance().getCurrentPose(); |
| 25 | + |
| 26 | + //add ProfiledPID controllers for Translation and Rotation |
| 27 | + final TrapezoidProfile.Constraints TRANSLATION_CONSTRAINTS = new TrapezoidProfile.Constraints( |
| 28 | + VisionConfig.AlignmentConfig.MAX_ALIGN_TRANSLATION_VELOCITY.in(MetersPerSecond), |
| 29 | + VisionConfig.AlignmentConfig.MAX_ALIGN_TRANSLATION_ACCELERATION.in(MetersPerSecondPerSecond)); |
| 30 | + |
| 31 | + final TrapezoidProfile.Constraints THETA_CONSTRAINTS = new TrapezoidProfile.Constraints( |
| 32 | + VisionConfig.AlignmentConfig.MAX_ALIGN_ANGULAR_VELOCITY.in(RadiansPerSecond), |
| 33 | + VisionConfig.AlignmentConfig.MAX_ALIGN_ANGULAR_ACCELERATION.in(RadiansPerSecondPerSecond)); |
| 34 | + |
| 35 | + |
| 36 | + final ProfiledPIDController xDistanceController = new ProfiledPIDController( |
| 37 | + VisionConfig.AlignmentConfig.X_kP, |
| 38 | + VisionConfig.AlignmentConfig.X_kI, |
| 39 | + VisionConfig.AlignmentConfig.X_kD, |
| 40 | + TRANSLATION_CONSTRAINTS); |
| 41 | + |
| 42 | + final ProfiledPIDController yDistanceController = new ProfiledPIDController( |
| 43 | + VisionConfig.AlignmentConfig.Y_kP, |
| 44 | + VisionConfig.AlignmentConfig.Y_kI, |
| 45 | + VisionConfig.AlignmentConfig.Y_kD, |
| 46 | + TRANSLATION_CONSTRAINTS); |
| 47 | + |
| 48 | + final ProfiledPIDController thetaController = new ProfiledPIDController( |
| 49 | + VisionConfig.AlignmentConfig.THETA_kP, |
| 50 | + VisionConfig.AlignmentConfig.THETA_kI, |
| 51 | + VisionConfig.AlignmentConfig.THETA_kD, |
| 52 | + THETA_CONSTRAINTS); |
| 53 | + |
| 54 | + final SwerveRequest.RobotCentric robotCentricRequest = new SwerveRequest.RobotCentric() |
| 55 | + .withDriveRequestType(DriveRequestType.Velocity) |
| 56 | + .withSteerRequestType(SteerRequestType.MotionMagicExpo); |
| 57 | + |
| 58 | + |
| 59 | + return new WaitCommand(0); |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +} |
0 commit comments