Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new integral function block for determining approximate integral over time. #648

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions data/typelibrary/utils-1.0.0/typelib/math/INTEGRAL.fbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<FBType Name="INTEGRAL" Comment="determines approximately the integral over time.">
<Identification Standard="61499-1" Description="Copyright (c) 2024 HR Agrartechnik GmbH &#10; &#10;This program and the accompanying materials are made&#10;available under the terms of the Eclipse Public License 2.0&#10;which is available at https://www.eclipse.org/legal/epl-2.0/&#10;&#10;SPDX-License-Identifier: EPL-2.0&#10;&#10;This Block was inspired by &#10;https://content.helpme-codesys.com/en/libs/Util/Current/Mathematical-Functions/INTEGRAL.html&#10;" >
</Identification>
<VersionInfo Organization="HR Agrartechnik GmbH" Version="1.0" Author="Franz Höpfinger" Date="2024-10-18" Remarks="initial Version">
</VersionInfo>
<CompilerInfo packageName="utils::math">
</CompilerInfo>
<InterfaceList>
<EventInputs>
<Event Name="REQ" Type="Event" Comment="Normal Execution Request">
<With Var="IN"/>
<With Var="TM"/>
</Event>
<Event Name="RESET" Type="Event" Comment="TRUE: OUT is set to zero and OVERFLOW to FALSE">
</Event>
</EventInputs>
<EventOutputs>
<Event Name="CNF" Type="Event" Comment="Execution Confirmation">
<With Var="OUT"/>
<With Var="OVERFLOW"/>
</Event>
</EventOutputs>
<InputVars>
<VarDeclaration Name="IN" Type="REAL" Comment="Input value" InitialValue="0.0"/>
<VarDeclaration Name="TM" Type="DINT" Comment="Time since last call in msec" InitialValue="0"/>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer TM to have type TIME to better indicate the meaning of this value. But I fully understand the implications this has on the integration as soon as people start to use values in nanoseconds...

</InputVars>
<OutputVars>
<VarDeclaration Name="OUT" Type="REAL" Comment="Value of the integral. This is done by summing all part integrals IN * TM" InitialValue="0.0"/>
<VarDeclaration Name="OVERFLOW" Type="BOOL" Comment="TRUE: The value of OUT is out of range of REAL variables. he function is blocked till it is new initialised by input RESET." InitialValue="FALSE"/>
</OutputVars>
</InterfaceList>
<SimpleFB>
<Algorithm Name="REQ" Comment="">
<ST><![CDATA[ALGORITHM REQ
IF NOT OVERFLOW THEN
IF (1.0E38 - IN * DINT_TO_REAL(TM) < OUT OR -1.0E38 - IN * DINT_TO_REAL(TM) > OUT) THEN
OVERFLOW := TRUE;
ELSIF (TM > 0) THEN // Time Difference since last call must be positive.
OUT := OUT + IN * DINT_TO_REAL(TM) / 1000.0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing this in the Interpreter I got the following case:

  • send RESET
  • set IN to 9.0E9, TM to 1 send REQ; OUT goes to 8999999.0
  • set the input to 1.0, send REQ; OUT does not change
  • set the input to -1.0, send REQ; OUT also does not change

this is caused by the variable resolution of the REAL datatype - a warning for the case where the integration does not work (i.e. OUT does not change with IN <> 0) could be nice-to-have

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are totally right:
our colleges at CODESYS have same issue with same Function.
this comes from the internal representation of REAL.

maybe we should also make a LREAL Version, as well a Fixed-comma Version in DINT.
i will think about it, and in the MEantime make the warning as written above.

END_IF;
END_IF;
END_ALGORITHM]]></ST>
</Algorithm>
<Algorithm Name="RESET" Comment="">
<ST><![CDATA[

ALGORITHM RESET
OUT := 0.0;
OVERFLOW := FALSE;
END_ALGORITHM

]]></ST>
</Algorithm>
</SimpleFB>
</FBType>
Loading