OnOffController
- Namespace
- ZEquipment
- Implements
FUNCTION_BLOCK OnOffController IMPLEMENTS ZCore.IObject, ZCore.IError (
[output] Diagnostics : ZCore.DiagnosticMessage)
In control theory a on off controller is a controller with a feedback and a digital output to switch abruptly between two states. Usually this type of system is used to control hydraulic levels, pressure or also heat in a water heating system. In general these processes do not have high dynamic requirements..
This function block has to be provided with a digital output which controls the actor of the control system and an analog input which measures the actual value of the controlled system. E.g. a pressurized system with the digital output it is possible to switch on and off a compressor. The analog input measures the actual pressure in the system.
In order to function as supposed one has to provide an upper limit, a lower limit as on and off thresholds and a feedback tolerance to detect runaway events like a wire break for the digital output or a stuck relais. There is also a timeout and a duration parameter which is necessary to observe the settling of the controlled system.
If the feedback (analog input) is simulated, this function block will automatically write random values in the range of (switchOnAt, switchOffAt) to the analog input in order to simulate a working behavior of the controller
The controller triggers an error if the settling is not ok within the parameterized settling timeout or if the feedback value gets outside its on and off limits always taking the feedback tolerance into account.
See the following diagram for more information on how the OnOffController switches the digital output:
- FeedbackTolerance: Defines the threshold value for the Settled property in physical units of the feedback analogue input
- Hysteresis: When parametrizing the controller with SetReference this value is defined by 2*hysteresis around reference value
- Settled=TRUE range: This range is defined by 2*hysteresis + feedbackTolerance
Note
The simulation behavior of the OnOffController depends on the feedback input only. If this object is set to Simulation:=TRUE then the OnOffController will also calculate a simulated trajectory of the feedback input and therefore simulate its behavior. It is also possible to set the OnOffController to Simulation:=TRUE which will propagate this setting to the input and output automatically.
Note
It is important to note, that if one sets the direct used feedback input of the OnOffController to Simulation:=FALSE, after initialization of OnOffController itself with Simulation:=TRUE, this last call will set the final Simulation config, which is in this case Simulation:=FALSE.
Outputs
Diagnostics
DiagnosticMessage
Constructor
FB_init
METHOD FB_init (
[input] bInitRetains : BOOL,
[input] bInCopyCode : BOOL,
[input] parent : ZCore.IManagedObject,
[input] output : IDigital,
[input] feedback : IAnalog) : BOOL
This method defines the constructor of this object. In order work properly the OnOffController needs a parent which is in charge of calling the Cyclic method, a digital output which controls the actor of the controlled system and an analog input which provides the feedback signal for the control loop. These objects have to be present in construction phase of this object.
Inputs
bInitRetains
BOOLif TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode
BOOLif TRUE, the instance afterwards gets moved into the copy code (online change)
parent
IManagedObjectInterface to the ManagedObject that is the parent of this object
output
IDigitalInterface to the IDigital that should be used to control the actor of the controlled system
feedback
IAnalogInterface to the IAnalog that is used as the actual feedback input for the controller
Returns
- BOOL
Properties
Busy
PROPERTY Busy : BOOL
Property Value
- BOOL
Done
PROPERTY Done : BOOL
If the object is in idle state (often mentioned as "the object is not busy and not on error"),
this is indicated by this property returning TRUE
.
Property Value
- BOOL
Enabled
PROPERTY Enabled : BOOL
This property returns the actual state of the internal initialized digital output. If the controller is working and the controlled output is set, this property will return TRUE, otherwise FALSE. The output state of this digital output can also be retrieved by using the actual digital output
Property Value
- BOOL
Error
PROPERTY Error : BOOL
Property Value
- BOOL
Feedback
PROPERTY Feedback : IAnalog
This property provides the interface of the feedback of the controllers as it has be initialized with the constructor.
Property Value
FeedbackTolerance
PROPERTY FeedbackTolerance : LREAL
Maximum and minimum value of the feedback input given in %. If the feedback gets outside these values the controller will trigger an error.
Use 0
to disable this feature.
This property is used for the settling feature of the OnOffController, see SetSettling for details.
Property Value
- LREAL
InRange
PROPERTY InRange : BOOL
This property returns TRUE if the controller has been started and the feedback value is in between the provided on and off limits set by SetOnOffThreshold also taking the feedbackTolerance into account.
See the following diagram for more information on when this property returns TRUE:
Property Value
- BOOL
Settled
PROPERTY Settled : BOOL
This property returns TRUE if the controller has been started and the feedback value is in between the given on and off threshold also tolerating the parameterized tolerance with SetSettling
Property Value
- BOOL
SettlingDuration
PROPERTY SettlingDuration : LREAL
Minimum duration in seconds which the feedback has to be inside the on and off range (including feedback tolerance).
Use 0
to disable this feature.
This property is used for the settling feature of the OnOffController, see SetSettling for details.
Property Value
- LREAL
SettlingTimeout
PROPERTY SettlingTimeout : LREAL
Maximum time in seconds which it can take the controller to get the feedback value into the given range of on and off value.
Use 0
to disable this feature.
This property is used for the settling feature of the OnOffController, see SetSettling for details.
Property Value
- LREAL
Simulation
PROPERTY Simulation : BOOL
With this property the simulation behavior of the OnOffController can be set. If set to TRUE the Feedback and control output is also set to simulation on, if FALSE then the simulation will be turned off.
Property Value
- BOOL
State
PROPERTY State : ZCore.ObjectState
Returns the object state of the axis object. This exposes if an object is still in its booting phase, had an error, or is busy executing an async action.
Property Value
SwitchOffThreshold
PROPERTY SwitchOffThreshold : LREAL
Feedback value at which the controller switches off its output. Provide here the same units as initialized at the analog input. This property is a shortcut to set this threshold directly, see SetOnOffThreshold for details.
Property Value
- LREAL
SwitchOnThreshold
PROPERTY SwitchOnThreshold : LREAL
Feedback value at which the controller switches on its output. Provide here the same units as initialized at the analog input. This property is a shortcut to set this threshold directly, see SetOnOffThreshold for details.
Property Value
- LREAL
Methods
ErrorId
METHOD ErrorId () : UDINT
Returns the error code of the first error source for this object. The method recursively goes down the error stack until the initial source of error of this object can be found. For performance reasons, the error stack is not cleared when the error state is reset. So this method should always used in conjunction with Error.
Returns
- UDINT
ErrorMessage
METHOD ErrorMessage () : ZCore.ZString
Returns the error description of the first error source for this object. The method recursively goes down the error stack until the initial source of error of this object can be found. For performance reasons, the error stack is not cleared when the error state is reset. So this method should always used in conjunction with Error.
Returns
ErrorSource
METHOD ErrorSource () : ZCore.IError
This method returns the direct error source of this object. This method can then be used to retrieve the actual error source by using the method of the returned IError.
Returns
Name
METHOD FINAL Name () : ZCore.ZString
This method returns the name that has been set with SetName during initialization phase.
Returns
RunAsync
METHOD RunAsync (
[input] startToken : ZCore.IStartToken)
This method starts the opreation of the OnOffController. After calling and the feddback value is outside its initialized on and off boundaries it sets the output and tries to hold the feedback in between the parameterized values. It only stops doing this if an error occurs like exceeding the on or off boundaries (always taking the feedbackTolerance into account) or if you stop it by calling the stop method
Before starting the OnOffController, one has to set the On- & Off- Thresholds with SetOnOffThreshold or it is also possible to set a reference value and a specific hysteresis for symetric on and off thresholds with SetReference. It is also important to provide a digital output for controlling the actuator of the system and an analog input for the feedback value of the control loop.
Inputs
startToken
IStartToken
SetLogger
METHOD SetLogger (
[input] logger : ZCore.ILogger)
With this method an optional logger may be passed to this object. The object then informs about errors, starting, stopping actions and so on. The logger of the IDigital and IAnalog that is passed when constructing this object is not influenced by this method and have to be set in the according initialization phases.
Inputs
logger
ILogger
SetName
METHOD SetName (
[input] name : ZCore.ZString)
The name of this object is used for identification to simplify debugging, especially when generating log messages in an application. It can be set during initialization while constructing the function block or anywhere, at any time in the application
Inputs
name
ZStringname of the controller usually set with context to the process
SetOnOffThreshold
METHOD SetOnOffThreshold (
[input] switchOnAt : LREAL,
[input] switchOffAt : LREAL)
This method is used to set the desired feedback boundaries for on and off of this controller. The output is switched off, if the feedback value is greater than switchOffAt and it gets switched on, if the feedback value is smaller than switchOnAt. In order to function properly these parameters have to be provided in correct units which are also parametrized by the initialzed analog input. When changing the values while the controller is already busy, the settling timeout is reset.
Inputs
switchOnAt
LREALfeedback value at which the controller switches on its output. Provide here the same units as initialized at the analog input
switchOffAt
LREALfeedback value at which the controller switches off its output. Provide here the same units as initialized at the analog input
SetReference
METHOD SetReference (
[input] referenceValue : LREAL,
[input] hysteresis : LREAL)
This method is used to set the desired feedback boundaries for on and off of this controller by providing the reference value as mean value surrounded by a hysteresis for on and off. The output is switched off, if the feedback value is greater than switchOffAt and it gets switched on, if the feedback value is smaller than switchOnAt. In order to function properly these parameters have to be provided in correct units which are also parametrized by the initialzed analog input.
Internally the OnOffController calls SetOnOffThreshold with switchOnAt as referenceValue - hysteresis and referenceValue + hysteresis for the parameter switchOffAt.
SetOnOffThreshold(referenceValue - hysteresis, referenceValue + hysteresis);
Inputs
referenceValue
LREALdesired process value to which the on off controller should get the feedback value by controlling the process
hysteresis
LREALhysteresis around the reference value which defines the on and off value
SetSettling
METHOD SetSettling (
[input] settlingDuration : LREAL,
[input] settlingTimeout : LREAL,
[input] feedbackTolerance : LREAL)
This method can be used to parameterize a duration that the feedback has to be stable (actual value matched the nominal value within its tolerance) in order for the Settled property to return TRUE. The actual tolerance is taken into account in the form switchOnAt - feedbackTolerance, switchOffAt + feedbackTolerance such that it closely resembles the behavior of OnOffController.
Inputs
settlingDuration
LREALThe feedback value has to be at least for settlingDuration seconds between On-tolerance and Off+tolerance, use
0
to disable this feature.settlingTimeout
LREALAfter settlingTimeout seconds the feedback has to reach at least the onValue otherwise the OnOffController will signal an error, use
0
to disable this feature.feedbackTolerance
LREALDefines the threshold value for the Settled property in physical units of the feedback analogue input for on and off value, use
0
to disable this feature.
SetSimulation
METHOD SetSimulation (
[input] on : BOOL)
With this method the simulation behavior of the OnOffController can be set. If set to TRUE the Feedback and control output is also set to simulation on, if FALSE then the simulation will be turned off. Also when simulation is on, the OnOffController simulates the process by writing simulated values to the feedback and therefore the OnOffController can function properly.
Inputs
SetSimulationParameter
METHOD SetSimulationParameter (
[input] feedbackNoise : LREAL,
[input] disabledGain : LREAL,
[input] enabledGain : LREAL)
If Simulation is activated for the OnOffController, this method can be used to adjust some parameters that are used to simulate the feedback of the controller. The parameters of this method are based on the parameters that are set with SetSettling.
- feedbackNoise, feedback noise in percent (0-100) relative to the feedback-tolerance range which is added to the (simulated) feedback, defaults to 1 percent
Inputs
feedbackNoise
LREALIn percent, based on
feedbackTolerance
, defaults to 1disabledGain
LREALControls how much the feedback changes in every cycle relative to
(switchOffThreshold-switchOnThreshold) / settlingDuration
times the deviation from the nominal value, if the controller is disabled, defaults to 0.4enabledGain
LREALControls how much the feedback changes in every cycle relative to
(switchOffThreshold-switchOnThreshold) / settlingDuration
time sthe deviation from the nominal value, if the controller is enabled, defaults to 1
Stop
METHOD Stop ()
This method explictly stops the OnOffController and resets the output. After that all observing mechanisms are switched off and are only turned on by calling RunAsync again. If the OnOffController is on error, it can simply be started by calling RunAsync again, there is no need for calling Stop beforehand.
TraceErrorStack
METHOD TraceErrorStack (
[input] trace : ZCore.IErrorTrace)
This method is used internally when recording an error trace.
Inputs
trace
IErrorTrace