|
1 | 1 | package frc.robot.utils;
|
2 | 2 |
|
| 3 | +import edu.wpi.first.math.MathUtil; |
3 | 4 | import edu.wpi.first.math.controller.PIDController;
|
| 5 | +import edu.wpi.first.math.geometry.Pose2d; |
| 6 | +import edu.wpi.first.math.kinematics.ChassisSpeeds; |
| 7 | +import edu.wpi.first.math.trajectory.TrapezoidProfile; |
4 | 8 |
|
5 | 9 | public class HolonomicController {
|
| 10 | + private final TrapezoidProfile _xProfile = new TrapezoidProfile(null); |
| 11 | + private final TrapezoidProfile _yProfile = new TrapezoidProfile(null); |
| 12 | + private final TrapezoidProfile _headingProfile = new TrapezoidProfile(null); |
| 13 | + |
6 | 14 | private final PIDController _xController = new PIDController(0, 0, 0);
|
7 | 15 | private final PIDController _yController = new PIDController(0, 0, 0);
|
8 | 16 | private final PIDController _headingController = new PIDController(0, 0, 0);
|
| 17 | + |
| 18 | + private Pose2d _error = new Pose2d(); |
| 19 | + private Pose2d _setpoint = new Pose2d(); |
| 20 | + |
| 21 | + private Pose2d _tolerance = new Pose2d(); |
| 22 | + |
| 23 | + public void setTolerance(Pose2d tolerance) { |
| 24 | + _tolerance = tolerance; |
| 25 | + } |
| 26 | + |
| 27 | + public void setSetpoint(Pose2d setpoint) { |
| 28 | + _setpoint = setpoint; |
| 29 | + } |
| 30 | + |
| 31 | + /** A state the drive can be at. */ |
| 32 | + public record State(Pose2d pose, ChassisSpeeds speeds) {} |
| 33 | + |
| 34 | + /** |
| 35 | + * Whether the error of the holonomic controller (since the last {@link #calculate call}) is |
| 36 | + * within the tolerance or not. |
| 37 | + */ |
| 38 | + public boolean atReference() { |
| 39 | + return MathUtil.isNear(_setpoint.getX(), _error.getX(), _tolerance.getX()) |
| 40 | + && MathUtil.isNear(_setpoint.getY(), _error.getY(), _tolerance.getY()) |
| 41 | + && MathUtil.isNear( |
| 42 | + _setpoint.getRotation().getRadians(), |
| 43 | + _error.getRotation().getRadians(), |
| 44 | + _tolerance.getRotation().getRadians()); |
| 45 | + } |
| 46 | + |
| 47 | + public ChassisSpeeds calculate(State current, State goal, double t) { |
| 48 | + return new ChassisSpeeds(); |
| 49 | + } |
9 | 50 | }
|
0 commit comments