CogniPilot

MODELICA LIBRARY · ENGINEERING REFERENCE

function

Tests.ManualGuidanceTests.switchMonotonicityResidual

Band index decreases somewhere as the channel rises

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 switchMonotonicityResidual
    "Band index decreases somewhere as the channel rises"
    output Integer residual;
  protected
    constant Integer samples = 141;
    Real pwm_us;
    Integer previousBand;
    Integer band;
  algorithm
    residual := 0;
    previousBand := switchPosition(800.0, 0.0, 1);
    for index in 2:samples loop
      pwm_us := 800.0 + 10.0 * (index - 1);
      band := switchPosition(pwm_us, 0.0, 1);
      residual := residual + max(0, previousBand - band);
      previousBand := band;
    end for;
  end switchMonotonicityResidual;