Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified PIDSensor #200

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 7 additions & 37 deletions custom/sensors/PIDSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,17 @@
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();

public interface PIDSensor extends PIDSource {
/**
* 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();

/**
* Get the result to use in PIDController
* $
*
* @return the result to use in PIDController
* @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
Expand All @@ -51,22 +26,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();
Expand Down