-
Notifications
You must be signed in to change notification settings - Fork 7
Algae automatic height switching #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a374024
New command that in theory changes the algae intake command based on …
Jetblackdragon 7f8c421
Change so auto evelator movements get canceled when you have a game p…
TrisDooley 9ce9866
oops i did withtimeout instead of until
Jetblackdragon 311ce02
spot
Jetblackdragon 49cb5bc
spotspot
Jetblackdragon b91070c
AutoAlgaeHeights Working
RobototesProgrammers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
104 changes: 104 additions & 0 deletions
104
src/main/java/frc/robot/subsystems/auto/AutoAlgaeHeights.java
This file contains hidden or 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,104 @@ | ||
package frc.robot.subsystems.auto; | ||
|
||
import edu.wpi.first.apriltag.AprilTagFieldLayout; | ||
import edu.wpi.first.apriltag.AprilTagFields; | ||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
import edu.wpi.first.wpilibj.DriverStation.Alliance; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.Controls; | ||
import frc.robot.subsystems.SuperStructure; | ||
import frc.robot.subsystems.drivebase.CommandSwerveDrivetrain; | ||
import frc.robot.util.ScoringMode; | ||
import java.util.List; | ||
|
||
/** | ||
* Command that automatically moves the elevator to the proper height for the nearest algae based on | ||
* alliance and current robot pose. | ||
*/ | ||
public class AutoAlgaeHeights extends Command { | ||
|
||
private final CommandSwerveDrivetrain drivebase; | ||
private final SuperStructure s; | ||
private final Controls c; | ||
|
||
private static final AprilTagFieldLayout aprilTagFieldLayout = | ||
AprilTagFieldLayout.loadField(AprilTagFields.k2025ReefscapeWelded); | ||
|
||
private static final List<Pose2d> blueAlgaePoses = | ||
List.of( | ||
aprilTagFieldLayout.getTagPose(17).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(19).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(21).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(18).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(20).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(22).get().toPose2d()); | ||
|
||
private static final List<Pose2d> redAlgaePoses = | ||
List.of( | ||
aprilTagFieldLayout.getTagPose(6).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(8).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(10).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(7).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(9).get().toPose2d(), | ||
aprilTagFieldLayout.getTagPose(11).get().toPose2d()); | ||
|
||
public AutoAlgaeHeights(CommandSwerveDrivetrain drivebase, SuperStructure s, Controls c) { | ||
this.drivebase = drivebase; | ||
this.s = s; | ||
this.c = c; | ||
} | ||
|
||
public static Command autoAlgaeIntakeCommand( | ||
CommandSwerveDrivetrain drivebase, SuperStructure s, Controls c) { | ||
return new AutoAlgaeHeights(drivebase, s, c); | ||
} | ||
|
||
private static boolean isBlue() { | ||
return DriverStation.getAlliance() | ||
.map(alliance -> alliance.equals(Alliance.Blue)) | ||
.orElse(false); | ||
} | ||
|
||
private static Pose2d getNearestAlgae(Pose2d robotPose) { | ||
List<Pose2d> poses = isBlue() ? blueAlgaePoses : redAlgaePoses; | ||
return robotPose.nearest(poses); | ||
} | ||
|
||
private String aprilTagToAlgaeHeight(Pose2d algaePose) { | ||
// Map poses to two heights only | ||
List<Pose2d> poses = isBlue() ? blueAlgaePoses : redAlgaePoses; | ||
int index = poses.indexOf(algaePose); | ||
|
||
if (index >= 3) { | ||
return "top"; // upper reef | ||
} else { | ||
return "low"; // lower reef | ||
} | ||
} | ||
|
||
private String activeCommand = ""; | ||
|
||
@Override | ||
public void execute() { | ||
Pose2d robotPose = drivebase.getState().Pose; | ||
Pose2d nearestAlgae = getNearestAlgae(robotPose); | ||
|
||
String targetHeight = aprilTagToAlgaeHeight(nearestAlgae); | ||
|
||
if (!(activeCommand.equals(targetHeight))) { | ||
if (targetHeight.equals("top")) { | ||
s.algaeLevelThreeFourIntake().schedule(); | ||
activeCommand = "top"; | ||
} else { | ||
s.algaeLevelTwoThreeIntake().schedule(); | ||
activeCommand = "low"; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return c.intakeMode != ScoringMode.ALGAE; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.