-
Notifications
You must be signed in to change notification settings - Fork 36
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/ SPDX-License-Identifier: EPL-2.0 This Block was inspired by https://content.helpme-codesys.com/en/libs/Util/Current/Mathematical-Functions/INTEGRAL.html " > | ||
</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"/> | ||
</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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When testing this in the Interpreter I got the following case:
this is caused by the variable resolution of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are totally right: maybe we should also make a LREAL Version, as well a Fixed-comma Version in DINT. |
||
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> |
There was a problem hiding this comment.
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...