-
Notifications
You must be signed in to change notification settings - Fork 13
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
auto alignment #109
Open
kirbt
wants to merge
14
commits into
robototes:main
Choose a base branch
from
kirbt:shuffleboard-alignment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
auto alignment #109
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8c3b93d
auto alignment
kirbt 782ac95
it workes yippee
kirbt 17f4818
spotless boohoo
kirbt 9ea898a
lower alignment tolerances
kirbt 1e912ef
Merge branch 'main' into shuffleboard-alignment
kirbt 1563ec8
merge conflict debug + spotless
kirbt b1e0732
enabled checker for alignment
kirbt bdb3202
Update src/main/java/frc/team2412/robot/util/auto/AutoAlignment.java
kirbt 4e99823
address pr
kirbt 0120baa
Merge branch 'shuffleboard-alignment' of https://github.com/kirbt/Cre…
kirbt 081a031
a
kirbt bd7fca9
spotless
kirbt 6641df1
Merge branch 'main' into shuffleboard-alignment
kirbt ec8fa8f
spotless + noob gaming merge
kirbt 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
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
107 changes: 107 additions & 0 deletions
107
src/main/java/frc/team2412/robot/util/auto/AutoAlignment.java
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,107 @@ | ||
package frc.team2412.robot.util.auto; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; | ||
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; | ||
import edu.wpi.first.wpilibj.smartdashboard.Field2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.FieldObject2d; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import frc.team2412.robot.Robot; | ||
import frc.team2412.robot.Subsystems; | ||
import java.util.function.Supplier; | ||
|
||
public class AutoAlignment { | ||
private static Robot r = Robot.getInstance(); | ||
private static final Subsystems s = r.subsystems; | ||
|
||
private static Supplier<Pose2d> currentPosition = s.drivebaseWrapper::getEstimatedPosition; | ||
private static Supplier<Pose2d> goalPosition = | ||
() -> AutoLogic.getSelectedAutoPath().getStartPose2d(); | ||
|
||
private static final double POSITION_TOLERANCE = 0.0254; // meters | ||
private static final double ROTATION_TOLERANCE = 3; // degrees | ||
|
||
private static Field2d field = new Field2d(); | ||
private static FieldObject2d robotPos; | ||
private static FieldObject2d robotGoalPos; | ||
private static ShuffleboardTab tab = Shuffleboard.getTab("AutoAlignment"); | ||
|
||
public static void initShuffleboard() { | ||
|
||
tab.addString("Current Position", () -> getPose2dString(currentPosition.get())) | ||
.withPosition(0, 0) | ||
.withSize(3, 1); | ||
|
||
tab.addString("Auto Starting Position", () -> getPose2dString(goalPosition.get())) | ||
.withPosition(0, 1) | ||
.withSize(3, 1); | ||
|
||
tab.addBoolean("Correct Horizontal Position", AutoAlignment::isRobotInCorrectHorizontalPosition) | ||
.withPosition(3, 0) | ||
.withSize(2, 1); | ||
tab.addBoolean("Correct Vertical Position", AutoAlignment::isRobotInCorrectVerticalPosition) | ||
.withPosition(3, 1) | ||
.withSize(2, 1); | ||
tab.addBoolean("Correct Rotation", AutoAlignment::isRobotInCorrectRotation) | ||
.withPosition(3, 2) | ||
.withSize(2, 1); | ||
|
||
tab.addBoolean("Correct Position", AutoAlignment::isRobotInCorrectPosition) | ||
.withPosition(5, 0) | ||
.withSize(2, 3); | ||
|
||
initField(); | ||
} | ||
|
||
private static boolean isRobotInCorrectPosition() { | ||
return (isRobotInCorrectHorizontalPosition() | ||
&& isRobotInCorrectVerticalPosition() | ||
&& isRobotInCorrectRotation()); | ||
} | ||
|
||
private static boolean isRobotInCorrectHorizontalPosition() { | ||
return MathUtil.isNear( | ||
currentPosition.get().getX(), goalPosition.get().getX(), POSITION_TOLERANCE); | ||
} | ||
|
||
private static boolean isRobotInCorrectVerticalPosition() { | ||
return MathUtil.isNear( | ||
currentPosition.get().getY(), goalPosition.get().getY(), POSITION_TOLERANCE); | ||
} | ||
|
||
private static boolean isRobotInCorrectRotation() { | ||
return MathUtil.isNear( | ||
currentPosition.get().getRotation().getDegrees(), | ||
goalPosition.get().getRotation().getDegrees(), | ||
ROTATION_TOLERANCE); | ||
} | ||
|
||
private static String getPose2dString(Pose2d pose) { | ||
return "Translation: (" | ||
+ pose.getX() | ||
+ "m, " | ||
+ pose.getY() | ||
+ "m) | Rotation: (" | ||
+ pose.getRotation().getDegrees() | ||
+ " deg.)"; | ||
} | ||
|
||
private static void initField() { | ||
field = new Field2d(); | ||
|
||
SmartDashboard.putData("AlignmentField", field); | ||
tab.add("Alignment Field", field).withPosition(7, 0).withSize(4, 3); | ||
|
||
robotPos = field.getObject("Robot"); | ||
robotGoalPos = field.getObject("AutoStartPosition"); | ||
|
||
updateField(); | ||
} | ||
|
||
public static void updateField() { | ||
robotPos.setPose(s.drivebaseWrapper.getEstimatedPosition()); | ||
|
||
robotGoalPos.setPose(AutoLogic.getSelectedAutoPath().getStartPose2d()); | ||
} | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This can also be combined into the previous if statement).