This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
371ffa3
commit f6228c6
Showing
6 changed files
with
94 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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 frc.robot.amp_align; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.localization.LocalizationSubsystem; | ||
import frc.robot.swerve.SwerveSubsystem; | ||
import frc.robot.util.scheduling.LifecycleSubsystem; | ||
import frc.robot.util.scheduling.SubsystemPriority; | ||
import java.util.List; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class AmpAlignManager extends LifecycleSubsystem { | ||
private final LocalizationSubsystem localization; | ||
private final SwerveSubsystem swerve; | ||
|
||
public AmpAlignManager(LocalizationSubsystem localization, SwerveSubsystem swerve) { | ||
super(SubsystemPriority.CLIMBER); | ||
|
||
this.localization = localization; | ||
this.swerve = swerve; | ||
} | ||
|
||
private AmpAlignPath getClosestTarget() { | ||
Pose2d current = localization.getPose(); | ||
|
||
List<AmpAlignPath> paths = AmpAlignPaths.PATHS; | ||
|
||
AmpAlignPath closest = AmpAlignPaths.PATHS.get(0); | ||
double currentDistance = Double.POSITIVE_INFINITY; | ||
|
||
for (AmpAlignPath target : paths) { | ||
double distance = | ||
target.behindAmpPose().getTranslation().getDistance(current.getTranslation()); | ||
if (distance < currentDistance) { | ||
closest = target; | ||
currentDistance = distance; | ||
} | ||
} | ||
return closest; | ||
} | ||
|
||
public Command getAlignForAmpCommand() { | ||
return swerve.driveToPoseCommand( | ||
() -> getClosestTarget().behindAmpPose(), localization::getPose); | ||
} | ||
|
||
@Override | ||
public void robotPeriodic() { | ||
Logger.recordOutput("AmpAlign/ClosestPose", getClosestTarget().behindAmpPose()); | ||
Logger.recordOutput( | ||
"AmpAlign/ClosestPathRotation", getClosestTarget().behindAmpPose().getRotation()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// 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 frc.robot.amp_align; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
|
||
public record AmpAlignPath(Pose2d behindAmpPose, Rotation2d robotHeading) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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 frc.robot.amp_align; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import java.util.List; | ||
|
||
public class AmpAlignPaths { | ||
public static final AmpAlignPath RED_AMP = | ||
new AmpAlignPath( | ||
new Pose2d(14.66, 7.32, Rotation2d.fromDegrees(-90)), Rotation2d.fromDegrees(-90)); | ||
public static final AmpAlignPath BLUE_AMP = | ||
new AmpAlignPath( | ||
new Pose2d(1.8, 7.19, Rotation2d.fromDegrees(-90)), Rotation2d.fromDegrees(-90)); | ||
|
||
public static final List<AmpAlignPath> PATHS = List.of(RED_AMP, BLUE_AMP); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters