|
5 | 5 | import com.spikes2212.control.FeedForwardSettings;
|
6 | 6 | import com.spikes2212.control.PIDSettings;
|
7 | 7 | import com.spikes2212.dashboard.RootNamespace;
|
| 8 | +import com.spikes2212.dashboard.SpikesLogger; |
| 9 | +import frc.robot.subsystems.Storage; |
8 | 10 | import frc.robot.subsystems.district2.District2CoralJoint;
|
9 | 11 |
|
10 | 12 | import java.util.function.Supplier;
|
11 | 13 |
|
12 | 14 | public class District2RotateStorage extends MoveGenericSubsystemWithPID {
|
13 | 15 |
|
14 | 16 | private static final RootNamespace namespace = new RootNamespace("district 2 rotate storage");
|
15 |
| - private static final PIDSettings intakePIDSettings = namespace.addPIDNamespace("rotate storage", |
| 17 | + private static final PIDSettings intakePIDSettings = namespace.addPIDNamespace("intake rotate storage", |
16 | 18 | new PIDSettings(0.11, 0, 0.005, 0, 3, 0.5));
|
17 |
| - private static final FeedForwardSettings intakeFeedForwardSettings = namespace.addFeedForwardNamespace("rotate storage", |
18 |
| - new FeedForwardSettings(0, 0, 0, 0.082, FeedForwardController.ControlMode.ANGULAR_POSITION)); |
19 |
| - private static final PIDSettings outtakePIDSettings = namespace.addPIDNamespace("rotate storage", |
20 |
| - new PIDSettings(0.11, 0, 0.005, 0, 3, 0.5)); |
21 |
| - private static final FeedForwardSettings outtakeFeedForwardSettings = namespace.addFeedForwardNamespace("rotate storage", |
| 19 | + private static final FeedForwardSettings intakeFeedForwardSettings = namespace.addFeedForwardNamespace("intake rotate storage", |
22 | 20 | new FeedForwardSettings(0, 0, 0, 0.082, FeedForwardController.ControlMode.ANGULAR_POSITION));
|
| 21 | + private static final PIDSettings outtakePIDSettings = namespace.addPIDNamespace("outtake rotate storage", |
| 22 | + new PIDSettings(0.15, 0, 0.012, 0, 3, 0.5)); |
| 23 | + private static final FeedForwardSettings outtakeFeedForwardSettings = namespace.addFeedForwardNamespace("outtake rotate storage", |
| 24 | + new FeedForwardSettings(0, 0, 0, 0.12, FeedForwardController.ControlMode.ANGULAR_POSITION)); |
23 | 25 |
|
24 | 26 | private final District2CoralJoint coralJoint;
|
| 27 | + private SpikesLogger logger = new SpikesLogger(); |
25 | 28 |
|
26 | 29 | public District2RotateStorage(District2CoralJoint coralJoint, Supplier<Double> setpoint) {
|
27 | 30 | super(coralJoint, () -> Math.toRadians(setpoint.get()), () -> Math.toRadians(coralJoint.getPosition()),
|
28 |
| - intakePIDSettings, intakeFeedForwardSettings); |
| 31 | + Storage.getInstance().hasCoral() ? outtakePIDSettings : intakePIDSettings, |
| 32 | + Storage.getInstance().hasCoral() ? outtakeFeedForwardSettings : intakeFeedForwardSettings); |
| 33 | + pidSettings.setWaitTime(() -> 999.0); |
29 | 34 | this.coralJoint = coralJoint;
|
| 35 | + logger.log("m" + pidSettings.getWaitTime()); |
30 | 36 | }
|
31 | 37 |
|
32 | 38 | public District2RotateStorage(District2CoralJoint coralJoint, District2CoralJoint.StoragePose pose) {
|
33 | 39 | this(coralJoint, () -> pose.neededPitch);
|
34 | 40 | }
|
35 | 41 |
|
| 42 | + @Override |
| 43 | + protected double calculatePIDAndFFValues() { |
| 44 | + if (Storage.getInstance().hasCoral()) { |
| 45 | + pidController.setTolerance(Math.toRadians(outtakePIDSettings.getTolerance())); |
| 46 | + pidController.setPID(outtakePIDSettings.getkP(), outtakePIDSettings.getkI(), outtakePIDSettings.getkD()); |
| 47 | + pidController.setIZone(outtakePIDSettings.getIZone()); |
| 48 | + feedForwardController.setGains(outtakeFeedForwardSettings); |
| 49 | + } else { |
| 50 | + pidController.setTolerance(Math.toRadians(intakePIDSettings.getTolerance())); |
| 51 | + pidController.setPID(intakePIDSettings.getkP(), intakePIDSettings.getkI(), intakePIDSettings.getkD()); |
| 52 | + pidController.setIZone(intakePIDSettings.getIZone()); |
| 53 | + feedForwardController.setGains(intakeFeedForwardSettings); |
| 54 | + } |
| 55 | + |
| 56 | + double pidValue = pidController.calculate(source.get(), setpoint.get()); |
| 57 | + double svagValue = feedForwardController.calculate(source.get(), setpoint.get()); |
| 58 | + return pidValue + svagValue; |
| 59 | + } |
| 60 | + |
36 | 61 | @Override
|
37 | 62 | public boolean isFinished() {
|
| 63 | + logger.log(source.get() + ", " + setpoint.get()); |
38 | 64 | return !(coralJoint.canMove(coralJoint.getSpeed())) || super.isFinished();
|
39 | 65 | }
|
40 | 66 | }
|
0 commit comments