Ejemplo n.º 1
0
def test_percent_tolerance(pid_controller: PIDController,
                           pid_runner: ControllerRunner):
    reference = 50
    tolerance = 10
    inp = pid_controller.measurement_source

    pid_controller.setPercentTolerance(tolerance)
    pid_controller.setReference(reference)
    pid_runner.enable()
    assert not pid_controller.atReference(), (
        "Error was in tolerance when it should not have been. Error was %f" %
        pid_controller.getError())

    # half of percent tolerance away from reference
    inp.return_value = reference + tolerance / 200 * input_range
    time.sleep(1)
    assert pid_controller.atReference(), (
        "Error was not in tolerance when it should have been. Error was %f" %
        pid_controller.getError())

    # double percent tolerance away from reference
    inp.return_value = reference + tolerance / 50 * input_range
    time.sleep(1)
    assert not pid_controller.atReference(), (
        "Error was in tolerance when it should not have been. Error was %f" %
        pid_controller.getError())
Ejemplo n.º 2
0
def test_absolute_tolerance(pid_controller: PIDController,
                            pid_runner: ControllerRunner):
    reference = 50
    tolerance = 10
    inp = pid_controller.measurement_source

    pid_controller.setAbsoluteTolerance(tolerance)
    pid_controller.setReference(reference)
    pid_runner.enable()
    time.sleep(1)
    assert not pid_controller.atReference(), (
        "Error was in tolerance when it should not have been. Error was %f" %
        pid_controller.getError())

    inp.return_value = reference + tolerance / 2
    time.sleep(1)
    assert pid_controller.atReference(), (
        "Error was not in tolerance when it should have been. Error was %f" %
        pid_controller.getError())

    inp.return_value = reference + 10 * tolerance
    time.sleep(1)
    assert not pid_controller.atReference(), (
        "Error was in tolerance when it should not have been. Error was %f" %
        pid_controller.getError())