-
Notifications
You must be signed in to change notification settings - Fork 1
/
PIDCtrl.java
78 lines (61 loc) · 1.94 KB
/
PIDCtrl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package frc.robot.util;
import edu.wpi.first.wpilibj.PIDController;
import edu.wpi.first.wpilibj.PIDOutput;
import edu.wpi.first.wpilibj.PIDSource;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.robot.util.settings.Func;
import frc.robot.util.settings.Setting;
public class PIDCtrl extends PIDController{
private Func iZone;
private double actingI;
// public PIDCtrl(double Kp, double Ki, double Kd, PIDSource source, PIDOutput output, double period) {
// super(Kp, 0, Kd, source, output, period);
// actingI = Ki;
// }
public PIDCtrl(double Kp, double Ki, double Kd, PIDSource source, PIDOutput output, double iz) {
super(Kp, 0, Kd, source, output);
actingI = Ki;
iZone = Func.getFunc(iz);
}
// public PIDCtrl(double Kp, double Ki, double Kd, double Kf, PIDSource source, PIDOutput output, double period) {
// super(Kp, 0, Kd, Kf, source, output, period);
// actingI = Ki;
// }
public PIDCtrl(double Kp, double Ki, double Kd, double Kf, PIDSource source, PIDOutput output, double iz) {
super(Kp, 0, Kd, Kf, source, output);
actingI = Ki;
iZone = Func.getFunc(iz);
}
public void sendToDash(String name) {
SmartDashboard.putData(name, this);
iZone = new Setting(name + " IZone", iZone.getValue());
}
/*
* these methods set and update the I-zone for the controller
*/
public synchronized void updateI(){
if(Math.abs(super.getError()) < iZone.getValue()){
super.setPID(super.getP(), actingI, super.getD());
}else{
super.setPID(super.getP(), 0, super.getD());
}
}
@Override
public void setI(double i) {
actingI = i;
}
/*
* these methods route to the controller, manipulating instead the acting I
*/
public synchronized void setPID(double p, double i, double d) {
actingI = i;
super.setPID(p, 0, d);
}
public synchronized void setPID(double p, double i, double d, double f) {
actingI = i;
super.setPID(p, 0, d, f);
}
// public void sendToDash(String name) {
//
// }
}