-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
145 additions
and
55 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
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
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
46 changes: 46 additions & 0 deletions
46
src/main/java/frc/robot/subsystems/drive/controllers/AutoAimController.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,46 @@ | ||
package frc.robot.subsystems.drive.controllers; | ||
|
||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.math.util.Units; | ||
import frc.robot.RobotState; | ||
import frc.robot.subsystems.drive.DriveConstants; | ||
import frc.robot.util.LoggedTunableNumber; | ||
import org.littletonrobotics.junction.AutoLogOutput; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class AutoAimController { | ||
private static final LoggedTunableNumber headingkP = | ||
new LoggedTunableNumber("AutoAim/kP", DriveConstants.headingControllerConstants.kP()); | ||
private static final LoggedTunableNumber headingkD = | ||
new LoggedTunableNumber("AutoAim/kD", DriveConstants.headingControllerConstants.kD()); | ||
private static final LoggedTunableNumber tolerance = | ||
new LoggedTunableNumber("AutoAim/ToleranceDegrees", 4.0); | ||
|
||
private PIDController headingController; | ||
|
||
public AutoAimController() { | ||
headingController = new PIDController(0, 0, 0, 0.02); | ||
headingController.enableContinuousInput(-Math.PI, Math.PI); | ||
} | ||
|
||
/** Returns the rotation rate to turn to aim at speaker */ | ||
public double update() { | ||
headingController.setPID(headingkP.get(), 0, headingkD.get()); | ||
headingController.setTolerance(Units.degreesToRadians(tolerance.get())); | ||
|
||
var aimingParams = RobotState.getInstance().getAimingParameters(); | ||
double output = | ||
headingController.calculate( | ||
RobotState.getInstance().getEstimatedPose().getRotation().getRadians(), | ||
aimingParams.driveHeading().getRadians()); | ||
|
||
Logger.recordOutput("AutoAim/HeadingError", headingController.getPositionError()); | ||
return output; | ||
} | ||
|
||
/** Returns true if within tolerance of aiming at speaker */ | ||
@AutoLogOutput(key = "AutoAim/AtSetpoint") | ||
public boolean atSetpoint() { | ||
return headingController.atSetpoint(); | ||
} | ||
} |
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