Skip to content

Commit

Permalink
tests for 2-way-actuator
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuergen committed Oct 9, 2024
1 parent 46b63a6 commit dc6c29a
Showing 1 changed file with 88 additions and 23 deletions.
111 changes: 88 additions & 23 deletions test/TwoWayActuatorTest.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.Commands;
USING Simatic.Ax.axftcmlib;
USING Simatic.Ax.IO.Output;
Expand All @@ -8,50 +9,114 @@ NAMESPACE Simatic.Ax.axftcmlib
{TestFixture}
CLASS TwoWayActuatorTest
VAR PROTECTED
_actuator : TimeBasedActuator;
_actuatorStateLess : TimeBasedActuator;
_output : BinOutput;
_actuator : TwoWayActuator;
_actuatorStateLess : TwoWayActuator;
_qToWork : BinOutput;
_qToHome : BinOutput;
_outputStateLess : BinOutput;
_iInHomePos : BinSignal;
_iInWorkPos : BinSignal;
_binSignalStateless : BinSignal;
cmd : itfCommand;
done : BOOL;
busy : BOOL;
END_VAR

{TestSetup}
METHOD PUBLIC SetUp
_actuator := _actuatorStateLess;
_actuator.Q_ToWorkPosition := _output;
_actuator.Q_ToWorkPosition := _qToWork;
_actuator.Q_ToHomePosition := _qToHome;
_actuator.I_InHomePosition := _iInHomePos;
_actuator.I_InWorkPosition := _iInWorkPos;
_iInHomePos := _binSignalStateless;
_iInWorkPos := _binSignalStateless;
_qToWork := _outputStateLess;
_qToHome := _outputStateLess;
busy := FALSE;
END_METHOD

{Test}
METHOD PUBLIC TestTurnPneumaticCylinderPush_Expect_state_is_On
{Test}
METHOD PUBLIC GoToWorkPosition_Swiches_Q_ToWorkPosition_On_And_Returns_Busy
cmd := _actuator.GoToWorkPosition();
busy := cmd.Busy();
AxUnit.Assert.Equal(expected := TRUE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := _output.IsOn());
AxUnit.Assert.Equal(expected := TRUE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#MoveToWorkPosition);
END_METHOD

{Test}
METHOD PUBLIC GoToWorkPosition_Returns_Done_When_end_position_is_already_reached
_iInWorkPos.ReadCyclic(signal := TRUE);
cmd := _actuator.GoToWorkPosition();
busy := cmd.Busy();
IF NOT(busy) THEN
done := cmd.Done();
END_IF;
AxUnit.Assert.Equal(expected := FALSE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := done);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#InWorkPosition);
END_METHOD

{Test}
METHOD PUBLIC Reaching_WorkPosition_Switches_Q_ToWorkPosition_Off_And_Returns_Done
THIS.GoToWorkPosition_Swiches_Q_ToWorkPosition_On_And_Returns_Busy();
_iInWorkPos.ReadCyclic(signal := TRUE);
busy := cmd.Busy();
IF NOT(busy) THEN
done := cmd.Done();
END_IF;
AxUnit.Assert.Equal(expected := FALSE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := done);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#InWorkPosition);
END_METHOD


// Test Home Position
{Test}
METHOD PUBLIC TestZylinderNotAsigned_Expected_ErrorFound_is_True
VAR
Test : BOOL;
END_VAR
_actuator.Q_ToWorkPosition := NULL;
_actuator.Busy();
AxUnit.Assert.Equal(Expected := TRUE, actual := _actuator.Error());
;
METHOD PUBLIC GoToHomePosition_Swiches_Q_ToHomePosition_On_And_Returns_Busy
cmd := _actuator.GoToHomePosition();
busy := cmd.Busy();
AxUnit.Assert.Equal(expected := TRUE, actual := busy);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := TRUE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#MoveToHomePosition);
END_METHOD

{Test}
METHOD PUBLIC TestPneumaticCylinderError_Expected_ErrorFound_TRUE
VAR
Test : BOOL;
END_VAR

Test := _actuator.Error();
AxUnit.Assert.Equal(Expected := FALSE, actual := Test);
;
METHOD PUBLIC GoToHomePosition_Returns_Done_When_end_position_is_already_reached
_iInHomePos.ReadCyclic(signal := TRUE);
cmd := _actuator.GoToHomePosition();
busy := cmd.Busy();
IF NOT(busy) THEN
done := cmd.Done();
END_IF;
AxUnit.Assert.Equal(expected := FALSE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := done);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#InHomePosition);
END_METHOD

{Test}
METHOD PUBLIC Reaching_HomePosition_Switches_Q_ToHomePosition_Off_And_Returns_Done
THIS.GoToHomePosition_Swiches_Q_ToHomePosition_On_And_Returns_Busy();
_iInHomePos.ReadCyclic(signal := TRUE);
busy := cmd.Busy();
IF NOT(busy) THEN
done := cmd.Done();
END_IF;
AxUnit.Assert.Equal(expected := FALSE, actual := busy);
AxUnit.Assert.Equal(expected := TRUE, actual := done);
AxUnit.Assert.Equal(expected := FALSE, actual := _qToWork.IsOn());
AxUnit.Assert.Equal(expected := FALSE, actual := _qToHome.IsOn());
Equal(expected := TRUE, actual := _actuator.GetState() = ActuatorState#InHomePosition);
END_METHOD
END_CLASS

END_NAMESPACE

0 comments on commit dc6c29a

Please sign in to comment.