CogniPilot

MODELICA LIBRARY · ENGINEERING REFERENCE

function

Tests.ManualGuidanceTests.switchIdempotenceResidual

Positions that change when the quantizer is fed its own output

Public declarations

Explicit source declarations; dimensions, modifications and defaults are shown as written, without evaluation.

RoleNameTypeDimensions / attributes / defaultDescription
outputresidualInteger

Modelica declarations and implementation

Show parameters, interfaces and source

Parameters, inputs, outputs, defaults and equations from the source file.

function switchIdempotenceResidual
    "Positions that change when the quantizer is fed its own output"
    output Integer residual;
  protected
    constant Integer samples = 141;
    Real pwm_us;
    Integer once;
    Integer twice;
  algorithm
    residual := 0;
    for index in 1:samples loop
      pwm_us := 800.0 + 10.0 * (index - 1);
      once := switchPosition(pwm_us, switchHysteresis_us, 1);
      twice := switchPosition(pwm_us, switchHysteresis_us, once);
      residual := residual + abs(twice - once);
    end for;
  end switchIdempotenceResidual;