diff --git a/BaseComponents.tsproj b/BaseComponents.tsproj index 4b3d69d..9938e25 100644 --- a/BaseComponents.tsproj +++ b/BaseComponents.tsproj @@ -116,13 +116,13 @@ - + {9FD32FC8-0CF9-4C5B-95FB-F35423496A77} - + @@ -136,7 +136,7 @@ - + BasicComponents Instance {08500001-0000-0000-F000-000000000064} diff --git a/BasicComponents.library b/BasicComponents.library index dd1cca1..8bc1e02 100644 Binary files a/BasicComponents.library and b/BasicComponents.library differ diff --git a/BasicComponents/BasicComponents.plcproj b/BasicComponents/BasicComponents.plcproj index 2bf2adc..a719c3e 100644 --- a/BasicComponents/BasicComponents.plcproj +++ b/BasicComponents/BasicComponents.plcproj @@ -21,7 +21,7 @@ false Heisig GmbH BaseComponents - 1.2 + 1.3 BC M.Heisig Basic components fb's (Valves, AI, AO, Motors, etc.) @@ -79,6 +79,12 @@ Code + + Code + + + Code + Code @@ -101,9 +107,6 @@ Code - - Code - Code @@ -148,9 +151,6 @@ Code - - Code - Code @@ -302,8 +302,8 @@ - - + + "<ProjectRoot>" {192FAD59-8248-4824-A8DE-9177C94C195A} @@ -2666,6 +2666,12 @@ 410,5410 + {eeeeeeee-3909-4298-8022-501ac3238667} + + "{eeeeeeee-3909-4298-8022-501ac3238667}" + + + {F66C7017-BDD8-4114-926C-81D6D687E35F} "{F66C7017-BDD8-4114-926C-81D6D687E35F}" @@ -2678,16 +2684,16 @@ - - - System.Boolean - System.Collections.Hashtable - System.Int32 - {54dd0eac-a6d8-46f2-8c27-2f43c7e49861} - System.String - System.UInt32 - - + + + System.Boolean + System.Collections.Hashtable + System.Int32 + {54dd0eac-a6d8-46f2-8c27-2f43c7e49861} + System.String + System.UInt32 + + \ No newline at end of file diff --git a/BasicComponents/POUs/Components/AxisPTP/E_AXIS_PTP_STATE.TcDUT b/BasicComponents/POUs/Components/AxisPTP/E_AXIS_PTP_STATE.TcDUT index 8c6fe63..40c18a8 100644 --- a/BasicComponents/POUs/Components/AxisPTP/E_AXIS_PTP_STATE.TcDUT +++ b/BasicComponents/POUs/Components/AxisPTP/E_AXIS_PTP_STATE.TcDUT @@ -13,6 +13,7 @@ TYPE E_AXIS_PTP_STATE : MOVING_ABSOLUTE, MOVING_RELATIVE, MOVING_VELOCITY, + MOVING_MODULO, HALTING, WAIT_FOR_DISABLE, ERROR, diff --git a/BasicComponents/POUs/Components/AxisPTP/FB_AxisPTP.TcPOU b/BasicComponents/POUs/Components/AxisPTP/FB_AxisPTP.TcPOU index 238d5dd..7fa3bf0 100644 --- a/BasicComponents/POUs/Components/AxisPTP/FB_AxisPTP.TcPOU +++ b/BasicComponents/POUs/Components/AxisPTP/FB_AxisPTP.TcPOU @@ -7,7 +7,7 @@ VAR_INPUT xCalibrationCam AT %I* : BOOL; xInvertCalibrationCam : BOOL := FALSE; xEnablePositive : BOOL := TRUE; - xEnableNegative : BOOL := TRUE;; + xEnableNegative : BOOL := TRUE; rOverride : REAL := 100.0; lrVelocity : LREAL; @@ -23,6 +23,7 @@ VAR_OUTPUT lrActPosition : LREAL; xIsStopped : BOOL; xBusy : BOOL; + xDone : BOOL; xError : BOOL; END_VAR VAR @@ -36,6 +37,7 @@ VAR _fbMoveAbsolute : MC_MoveAbsolute; _fbMoveRelative : MC_MoveRelative; _fbMoveVelocity : MC_MoveVelocity; + _fbMoveModulo : MC_MoveModulo; _fbHalt : MC_Halt; _fbReset : MC_Reset; @@ -49,6 +51,7 @@ VAR _xStartMoveAbsolute : BOOL; _xStartMoveRelative : BOOL; _xStartMoveVelocity : BOOL; + _xStartMoveModulo : BOOL; _xHalt : BOOL; _xReset : BOOL; @@ -61,6 +64,7 @@ VAR _xExecuteMoveAbs : BOOL; _xExecuteMoveRel : BOOL; _xExecuteMoveVelocity : BOOL; + _xExecuteMoveModulo : BOOL; _xExecuteHalt : BOOL; @@ -74,7 +78,9 @@ VAR _eHomingMode : MC_HomingMode := MC_HomingMode.MC_DefaultHoming; _xCalibrationCam : BOOL; - _eMoveVelDirection : MC_Direction; + _eMoveDirection : MC_Direction; + + _xCanExecNewCmd : BOOL; _eState : E_AXIS_PTP_STATE; @@ -83,6 +89,7 @@ VAR // Ouput buffers // ============= + _xDone : BOOL; _xBusy : BOOL; _xError : BOOL; END_VAR @@ -91,6 +98,10 @@ END_VAR @@ -403,11 +475,11 @@ END_IF]]> - - + + + + + + - - - 0 THEN +IF rTn > 0 THEN _rDeltaIntegral := (rKp * _rT / rTn) * _rError; ELSE _rDeltaIntegral := 0; @@ -74,9 +69,12 @@ END_IF _rIntegral := _rIntegral + _rDeltaIntegral; // Reset integral with deactivated integral time -IF (rTn = 0.0) AND (_rIntegral <> 0) THEN +IF (rTn <= 0.0) THEN _rIntegral := 0.0; -END_IF]]> +END_IF + +// Calculate controller output +rMV := _rProportional + _rIntegral;]]> \ No newline at end of file diff --git a/BasicComponents/POUs/Components/Controller/FB_PID.TcPOU b/BasicComponents/POUs/Components/Controller/FB_PID.TcPOU new file mode 100644 index 0000000..beb1782 --- /dev/null +++ b/BasicComponents/POUs/Components/Controller/FB_PID.TcPOU @@ -0,0 +1,108 @@ + + + + + + 0 THEN + _rDeltaIntegral := (rKp * _rT / rTn) * _rError; +ELSE + _rDeltaIntegral := 0; +END_IF + +// Only add new integral part if we are going away from the upper or lower bound +IF (xSaturatedUpper AND (_rDeltaIntegral > 0.0)) THEN + _rDeltaIntegral := 0.0; +END_IF + +IF (xSaturatedLower AND (_rDeltaIntegral < 0.0)) THEN + _rDeltaIntegral := 0.0; +END_IF + +// Calculate integral part +_rIntegral := _rIntegral + _rDeltaIntegral; + +// Reset integral with deactivated integral time +IF (rTn <= 0.0) THEN + _rIntegral := 0.0; +END_IF + +IF rTv > 0.0 THEN + _rDeltaPV := (rPV - _rPVLast) / _rT; + + // Unfiltered derivative + _rDRaw := -rKp * rTv * _rDeltaPV; + + // Filter with PT1 + IF rTdFilter > 0.0 THEN + _rDerivative := _rDerivative + (_rT / (rTdFilter + _rT)) * (_rDRaw - _rDerivative); + ELSE + _rDerivative := _rDRaw; + END_IF +ELSE + _rDerivative := 0.0; +END_IF + +_rPVLast := rPV; + +// Calculate controller output +rMV := _rProportional + _rIntegral + _rDerivative;]]> + + + \ No newline at end of file diff --git a/BasicComponents/POUs/Components/Controller/FB_RampGenerator.TcPOU b/BasicComponents/POUs/Components/Controller/FB_RampGenerator.TcPOU new file mode 100644 index 0000000..6a05817 --- /dev/null +++ b/BasicComponents/POUs/Components/Controller/FB_RampGenerator.TcPOU @@ -0,0 +1,91 @@ + + + + + + 0.0); + RETURN; +END_IF + +// Calculate diff to target +_rDiff := rTarget - _rOut; + +// Check if we need to ramp up or down +IF _rDiff > 0 THEN + // Ramp up + _rStep := ABS(rRiseRate) * _rT; + + // Clamp to target value + IF _rStep > _rDiff THEN + _rOut := rTarget; + ELSE + _rOut := _rOut + _rStep; + END_IF +ELSIF _rDiff < 0 THEN + // Ramp down + _rStep := ABS(rFallRate) * _rT; + + // Clamp to target value + IF _rStep > ABS(_rDiff) THEN + _rOut := rTarget; + ELSE + _rOut := _rOut - _rStep; + END_IF +END_IF + +// Handle busy flag +xBusy := (ABS(rTarget - _rOut) > 0.0); + +// Copy internals to outputs +rOut := _rOut;]]> + + + + + + + + + \ No newline at end of file diff --git a/BasicComponents/POUs/Components/Utilities/FB_RampGenerator.TcPOU b/BasicComponents/POUs/Components/Utilities/FB_RampGenerator.TcPOU deleted file mode 100644 index 5983a0e..0000000 --- a/BasicComponents/POUs/Components/Utilities/FB_RampGenerator.TcPOU +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - T#0S THEN - _rRampUpSpeed := (rTargetMax - rTargetMin) * (_rCycleTime / TIME_TO_REAL(timRampUp)); -ELSE - _rRampUpSpeed := rTargetMax; -END_IF -IF timRampDown <> T#0S THEN - _rRampDownSpeed := -(rTargetMax - rTargetMin) * (_rCycleTime / TIME_TO_REAL(timRampDown)); -ELSE - _rRampDownSpeed := -rTargetMax; -END_IF - - -// Calculate distance left to go -_rDistanceToGo := rTarget - rSetpoint; - -// Calculate new setpoint -IF (_rDistanceToGo > 0.0) THEN - IF (_rDistanceToGo > _rRampUpSpeed) THEN - rSetpoint := rSetpoint + _rRampUpSpeed; - ELSE - rSetpoint := rTarget; - END_IF -ELSIF (_rDistanceToGo < 0.0) THEN - IF (_rDistanceToGo < _rRampDownSpeed) THEN - rSetpoint := rSetpoint + _rRampDownSpeed; - ELSE - rSetpoint := rTarget; - END_IF -ELSE - rSetpoint := rTarget; -END_IF - -// Check if we are in range of target range -IF ABS(rSetpoint-rTarget) <= 0.001 THEN - xInTarget := TRUE; -ELSE - xInTarget := FALSE; -END_IF ]]> - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/BasicComponents/POUs/HMI/Datentypen/ST_HMI_ORP_SENSOR_DATA.TcDUT b/BasicComponents/POUs/HMI/Datentypen/ST_HMI_ORP_SENSOR_DATA.TcDUT deleted file mode 100644 index 941f421..0000000 --- a/BasicComponents/POUs/HMI/Datentypen/ST_HMI_ORP_SENSOR_DATA.TcDUT +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/BasicComponents/POUs/Unittests/UtilitiesTests/FB_RampGeneratorTest.TcPOU b/BasicComponents/POUs/Unittests/UtilitiesTests/FB_RampGeneratorTest.TcPOU index d09b19a..5667299 100644 --- a/BasicComponents/POUs/Unittests/UtilitiesTests/FB_RampGeneratorTest.TcPOU +++ b/BasicComponents/POUs/Unittests/UtilitiesTests/FB_RampGeneratorTest.TcPOU @@ -3,17 +3,6 @@ - - - - 0.001 THEN - AssertTrue(FALSE, 'Project cycle time not set to 10ms!'); -ELSE - _fbRampGen( - rTarget:= 0.0, - rTargetMin:= 0.0, - rTargetMax:= 100.0, - timRampUp:= T#5S, - timRampDown:= T#5S, - rSetpoint=> , - xInTarget=> ); - - // Project should be set to 10ms cycle time for this test to work - AssertEquals_REAL(Expected := 10.0, Actual := _fbRampGen.CycleTime, Delta := 0.01, 'Cycle time is not equal to project cycle time (10ms)'); -END_IF - -TEST_FINISHED();]]> - - _rSetpoint, - xInTarget => _xInTarget); + rRiseRate := 2, + rFallRate := 2, + rOut => _rSetpoint, + xBusy =>); // check for whether InTarget is reached at the specified time IF NOT _fbDelayInTargetResultDown.Q THEN - AssertFalse(_xInTarget, 'InTarget reached earlier then expected.'); + AssertTrue(_fbRMPInTargetResultDown.xBusy, 'InTarget reached earlier then expected.'); ELSE - AssertTrue(_xInTarget, 'InTarget not reached in time.'); + AssertFalse(_fbRMPInTargetResultDown.xBusy, 'InTarget not reached in time.'); TEST_FINISHED(); END_IF]]> @@ -138,16 +84,13 @@ END_IF]]> _rSetpoint, - xInTarget => _xInTarget); + rRiseRate := 2, + rFallRate := 2, + rOut => _rSetpoint, + xBusy => ); // check for whether InTarget is reached at the specified time -IF NOT _fbDelayInTargetResultUp.Q THEN - AssertFalse(_xInTarget, 'InTarget reached earlier then expected.'); +IF (NOT _fbDelayInTargetResultUp.Q) THEN + AssertTrue(_fbRMPInTargetResultUp.xBusy, 'InTarget reached earlier then expected.'); ELSE - AssertTrue(_xInTarget, 'InTarget not reached in time.'); + AssertFalse(_fbRMPInTargetResultUp.xBusy, 'InTarget not reached in time.'); TEST_FINISHED(); -END_IF]]> - - - - - - _rSetpoint, - xInTarget =>); - -// check for clamping -IF NOT _fbDelayMaxClamp.Q THEN - // too early - AssertTrue(_rSetpoint < rExpected,'Clamped value reached before expected time'); -ELSE - // after expected rampTime - IF NOT _fbDelayMaxClampBuffer.Q THEN - AssertEquals_REAL(Expected := rExpected, Actual := _rSetpoint, Delta := rDelta, 'Value did not stay on or did not reach MaxTarget'); - ELSE - TEST_FINISHED(); - END_IF -END_IF]]> - - - - - - _rSetpoint, - xInTarget =>); - -// check for clamping -IF NOT _fbDelayMinClamp.Q THEN - // too early - AssertTrue(_rSetpoint >= (rExpected - rDelta), 'Clamped value reached before expected time'); -ELSE - // after expected rampTime - IF NOT _fbDelayMinClampBuffer.Q THEN - AssertEquals_REAL(Expected := rExpected, Actual := _rSetpoint, Delta := rDelta, 'Value did not stay on or did not reach MinTarget'); - ELSE - TEST_FINISHED(); - END_IF END_IF]]> @@ -297,31 +129,30 @@ END_VAR VAR CONSTANT // expected final value - rExpected : REAL := -9.4564; + rExpected : REAL := -0.8; // delta for assertion rDelta : REAL := 0.0001; // delay until final value is reached - timDelay : TIME := T#470MS; + timDelay : TIME := T#790MS; END_VAR]]> _rSetpoint, - xInTarget =>); + xEnable := TRUE, + rTarget := -1, + rRiseRate := 1, + rFallRate := 1, + rOut => _rSetpoint, + xBusy =>); // check for current expected value IF NOT _fbDelayRampDownContinuity.Q THEN @@ -360,12 +191,10 @@ _fbDelayRampDownTime(IN := TRUE, PT := timDelay); // run RampGenerator _fbRMPRampDownTime( rTarget := -7.4367, - rTargetMin := -10, - rTargetMax := 10, - timRampUp := T#500MS, - timRampDown := T#100MS, - rSetpoint => _rSetpoint, - xInTarget =>); + rRiseRate := 20, + rFallRate := 100, + rOut => _rSetpoint, + xBusy =>); // check whether final value is reach on time or before IF NOT _fbDelayRampDownTime.Q THEN @@ -390,31 +219,30 @@ END_VAR VAR CONSTANT // expected final value - rExpected : REAL := 8.673; + rExpected : REAL := 0.8; // delta for assertions rDelta : REAL := 0.0001; // delay until final value is reached - timDelay : TIME := T#860MS; + timDelay : TIME := T#790MS; END_VAR]]> _rSetpoint, - xInTarget =>); + xEnable := TRUE, + rTarget := 2, + rRiseRate := 1, + rFallRate := 1, + rOut => _rSetpoint, + xBusy =>); // check for current expected value IF NOT _fbDelayRampUpContinuity.Q THEN @@ -436,13 +264,13 @@ END_VAR VAR CONSTANT // expected final value - rExpected : REAL := 8.3456; + rExpected : REAL := 0.55; // delta for assertions rDelta : REAL := 0.0001; // delay until final value is reached - timDelay : TIME := T#440MS; + timDelay : TIME := T#550MS; END_VAR]]> _rSetpoint, - xInTarget =>); + rTarget := 0.55, + xEnable := TRUE, + rRiseRate := 1, + rFallRate := 100, + rOut => _rSetpoint, + xBusy =>); // check whether final value is reach on time or before IF NOT _fbDelayRampUpTime.Q THEN