Skip to content

Commit

Permalink
Add tests to plc task #89
Browse files Browse the repository at this point in the history
  • Loading branch information
LZimmermannLZI committed Apr 12, 2022
1 parent 239019c commit f750ae0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,6 @@
</Vars>
<Vars VarGrpType="2" AreaNo="1">
<Name>PlcTask Outputs</Name>
<Var>
<Name>MAIN.fbHSS.fbValve.nOpeningSet</Name>
<Comment><![CDATA[Raw values]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>ADS.bHSSPumpErrorADS</Name>
<Type>BOOL</Type>
Expand All @@ -330,6 +325,11 @@
<Name>ADS.bHSSPumpOperatingADS</Name>
<Type>BOOL</Type>
</Var>
<Var>
<Name>MAIN.fbHSS.fbValve.nOpeningSet</Name>
<Comment><![CDATA[Raw values]]></Comment>
<Type>INT</Type>
</Var>
<Var>
<Name>ADS.fTempAmbAirADS</Name>
<Comment><![CDATA[Ambient air datapoints]]></Comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[FC_HeatingCurve:= fSlope * fTempAmb + fOffset;]]></ST>
<ST><![CDATA[FC_HeatingCurve := fSlope * fTempAmb + fOffset;]]></ST>
</Implementation>
<LineIds Name="FC_HeatingCurve">
<LineId Id="7" Count="0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.3">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.6">
<POU Name="MAIN" Id="{739250fd-a178-4b07-8586-e950252efe80}" SpecialFunc="None">
<Declaration><![CDATA[PROGRAM MAIN
VAR
Expand All @@ -12,7 +12,8 @@ VAR
//simulated sensor data
fbHSSSenDa : FB_SenDaHydMixCir;
//simulated enviromental temperature
fbAmbientAir : FB_AmbientAir;
fbAmbientAir : FB_AmbientAir;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[//Check main control mode
Expand All @@ -37,6 +38,7 @@ fbHSS.TempSup := fbHSSSenDa.fTempSupAct;
//Valve input
fbHSS.Valve := fbHSSSenDa.fHSSValveAct;
//Execute Routine
fbHSS.Run();
Expand Down Expand Up @@ -64,6 +66,7 @@ fbHSS.Run();
<LineId Id="2029" Count="0" />
<LineId Id="2027" Count="0" />
<LineId Id="1981" Count="0" />
<LineId Id="2074" Count="0" />
<LineId Id="1898" Count="0" />
<LineId Id="1921" Count="0" />
<LineId Id="1529" Count="0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,106 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.6">
<POU Name="FC_HeatingCurve_Test" Id="{8e411346-ca53-4fb8-b98d-0f5f8749ec27}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION_BLOCK FC_HeatingCurve_Test EXTENDS TcUnit.FB_TestSuite
<Declaration><![CDATA[FUNCTION_BLOCK FC_HeatingCurve_Test EXTENDS TcUnit.FB_TestSuite // This block calls the different Test methods
VAR
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[NegativeTAmb();
<ST><![CDATA[TAmbNegative();
TAmbZero();
HeatingCurveZero();
NegativeHeatingCurve();]]></ST>
HeatingCurveNegative();]]></ST>
</Implementation>
<Method Name="FB_init" Id="{17668140-ad48-4f55-bdcc-0c34a19d497e}">
<Declaration><![CDATA[METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[]]></ST>
</Implementation>
</Method>
<Method Name="HeatingCurveZero" Id="{a8a24643-9d4c-47d2-9a52-f8327d36a5c7}">
<Declaration><![CDATA[METHOD HeatingCurveZero
<Method Name="HeatingCurveNegative" Id="{c18ef7fb-b184-4ae9-a8c8-5a1b615ecc7a}">
<Declaration><![CDATA[METHOD HeatingCurveNegative // This method checks whether the heating curve can have a negative value
VAR
HeatingCurve: FC_HeatingCurve;
ExpectedValue : REAL := 0;
fSlope: REAL;
fOffset: REAL;
END_VAR]]></Declaration>
HeatingCurveRes: Real; //Actual value for Heating Curve
ExpectedValue : REAL := -1; //Expected value for Heating Curve
fSlope: REAL := -1; //Slope of Heating Curve
fOffset: REAL := 35; //Offset of Heating Curve
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('HeatingCurveZero');
<ST><![CDATA[TEST('HeatingCurveNegative');
HeatingCurve(fTempAmb := 35, fSlope, fOffset);
HeatingCurveRes := FC_HeatingCurve(fTempAmb := 36, fSlope, fOffset);
AssertEquals(Expected := ExpectedValue,
Actual := HeatingCurve,
Actual := HeatingCurveRes,
Message := 'The calculation is not correct');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="NegativeHeatingCurve" Id="{c18ef7fb-b184-4ae9-a8c8-5a1b615ecc7a}">
<Declaration><![CDATA[METHOD NegativeHeatingCurve
<Method Name="HeatingCurveZero" Id="{a8a24643-9d4c-47d2-9a52-f8327d36a5c7}">
<Declaration><![CDATA[METHOD HeatingCurveZero // This method checks whether the heating curve can have zero as value
VAR
HeatingCurve: FC_HeatingCurve;
ExpectedValue : REAL := -1;
fSlope: REAL;
fOffset: REAL;
END_VAR
]]></Declaration>
HeatingCurveRes: REAL; //Actual value for Heating Curve
ExpectedValue : REAL := 0; //Expected value for Heating Curve
fSlope: REAL := -1; //Slope of Heating Curve
fOffset: REAL := 35; //Offset of Heating Curve
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('NegativeHeatingCurve');
<ST><![CDATA[TEST('HeatingCurveZero');
HeatingCurve(fTempAmb := 36, fSlope, fOffset);
HeatingCurveRes := FC_HeatingCurve(fTempAmb := 35, fSlope, fOffset);
AssertEquals(Expected := ExpectedValue,
Actual := HeatingCurve,
Actual := HeatingCurveRes,
Message := 'The calculation is not correct');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="NegativeTAmb" Id="{9d838b89-4191-4965-a221-a3d4c4ffe851}">
<Declaration><![CDATA[METHOD NegativeTAmb
<Method Name="TAmbNegative" Id="{9d838b89-4191-4965-a221-a3d4c4ffe851}">
<Declaration><![CDATA[METHOD TAmbNegative // This method checks whether negative ambient temperatures work properly
VAR
HeatingCurve: FC_HeatingCurve;
ExpectedValue : REAL := 40;
fSlope: REAL;
fOffset: REAL;
HeatingCurveRes: REAL; //Actual value for Heating Curve
ExpectedValue : REAL := 40; //Expected value for Heating Curve
fSlope: REAL := -1; //Slope of Heating Curve
fOffset: REAL := 35; //Offset of Heating Curve
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('NegativeTAmb');
<ST><![CDATA[TEST('TAmbNegative');
HeatingCurve(fTempAmb := -5, fSlope, fOffset);
HeatingCurveRes := FC_HeatingCurve(fTempAmb := -5, fSlope, fOffset);
AssertEquals(Expected := ExpectedValue,
Actual := HeatingCurve,
Actual := HeatingCurveRes,
Message := 'The calculation is not correct');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="TAmbZero" Id="{dc201b29-625d-4f36-9a87-0bee747e9dca}">
<Declaration><![CDATA[METHOD TAmbZero
<Declaration><![CDATA[METHOD TAmbZero // This method checks whether zero degrees as ambient temperature work properly
VAR
HeatingCurve: FC_HeatingCurve;
ExpectedValue : REAL := 35;
fSlope: REAL;
fOffset: REAL;
HeatingCurveRes : REAL; //Actual value for Heating Curve
ExpectedValue : REAL := 35; //Expected value for Heating Curve
fSlope: REAL := -1; //Slope of Heating Curve
fOffset: REAL := 35; //Offset of Heating Curve
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('TAmbZero');
HeatingCurve(fTempAmb := 0, fSlope, fOffset);
HeatingCurveRes := FC_HeatingCurve(fTempAmb := 0, fSlope, fOffset);
AssertEquals(Expected := ExpectedValue,
Actual := HeatingCurve,
Actual := HeatingCurveRes,
Message := 'The calculation is not correct');
TEST_FINISHED();]]></ST>
Expand All @@ -111,18 +101,15 @@ TEST_FINISHED();]]></ST>
<LineId Id="15" Count="0" />
<LineId Id="14" Count="0" />
</LineIds>
<LineIds Name="FC_HeatingCurve_Test.FB_init">
<LineId Id="6" Count="0" />
<LineIds Name="FC_HeatingCurve_Test.HeatingCurveNegative">
<LineId Id="13" Count="7" />
<LineId Id="5" Count="0" />
</LineIds>
<LineIds Name="FC_HeatingCurve_Test.HeatingCurveZero">
<LineId Id="14" Count="7" />
<LineId Id="5" Count="0" />
</LineIds>
<LineIds Name="FC_HeatingCurve_Test.NegativeHeatingCurve">
<LineId Id="13" Count="7" />
<LineId Id="5" Count="0" />
</LineIds>
<LineIds Name="FC_HeatingCurve_Test.NegativeTAmb">
<LineIds Name="FC_HeatingCurve_Test.TAmbNegative">
<LineId Id="10" Count="7" />
<LineId Id="5" Count="0" />
</LineIds>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.0">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.6">
<Task Name="PlcTask" Id="{3c0224ee-f1c7-4eb9-90c6-6a2494cd5003}">
<!--CycleTime in micro seconds.-->
<CycleTime>10000</CycleTime>
<Priority>20</Priority>
<PouCall>
<Name>MAIN</Name>
</PouCall>
<PouCall>
<Name>PRG_TEST</Name>
</PouCall>
<TaskFBGuid>{e68f1ea2-454c-4bb4-ac88-1dd654fc7c07}</TaskFBGuid>
<Fb_init>{9dbac7c0-1678-4276-874f-204e11a40588}</Fb_init>
<Fb_exit>{d2c7e825-292c-4a2d-a1bb-63a24f26e098}</Fb_exit>
Expand Down

0 comments on commit f750ae0

Please sign in to comment.