-
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.
Merge pull request #72 from frc2052/mlms/2Dapriltags
Mlms/2 dapriltags
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 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
60 changes: 60 additions & 0 deletions
60
...main/java/frc/robot/commands/auto/commands/drive/AimToSpeakerUsingOneAprilTagCommand.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,60 @@ | ||
// 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.commands.auto.commands.drive; | ||
|
||
import org.littletonrobotics.junction.Logger; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.RobotState; | ||
import frc.robot.subsystems.DrivetrainSubsystem; | ||
import frc.robot.util.AimingCalculator; | ||
|
||
public class AimToSpeakerUsingOneAprilTagCommand extends Command { | ||
protected final DrivetrainSubsystem drivetrain; | ||
private double goalAngleDegrees; | ||
private double deltaDegrees; | ||
private boolean isFinished = false; | ||
|
||
public AimToSpeakerUsingOneAprilTagCommand(DrivetrainSubsystem drivetrain) { | ||
this.drivetrain = drivetrain; | ||
isFinished = false; | ||
|
||
addRequirements(drivetrain); | ||
} | ||
|
||
private double getRotation() { | ||
isFinished = false; | ||
goalAngleDegrees = AimingCalculator.calculateRobotAngleOneAprilTag(); | ||
deltaDegrees = RobotState.getInstance().getRotation2d360().getDegrees() - goalAngleDegrees; | ||
Logger.recordOutput("goal angle", goalAngleDegrees); | ||
Logger.recordOutput("measured angle", RobotState.getInstance().getRotation2d360().getDegrees()); | ||
|
||
// return 0; | ||
if (Math.abs(deltaDegrees) > 90) { | ||
return Math.copySign(0.5, -deltaDegrees); | ||
} else if (Math.abs(deltaDegrees) > 45){ | ||
return Math.copySign(0.25, -deltaDegrees); | ||
} else if (Math.abs(deltaDegrees) > 5){ | ||
return Math.copySign(0.1, -deltaDegrees); | ||
} else { | ||
isFinished = true; | ||
return 0; | ||
} | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
drivetrain.drive(0, 0, getRotation(), true); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
drivetrain.stop(); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return isFinished; | ||
} | ||
} |
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