-
Notifications
You must be signed in to change notification settings - Fork 0
RM_Loggable_Autochooser #28
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
28 commits
Select commit
Hold shift + click to select a range
467966d
Added code from last year for the autochooser (broken).
The-Cool-Python-Guy d2039a9
The autochooser now has a basic errorless implementation.
The-Cool-Python-Guy f1ab6b7
Refactored AutoChooser2025 as AutoChooser2026.
The-Cool-Python-Guy b018e4a
Fixed bug that silently passed null as a providerIO.
The-Cool-Python-Guy 6e8d5c3
Merge branch 'main' of https://github.com/FRC4048/Java_2026 into RM_L…
The-Cool-Python-Guy b562a11
Implemented the AdvantageKit Autochooser.
The-Cool-Python-Guy 9c2f9a9
Added chooser to robotContainer and fixed some errors.
The-Cool-Python-Guy 9cc422e
Added "DoSomethingCommand" for harmless visible output.
The-Cool-Python-Guy 72423d9
Largened print message for DoSomethingCommand for better visibility i…
The-Cool-Python-Guy c055bf5
Deleted old autochooser files, cleaned up branch.
The-Cool-Python-Guy c72e11a
Merge branch 'main' into RM_LoggableAutochooser
The-Cool-Python-Guy 28f384d
Merge branch 'main' into RM_LoggableAutochooser
The-Cool-Python-Guy 8e7767e
I made the AutoChooser extend LoggedDashboardChooser rather than be a…
The-Cool-Python-Guy 7228f1c
Merge branch 'main' into RM_LoggableAutochooser
The-Cool-Python-Guy febd78c
Fixed error due to changing the name of a method.
The-Cool-Python-Guy 7589b95
Created two choosers instead of one to clean up the interface on elas…
The-Cool-Python-Guy 8b6eb6d
Set up an area on the elastic dashboard for visual feedback on the se…
The-Cool-Python-Guy 31293b6
Merge branch 'main' into RM_LoggableAutochooser
The-Cool-Python-Guy ae8f723
Got rid of unnecessary things.
The-Cool-Python-Guy 10475f7
Differentiated between 'nothing' and 'invalid' for AutoCommand, and m…
The-Cool-Python-Guy 38a6ccd
Added methods for getting the location of the robot.
The-Cool-Python-Guy 5d1988a
Merge branch 'main' into RM_LoggableAutochooser
The-Cool-Python-Guy 3245a6c
Cleaned indentation in RobotContainer.
The-Cool-Python-Guy 5bbec3d
I cleaned up unnecessary changes to RobotContainer, some small whites…
The-Cool-Python-Guy 1b9da62
Merge branch 'main' into RM_LoggableAutochooser
The-Cool-Python-Guy b7e1e32
Clean up merge.
The-Cool-Python-Guy 7bb6c91
Made a getter for the starting position.
The-Cool-Python-Guy 09f4f94
Reimplemented equals() ans hashCode() so that the AutoEvent class can…
The-Cool-Python-Guy 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
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
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,37 @@ | ||
| package frc.robot.autochooser; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public enum AutoAction { | ||
| DO_NOTHING("Do Nothing"), | ||
| TWO_PIECE_HIGH("2 Piece L4"), | ||
| TWO_PIECE_LOW("2 Piece L2"), | ||
| ONE_PIECE("1 Piece"), | ||
| CROSS_THE_LINE("Cross The Line"), | ||
| INVALID("INVALID"); | ||
| private final String name; | ||
| private static final HashMap<String, AutoAction> nameMap = | ||
| new HashMap<>( | ||
| Arrays.stream(AutoAction.values()) | ||
| .collect(Collectors.toMap(AutoAction::getName, Function.identity()))); | ||
|
|
||
| AutoAction(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return getName(); | ||
| } | ||
|
|
||
| public static AutoAction fromName(String name) { | ||
| return nameMap.get(name); | ||
| } | ||
| } |
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,85 @@ | ||
| package frc.robot.autochooser; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.littletonrobotics.junction.networktables.LoggedDashboardChooser; | ||
|
|
||
| import frc.robot.utils.logging.commands.LoggableCommand; | ||
|
|
||
| public class AutoChooser { | ||
|
|
||
| /** Drop-down chooser for the location. */ | ||
| private LoggedDashboardChooser<FieldLocation> locationChooser; | ||
| /** Drop-down chooser for the action. */ | ||
| private LoggedDashboardChooser<AutoAction> actionChooser; | ||
| /** Structure for mapping possible choices to commands. */ | ||
| private final Map<AutoEvent, AutoCommand> commandMap = new HashMap<>(); | ||
|
|
||
| private final AutoCommand DEFAULT_COMMAND = AutoCommand.Invalid; | ||
|
|
||
| public AutoChooser() { | ||
| this.locationChooser = new LoggedDashboardChooser<>( | ||
| "Location Chooser" | ||
| ); | ||
| this.actionChooser = new LoggedDashboardChooser<>( | ||
| "Action Chooser" | ||
| ); | ||
| populateChoosers(); | ||
| populateMap(); | ||
| } | ||
|
|
||
| /** Populates the drop-down choosers with enum constants. */ | ||
| private void populateChoosers() { | ||
| for (FieldLocation location : FieldLocation.values()) { | ||
| switch (location) { | ||
| case INVALID -> {} // Skip the invalid case. | ||
| case ZERO -> { // Default | ||
| locationChooser.addDefaultOption(location.toString(), location); | ||
| } | ||
| default -> {locationChooser.addOption(location.toString(), location);} | ||
| }; | ||
| } | ||
| for (AutoAction action : AutoAction.values()) { | ||
| switch (action) { | ||
| case INVALID -> {} // Skip the invalid case. | ||
| case DO_NOTHING -> { // Default | ||
| actionChooser.addDefaultOption(action.toString(), action); | ||
| } | ||
| default -> {actionChooser.addOption(action.toString(), action);} | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| /** Put mappings here. | ||
| * @see AutoCommand */ | ||
| private void populateMap() { | ||
| // Currently, we have some example mappings. | ||
| commandMap.put(new AutoEvent(AutoAction.DO_NOTHING, FieldLocation.LEFT), | ||
| AutoCommand.DoNothing); | ||
| commandMap.put(new AutoEvent(AutoAction.DO_NOTHING, FieldLocation.RIGHT), | ||
| AutoCommand.DoSomething); | ||
| } | ||
|
|
||
| private AutoCommand get() { | ||
| AutoAction chosenAction = actionChooser.get(); | ||
| FieldLocation chosenLocation = locationChooser.get(); | ||
| AutoEvent event = new AutoEvent(chosenAction, chosenLocation); | ||
|
|
||
| return commandMap.getOrDefault(event, DEFAULT_COMMAND); | ||
| } | ||
|
|
||
| public LoggableCommand getCommand() { | ||
| return get().getCommand(); | ||
| } | ||
|
|
||
| /** @return A human-readable description of the selected command. */ | ||
| public String getCommandDescription() { | ||
| return get().getDescription(); | ||
| } | ||
|
|
||
| public FieldLocation getLocation() { | ||
| return locationChooser.get(); | ||
| } | ||
|
|
||
| } | ||
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,47 @@ | ||
| package frc.robot.autochooser; | ||
|
|
||
| import frc.robot.utils.logging.commands.LoggableCommand; | ||
| import frc.robot.utils.logging.commands.DoNothingCommand; | ||
| import frc.robot.utils.logging.commands.DoSomethingCommand; | ||
|
|
||
| /** An enum to associate commands with human-readable descriptions. */ | ||
| public enum AutoCommand { | ||
|
|
||
| // Add commands here. Importantly, you should give each command | ||
| // a readable description so that the drive team can tell what | ||
| // the robot will actually do. This will be used to give the | ||
| // drive team visual feedback on the elastic dashboard when | ||
| // selecting an autonoumous command. | ||
| Invalid( | ||
| "The selection is invalid. (The robot won't do anything.)", | ||
| new DoNothingCommand() | ||
| ), | ||
| DoNothing("The robot won't do anything.", new DoNothingCommand()), | ||
| DoSomething( | ||
| "Something will be printed to the terminal.", | ||
| new DoSomethingCommand(""" | ||
| SUCCESSFULLY | ||
|
|
||
| DID | ||
|
|
||
| SOMETHING | ||
| """) | ||
| ); | ||
|
|
||
| private String description; | ||
| private LoggableCommand command; | ||
|
|
||
| AutoCommand(String description, LoggableCommand command) { | ||
| this.description = description; | ||
| this.command = command; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public LoggableCommand getCommand() { | ||
| return command; | ||
| } | ||
|
|
||
| } |
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,51 @@ | ||
| package frc.robot.autochooser; | ||
|
|
||
| /** | ||
| * Wrapper Class, that Contains a {@link frc.robot.autochooser.AutoAction} and a {@link | ||
| * frc.robot.autochooser.FieldLocation} | ||
| */ | ||
| public class AutoEvent { | ||
| private final AutoAction action; | ||
| private final FieldLocation location; | ||
|
|
||
| public AutoEvent(AutoAction action, FieldLocation location) { | ||
| this.action = action; | ||
| this.location = location; | ||
| } | ||
|
|
||
| public AutoAction getAction() { | ||
| return action; | ||
| } | ||
|
|
||
| public FieldLocation getLocation() { | ||
| return location; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| final int prime = 31; | ||
| int result = 1; | ||
| result = prime * result + ((action == null) ? 0 : action.hashCode()); | ||
| result = prime * result + ((location == null) ? 0 : location.hashCode()); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) | ||
| return true; | ||
| if (obj == null) | ||
| return false; | ||
| if (getClass() != obj.getClass()) | ||
| return false; | ||
| AutoEvent other = (AutoEvent) obj; | ||
| if (action != other.action) | ||
| return false; | ||
| if (location != other.location) | ||
| return false; | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
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.
I don't think you have a way to differentiate between an invalid combination of action+position and driver intentionally selecting "do nothing".
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 problem has actually been on my mind since I realized it a few minutes after leaving last Monday. I've got a solid distinction this time.