Remove PIDControllerRunner and mutex from new PIDController (#1795)

Teams that wish to use it asynchronously may still do so - they simply need to handle the thread safety themselves (it is not that difficult, and can be done more cleanly in the calling code anyway).
This commit is contained in:
Oblarg
2019-08-04 03:01:11 -04:00
committed by Peter Johnson
parent 98d0706de8
commit c9873e81b2
11 changed files with 165 additions and 706 deletions

View File

@@ -12,14 +12,12 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import edu.wpi.first.wpilibj.controller.PIDController;
import edu.wpi.first.wpilibj.controller.PIDControllerRunner;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class PIDToleranceTest {
private PIDController m_pidController;
private PIDControllerRunner m_pidRunner;
private static final double m_setpoint = 50.0;
private static final double m_tolerance = 10.0;
private static final double m_range = 200;
@@ -42,7 +40,6 @@ class PIDToleranceTest {
void setUp() {
m_inp = new FakeInput();
m_pidController = new PIDController(0.05, 0.0, 0.0);
m_pidRunner = new PIDControllerRunner(m_pidController, m_inp::getMeasurement, x -> { });
m_pidController.setInputRange(-m_range / 2, m_range / 2);
}
@@ -61,42 +58,53 @@ class PIDToleranceTest {
void absoluteToleranceTest() {
m_pidController.setAbsoluteTolerance(m_tolerance);
m_pidController.setSetpoint(m_setpoint);
m_pidRunner.enable();
Timer.delay(1);
for (int i = 0; i < 50; i++) {
m_pidController.calculate(m_inp.getMeasurement());
}
assertFalse(m_pidController.atSetpoint(),
"Error was in tolerance when it should not have been. Error was "
+ m_pidController.getError());
"Error was in tolerance when it should not have been. Error was " + m_pidController
.getError());
m_inp.m_val = m_setpoint + m_tolerance / 2;
Timer.delay(1.0);
for (int i = 0; i < 50; i++) {
m_pidController.calculate(m_inp.getMeasurement());
}
assertTrue(m_pidController.atSetpoint(),
"Error was not in tolerance when it should have been. Error was "
+ m_pidController.getError());
"Error was not in tolerance when it should have been. Error was " + m_pidController
.getError());
m_inp.m_val = m_setpoint + 10 * m_tolerance;
Timer.delay(1.0);
for (int i = 0; i < 50; i++) {
m_pidController.calculate(m_inp.getMeasurement());
}
assertFalse(m_pidController.atSetpoint(),
"Error was in tolerance when it should not have been. Error was "
+ m_pidController.getError());
"Error was in tolerance when it should not have been. Error was " + m_pidController
.getError());
}
@Test
void percentToleranceTest() {
m_pidController.setPercentTolerance(m_tolerance);
m_pidController.setSetpoint(m_setpoint);
m_pidRunner.enable();
for (int i = 0; i < 50; i++) {
m_pidController.calculate(m_inp.getMeasurement());
}
assertFalse(m_pidController.atSetpoint(),
"Error was in tolerance when it should not have been. Error was "
+ m_pidController.getError());
"Error was in tolerance when it should not have been. Error was " + m_pidController
.getError());
//half of percent tolerance away from setPoint
m_inp.m_val = m_setpoint + m_tolerance / 200 * m_range;
Timer.delay(1.0);
for (int i = 0; i < 50; i++) {
m_pidController.calculate(m_inp.getMeasurement());
}
assertTrue(m_pidController.atSetpoint(),
"Error was not in tolerance when it should have been. Error was "
+ m_pidController.getError());
"Error was not in tolerance when it should have been. Error was " + m_pidController
.getError());
//double percent tolerance away from setPoint
m_inp.m_val = m_setpoint + m_tolerance / 50 * m_range;
Timer.delay(1.0);
for (int i = 0; i < 50; i++) {
m_pidController.calculate(m_inp.getMeasurement());
}
assertFalse(m_pidController.atSetpoint(),
"Error was in tolerance when it should not have been. Error was "
+ m_pidController.getError());
"Error was in tolerance when it should not have been. Error was " + m_pidController
.getError());
}
}