From 3d299f1643534450937de4c918c756405e085226 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sun, 26 Mar 2017 10:14:09 -0700 Subject: [PATCH 1/2] Added default for PIDSensor pidGetSafely --- custom/sensors/PIDSensor.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/custom/sensors/PIDSensor.java b/custom/sensors/PIDSensor.java index 51290886..1faebfcf 100644 --- a/custom/sensors/PIDSensor.java +++ b/custom/sensors/PIDSensor.java @@ -39,7 +39,9 @@ public interface PIDSensor { * @throws InvalidSensorException * when sensor data should not be used for PID due to potential inaccuracy */ - public double pidGetSafely() throws InvalidSensorException; + default public double pidGetSafely() throws InvalidSensorException { + return pidGet(); + } /** * Class to wrap a PIDSource to a PIDSensor @@ -51,22 +53,17 @@ public static class PIDSourceWrapper implements PIDSensor { public PIDSourceWrapper(PIDSource source) { this.source = source; } - + @Override public void setPIDSourceType(PIDSourceType pidSource) { source.setPIDSourceType(pidSource); } - + @Override public PIDSourceType getPIDSourceType() { return source.getPIDSourceType(); } - - @Override - public double pidGetSafely() throws InvalidSensorException { // No exception possible anyway - return source.pidGet(); - } - + @Override public double pidGet() { return source.pidGet(); From 90b1d457138c05fc9b7fdc7e49393439cb326e99 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sun, 26 Mar 2017 11:04:25 -0700 Subject: [PATCH 2/2] Made PIDSensor extend PIDSource --- custom/sensors/PIDSensor.java | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/custom/sensors/PIDSensor.java b/custom/sensors/PIDSensor.java index 1faebfcf..08df3a61 100644 --- a/custom/sensors/PIDSensor.java +++ b/custom/sensors/PIDSensor.java @@ -4,36 +4,9 @@ import edu.wpi.first.wpilibj.PIDSource; import edu.wpi.first.wpilibj.PIDSourceType; -public interface PIDSensor { - /** - * Set which parameter of the device you are using as a process control - * variable. - * - * @param pidSource - * An enum to select the parameter. - */ - public void setPIDSourceType(PIDSourceType pidSource); - - /** - * Get which parameter of the device you are using as a process control - * variable. - * - * @return the currently selected PID source parameter - */ - public PIDSourceType getPIDSourceType(); - - /** - * Get the result to use in PIDController - * $ - * - * @return the result to use in PIDController - * @warning does not report sensor errors, will just return 0 - */ - public double pidGet(); - +public interface PIDSensor extends PIDSource { /** * Get the result to use in PIDController - * $ * * @return the result to use in PIDController * @throws InvalidSensorException