@@ -33,6 +33,8 @@ public class PrefPIDController extends PIDController {
3333 private double m_defP , m_defI , m_defD , m_defF ;
3434 private double m_defTolerance = -1 ; // -1 indicates no tolerance
3535 private double m_defMinOutput = -1 , m_defMaxOutput = 1 ;
36+
37+ private PIDSource m_source ;
3638
3739 private final String m_prefString ;
3840
@@ -132,6 +134,7 @@ public PrefPIDController(String prefString, double Kp, double Ki, double Kd,
132134 m_defD = Kd ;
133135 m_defF = Kf ;
134136 m_prefString = prefString ;
137+ m_source = source ;
135138
136139 createKeysIfEmpty ();
137140 updatePreferences ();
@@ -231,6 +234,44 @@ public void setOutputRange(double min, double max) {
231234
232235 updatePreferences ();
233236 }
237+ /**
238+ * Gets the tolerance of the PID
239+ *
240+ * @return the tolerance of this PID
241+ */
242+ public double getTolerance () {
243+ return m_defTolerance ;
244+ }
245+
246+ /**
247+ * Is the system above the given target
248+ *
249+ * @param target
250+ * setpoint to check if the PID system is above
251+ *
252+ * @param reverse
253+ * is the system reversed
254+ *
255+ * @return is the system above the given target
256+ */
257+ public boolean isAbove (double target , boolean reverse ) {
258+ return (reverse ? m_source .pidGet () <= target +m_defTolerance : m_source .pidGet () >= target -m_defTolerance );
259+ }
260+ /**
261+ * Is the system below the given target
262+ *
263+ * @param target
264+ * setpoint to check if the PID system is below
265+ *
266+ * @param reverse
267+ * is the system reversed
268+ *
269+ * @return is the system below the given target
270+ */
271+ public boolean isBelow (double target , boolean reverse ) {
272+ return (reverse ? m_source .pidGet () >= target -m_defTolerance : m_source .pidGet () <= target +m_defTolerance );
273+ }
274+
234275
235276 private void updatePreferences () {
236277 Preferences pref = Preferences .getInstance ();
0 commit comments