def test_pidcontroller_calculate_rate7(input, setpoint, expected_error, expected_output): pid = PIDController(0.1, 0, 0.075) pid.enableContinuousInput(-180.0, 180.0) pid.setIntegratorRange(-1, 1) pid.setSetpoint(setpoint) out = pid.calculate(input) assert pid.getPositionError() == pytest.approx(expected_error, 0.01) # assert out == pytest.approx(expected_output, 0.01) assert out != 0
def test_pidcontroller_calculate_displacement3(d, source1, source2, output1, output2, output3): pid = PIDController(0, 0, d) # D is change in error coeff for kDisplacement pid.enableContinuousInput(0, 100.0) pid.setIntegratorRange(-1, 1) pid.setSetpoint(50.0) out = pid.calculate(source1) # assert out == pytest.approx(output1, 0.01) assert out > 0 out = pid.calculate(source1) assert out == pytest.approx(output2, 0.01) out = pid.calculate(source2) # assert out == pytest.approx(output3, 0.01) assert out < 0
def test_pidcontroller_calculate_displacement1(p, source1, source2, output1, output2): pid = PIDController(p, 0, 0) # P is proportional error coeff for kDisplacement pid.enableContinuousInput(0, 100.0) pid.setIntegratorRange(-1, 1) pid.setSetpoint(50.0) out = pid.calculate(source1) # assert out == pytest.approx(output1, 0.01) assert out > 0 out = pid.calculate(source1) # assert out == pytest.approx(output1, 0.01) assert out > 0 out = pid.calculate(source2) # assert out == pytest.approx(output2, 0.01) assert out > 0