-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from grt192/notealign
Notealign
- Loading branch information
Showing
16 changed files
with
310 additions
and
57 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
30 changes: 30 additions & 0 deletions
30
src/main/java/frc/robot/commands/sequences/AutoIntakeSequence.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,30 @@ | ||
package frc.robot.commands.sequences; | ||
|
||
import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup; | ||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
import frc.robot.commands.auton.DriveForwardCommand; | ||
import frc.robot.commands.elevator.ElevatorToGroundCommand; | ||
import frc.robot.commands.intake.roller.IntakeRollerIntakeCommand; | ||
import frc.robot.commands.swerve.NoteAlignCommand; | ||
import frc.robot.subsystems.elevator.ElevatorSubsystem; | ||
import frc.robot.subsystems.intake.IntakeRollersSubsystem; | ||
import frc.robot.subsystems.swerve.SwerveSubsystem; | ||
import frc.robot.vision.NoteDetectionWrapper; | ||
|
||
public class AutoIntakeSequence extends SequentialCommandGroup { | ||
|
||
|
||
public AutoIntakeSequence( | ||
ElevatorSubsystem elevatorSubsystem, | ||
IntakeRollersSubsystem intakeRollersSubsystem, | ||
SwerveSubsystem swerveSubsystem, | ||
NoteDetectionWrapper noteDetector | ||
){ | ||
addCommands(new ElevatorToGroundCommand(elevatorSubsystem) | ||
.andThen(new NoteAlignCommand(swerveSubsystem, noteDetector)) | ||
.andThen(new ParallelDeadlineGroup( | ||
new IntakeRollerIntakeCommand(intakeRollersSubsystem).withTimeout(3), | ||
new DriveForwardCommand(swerveSubsystem))) | ||
); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/frc/robot/commands/swerve/NoteAlignCommand.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,63 @@ | ||
package frc.robot.commands.swerve; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import frc.robot.subsystems.swerve.SwerveSubsystem; | ||
import frc.robot.vision.NoteDetectionWrapper; | ||
|
||
public class NoteAlignCommand extends Command{ | ||
private final SwerveSubsystem swerveSubsystem; | ||
private final NoteDetectionWrapper noteDetector; | ||
|
||
private double noteYawOffsetDegrees; | ||
|
||
public NoteAlignCommand(SwerveSubsystem swerveSubsystem, NoteDetectionWrapper noteDetector) { | ||
this.swerveSubsystem = swerveSubsystem; | ||
this.noteDetector = noteDetector; | ||
|
||
this.addRequirements(swerveSubsystem); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
System.out.println("Started NoteAlignCommand"); | ||
|
||
this.noteYawOffsetDegrees = 0; | ||
try { | ||
noteYawOffsetDegrees = noteDetector.getNote().get().getYaw(); | ||
} catch(NoSuchElementException e) { | ||
System.out.println("Tried to align to a note, but none was detected."); | ||
this.end(true); | ||
} | ||
|
||
System.out.println("Rotating to note at offset " + this.noteYawOffsetDegrees + " degrees"); | ||
|
||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return Math.abs(noteYawOffsetDegrees) < 1; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
try { | ||
noteYawOffsetDegrees = noteDetector.getNote().get().getYaw(); | ||
} catch(NoSuchElementException e) { | ||
|
||
} | ||
|
||
swerveSubsystem.setRobotRelativeDrivePowers(0.,0., -MathUtil.clamp(noteYawOffsetDegrees * .008, -.3, .3)); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
swerveSubsystem.setRobotRelativeDrivePowers(0, 0, 0); | ||
System.out.println("Ended NoteAlignCommand"); | ||
} | ||
|
||
|
||
} |
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
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.