-
-
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.
Start adding auto capabilities for Note Map
- Loading branch information
1 parent
28a8a0a
commit 290ca30
Showing
5 changed files
with
151 additions
and
6 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,73 @@ | ||
// 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.auto_manager; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.wpilibj.Timer; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import frc.robot.intake.IntakeSubsystem; | ||
import frc.robot.note_manager.NoteManager; | ||
import frc.robot.note_tracking.NoteMapElement; | ||
import frc.robot.note_tracking.NoteTrackingManager; | ||
import frc.robot.robot_manager.RobotCommands; | ||
import frc.robot.robot_manager.RobotManager; | ||
import frc.robot.robot_manager.RobotState; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AutoManager { | ||
private final RobotCommands actions; | ||
private final NoteTrackingManager noteTrackingManager; | ||
private final RobotManager robotManager; | ||
|
||
public AutoManager(RobotCommands actions, NoteTrackingManager noteTrackingManager, RobotManager robotManager) { | ||
this.actions = actions; | ||
this.noteTrackingManager = noteTrackingManager; | ||
this.robotManager = robotManager; | ||
} | ||
|
||
public Command doManyAutoSteps(List<AutoNoteStep> steps) { | ||
return Commands.sequence(steps.stream().map(this::doAutoStep).toArray(Command[]::new)); | ||
} | ||
|
||
private Command doAutoStep(AutoNoteStep step) { | ||
var command = noteTrackingManager.intakeNoteAtPose(step.noteSearchPose().get()); | ||
|
||
// TODO: Pathfind to outtake/shoot position | ||
if (step.action() == AutoNoteAction.OUTTAKE) { | ||
command = command.andThen(actions.shooterOuttakeCommand().unless(()-> !robotManager.getState().hasNote)); | ||
} else if (step.action() == AutoNoteAction.SCORE) { | ||
command = command.andThen(actions.speakerShotCommand().unless(()-> !robotManager.getState().hasNote)); | ||
} | ||
|
||
return command; | ||
} | ||
|
||
public Command testCommand() { | ||
|
||
return Commands.sequence( | ||
Commands.runOnce( | ||
() -> { | ||
var now = Timer.getFPGATimestamp(); | ||
// 1. reset note map as if it were start of auto | ||
noteTrackingManager.resetNoteMap( | ||
new ArrayList<>( | ||
List.of( | ||
// new NoteMapElement(now + 5, new Pose2d(8.271, 7.458, new Rotation2d(0))), | ||
new NoteMapElement(now + 5, AutoNoteStep.noteIdToPose(4)), | ||
new NoteMapElement(now + 5, AutoNoteStep.noteIdToPose(5)), | ||
new NoteMapElement(now + 5, AutoNoteStep.noteIdToPose(6))))); | ||
}), | ||
// 2. intakes notes 4 5 6 and scores | ||
doManyAutoSteps(List.of( | ||
new AutoNoteStep(4, AutoNoteAction.OUTTAKE), | ||
new AutoNoteStep(5, AutoNoteAction.SCORE), | ||
new AutoNoteStep(6, AutoNoteAction.SCORE) | ||
))); | ||
} | ||
} |
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.auto_manager; | ||
|
||
public enum AutoNoteAction { | ||
SCORE, | ||
OUTTAKE; | ||
} |
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,51 @@ | ||
// 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.auto_manager; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import frc.robot.fms.FmsSubsystem; | ||
import java.util.function.Supplier; | ||
|
||
public record AutoNoteStep(Supplier<Pose2d> noteSearchPose, AutoNoteAction action) { | ||
public static Pose2d noteIdToPose(int noteId) { | ||
switch (noteId) { | ||
case 1: | ||
if (FmsSubsystem.isRedAlliance()) { | ||
return new Pose2d(13.65, 4.106, new Rotation2d(0)); | ||
} else { | ||
return new Pose2d(2.896, 4.106, new Rotation2d(0)); | ||
} | ||
case 2: | ||
if (FmsSubsystem.isRedAlliance()) { | ||
return new Pose2d(13.65, 5.553, new Rotation2d(0)); | ||
} else { | ||
return new Pose2d(2.896, 5.553, new Rotation2d(0)); | ||
} | ||
case 3: | ||
if (FmsSubsystem.isRedAlliance()) { | ||
return new Pose2d(13.65, 7.001, new Rotation2d(0)); | ||
} else { | ||
return new Pose2d(2.896, 7.001, new Rotation2d(0)); | ||
} | ||
case 4: | ||
return new Pose2d(8.271, 7.458, new Rotation2d(0)); | ||
case 5: | ||
return new Pose2d(8.271, 5.782, new Rotation2d(0)); | ||
case 6: | ||
return new Pose2d(8.271, 4.106, new Rotation2d(0)); | ||
case 7: | ||
return new Pose2d(8.271, 2.429, new Rotation2d(0)); | ||
case 8: | ||
return new Pose2d(8.271, 0.753, new Rotation2d(0)); | ||
default: | ||
throw new IllegalArgumentException("Expected a note ID from between 1 and 8"); | ||
} | ||
} | ||
|
||
public AutoNoteStep(int noteId, AutoNoteAction action) { | ||
this(() -> noteIdToPose(noteId), action); | ||
} | ||
} |
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