-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'robototes:main' into main
- Loading branch information
Showing
8 changed files
with
251 additions
and
37 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
44 changes: 44 additions & 0 deletions
44
src/main/java/frc/team2412/robot/commands/drivebase/DriveToNoteCommand.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,44 @@ | ||
package frc.team2412.robot.commands.drivebase; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.math.util.Units; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.team2412.robot.subsystems.DrivebaseSubsystem; | ||
import frc.team2412.robot.subsystems.LimelightSubsystem; | ||
|
||
public class DriveToNoteCommand extends Command { | ||
|
||
private final DrivebaseSubsystem drivebaseSubsystem; | ||
private final LimelightSubsystem limelightSubsystem; | ||
|
||
// limelight placement might be different so this multiplier is convenient | ||
private final double INVERT_DRIVE_DIRECTION = -1.0; | ||
|
||
public DriveToNoteCommand( | ||
DrivebaseSubsystem drivebaseSubsystem, LimelightSubsystem limelightSubsystem) { | ||
this.drivebaseSubsystem = drivebaseSubsystem; | ||
this.limelightSubsystem = limelightSubsystem; | ||
addRequirements(drivebaseSubsystem); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
if (limelightSubsystem.hasTargets()) { | ||
Translation2d move = | ||
new Translation2d( | ||
INVERT_DRIVE_DIRECTION | ||
* Units.inchesToMeters(limelightSubsystem.getDistanceFromTargetInches()), | ||
0.0); | ||
Rotation2d turn = | ||
new Rotation2d() | ||
.fromDegrees(2 * INVERT_DRIVE_DIRECTION * limelightSubsystem.getHorizontalOffset()); | ||
drivebaseSubsystem.drive(move, turn, false); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return (limelightSubsystem.isWithinDistance() || !limelightSubsystem.hasTargets()); | ||
} | ||
} |
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.