CogniPilot

MODELICA LIBRARY · ENGINEERING REFERENCE

function

Planning.Bezier.activeWaypointSegment

Locate the active segment in the populated prefix of a waypoint plan

Public declarations

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

RoleNameTypeDimensions / attributes / defaultDescription
inputsegmentDurationReal[:](each unit = "s")
inputwaypointCountInteger(min = 2, max = size(segmentDuration, 1) + 1)
inputtrajectoryTimeReal(unit = "s")
outputactiveSegmentInteger(min = 1, max = size(segmentDuration, 1))

Modelica declarations and implementation

Show parameters, interfaces and source

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

function activeWaypointSegment
  "Locate the active segment in the populated prefix of a waypoint plan"
  input Real segmentDuration[:](each unit = "s");
  input Integer waypointCount(min = 2, max = size(segmentDuration, 1) + 1);
  input Real trajectoryTime(unit = "s");
  output Integer activeSegment(min = 1, max = size(segmentDuration, 1));
protected
  Real elapsed(unit = "s");
algorithm
  activeSegment := 1;
  elapsed := 0.0;
  for segmentIndex in 1:size(segmentDuration, 1) loop
    if segmentIndex < waypointCount and trajectoryTime >= elapsed then
      activeSegment := segmentIndex;
    end if;
    if segmentIndex < waypointCount then
      elapsed := elapsed + segmentDuration[segmentIndex];
    end if;
  end for;
end activeWaypointSegment;