Skip to content

Commit 98f4be7

Browse files
committed
worked more on holonomic controller class
1 parent fe244ad commit 98f4be7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
package frc.robot.utils;
22

3+
import edu.wpi.first.math.MathUtil;
34
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;
48

59
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+
614
private final PIDController _xController = new PIDController(0, 0, 0);
715
private final PIDController _yController = new PIDController(0, 0, 0);
816
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+
}
950
}

0 commit comments

Comments
 (0)