Remove sendables from SendableRegistry when close() is called (#1917)

This only affected Java (C++ RAII doesn't have the same problem).

Needed to add close/AutoCloseable to several classes to add this behavior.
This commit is contained in:
Peter Johnson
2019-10-05 23:42:53 -07:00
committed by GitHub
parent a9f0e46680
commit 10deba8546
36 changed files with 110 additions and 15 deletions

View File

@@ -28,7 +28,7 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
* given set of PID constants.
*/
@SuppressWarnings("PMD.TooManyFields")
public class PIDBase implements PIDInterface, PIDOutput, Sendable {
public class PIDBase implements PIDInterface, PIDOutput, Sendable, AutoCloseable {
public static final double kDefaultPeriod = 0.05;
private static int instances;
@@ -191,6 +191,11 @@ public class PIDBase implements PIDInterface, PIDOutput, Sendable {
this(Kp, Ki, Kd, 0.0, source, output);
}
@Override
public void close() {
SendableRegistry.remove(this);
}
/**
* Read the input, calculate the output accordingly, and write to the output. This should only be
* called by the PIDTask and is created during initialization.