McePosTableFindEntry

0.1.0

Search the next valid entry in a PosTable from a given Index.

Version history

0.1.0

  Rioual

Changes

Added:
  • initial version

Overview

kindnametypedefaultcomment
inputindexINTindex of actual PosTable entry
inputoffsetINT0=first result, 1=second result, 2=third result
inputposTableSizeINTnumber of entries
inputrollOverBOOLcontinue from start after reaching end of table
in_outposTableMcePosTableDatatrajectory to be processed by PosTable

Details

index

INT

Index to start the search from.

offset

INT

Number of skipped result.

valueexplanation
0first result
1second result
2third result

posTableSize

INT

Number of entries of the PosTable.

rollOver

BOOL

Continue from the top of the PosTable after reaching the end.

Trajectory to be processed by PosTable.

Source code

Declarations

(*Index of found PosTable entry (-1=no valid result found)*)
FUNCTION McePosTableFindEntry : INT

(*
 * -----------------------------------------------------------------------------
 * Name               : McePosTableFindEntry
 * Version            : 0.1.0
 * Date               : 2024-02-29
 * Author             : Rioual
 * Family             : YaskawaMce
 * Organisation       : github.com/YaskawaEurope/mlx-examples
 * 
 * -----------------------------------------------------------------------------
 * Index of found PosTable entry (-1=no valid result found)
 * -----------------------------------------------------------------------------
 *)

VAR_INPUT
  index : INT; (*index of actual PosTable entry*)
  offset : INT; (*0=first result, 1=second result, 2=third result*)
  posTableSize : INT; (*number of entries*)
  rollOver : BOOL; (*continue from start after reaching end of table*)
END_VAR

VAR_IN_OUT
  posTable : McePosTableData; (*trajectory to be processed by PosTable*)
END_VAR

VAR
  nEntriesFound : INT;
  i : INT;
END_VAR

Logic

nEntriesFound := 0;

// -------------------------------------
// forward direction
// -------------------------------------
// search through the remaining part of the array
FOR i := index TO (posTableSize - 1) DO
  IF NOT posTable.stEntry[i].bSkipEntry THEN
    nEntriesFound := nEntriesFound + 1;
    IF (nEntriesFound > offset) THEN
      McePosTableFindEntry := i;
      RETURN;
    END_IF;
  END_IF;

  IF posTable.stEntry[i].bLastEntry THEN
    EXIT;
  END_IF;
END_FOR;

// search through the first part of the array
IF rollOver THEN
  FOR i := 0 TO index DO
    IF NOT posTable.stEntry[i].bSkipEntry THEN
      nEntriesFound := nEntriesFound + 1;
      IF (nEntriesFound > offset) THEN
        McePosTableFindEntry := i;
        RETURN;
      END_IF;
    END_IF;

    IF posTable.stEntry[i].bLastEntry THEN
      EXIT;
    END_IF;
  END_FOR;
END_IF;

// no valid result found
McePosTableFindEntry := - 1;

Implementation

Snippet of the function call:
dummy := McePosTableFindEntry(
           index := , 
           offset := , 
           posTableSize := , 
           rollOver := , 
           posTable := );

Pages built with Hugo - 23 Apr 2024 11:54 CEST