Linear functions by the piece

  • This bulky term refers to function curves that can be freely created by the programmer. They are defined by defining (at least 2) X-Y pairs (points), which are then mathematically connected with straight lines. Such functions also occur elsewhere in LOTUS, e.g. as volume curves in the sound editor.

    A typical example of this are motor characteristics. These do not follow a single mathematical formula, but must be based on corresponding diagrams in the data sheets.


    The functions are created according to the following principle:

    • Define a new "function envelope" in the initialization part
    • Add value pairs one after the other in the initialization part of the function
    • Use function anywhere

    In concrete terms, these steps are carried out as follows:


    First, a global integer variable must be defined, which is used to identify the function:


    Test function: integer;


    With the function LinFuncNew you can now create a new function in the initialization part:


    Testfunction := LinFuncNew;


    You can now pass the necessary value pairs to this function by calling LinFuncAddPair(id, x, y) several times. The order is important! X must always be increasing!


    Code
    1. LinFuncAddPair(Testfunction, 2, 6);
    2. LinFuncAddPair(Testfunction, 6, 5);
    3. LinFuncAddPair(Testfunction, 7, 8);
    4. LinFuncAddPair(Testfunction, 8, 2);


    After all, you can use the function with LinFuncGetValue(id, x) at any point (after the definition, of course):


    Result := LinFuncGetValue(Testfunction, 4); // Result = 5.5