Activity Programs are a diagrammatic approach to programming, this is very similar to creating logic diagrams.
Variable Usage: The value of a variable in use is passed to the Activity Program and a local copy is made when the activity is called. The local copy can then be used for various purposes within the activity. The local copy of the variable cannot be changed by the system variable once the activity is running. Upon exiting the activity program, the system variable is then updated with the value of the local copy. This includes variables used in Activity Programs (child activities) called from the main Activity. For this reason you cannot create loops or wait states where the value of a local variable is waiting on a change in the value of its system variable.
Loops: Loops are not recommended since all variable values are local to the activity until it terminates. Typically a loop requires the value of a variable to change from an external event however this new value will not get passed to the local variable and it will remain stuck in the loop and lock up the display.
Start Block: This is the entry point for the program.
Decision Block: This is a branch function and operates similar to a if/else statements. If the expression evaluates true then branch to the true connector else branch to the false connector.
Multi-Decision Block: This is similar to a case statement, each condition is evaluated and program flow will branch to the first one to evaluate true.
Fire Action Block: When the program flow enters this block the listed actions will be fired.
Set Variable Block: When the program flow enters this block the variables listed will be set to the values in the expression.
Activity Block: If the program flow becomes too complicated a section can be moved to its own activity program much like you would treat a subroutine. The rules for the value of variables apply for these activities as well. Local copies of any variables used by the child activity are created at the time the parent activity is called.
Local Variables: A local variable can be created and used within the activity or passed between activities when using the Activity Block to call a child activity. The button to create local variables is on the bottom left of the diagram window.
Internal Message: This is simplified method of generating a internal DM1 message, when this block is loaded with data a message is passed to the DM1 app that a new fault is available for handling. If using the DM1 message handler found in the templates this message will appear as a pop-up fault message.
Add List Item: This is a convenient way to add items to a existing custom list without having to use scripting.
Stop Block: All program branches must terminate in the stop block.
The following Activity Program example is a continuation of our engine temperature control system. We have previously demonstrated how to implement this same logic using State Machines and Scripting this example shows how to perform the same functions using and Activity Program.
In this video we will show how to use a Activity Program to monitor an engines coolant temperature and determine if it is too cold or too hot and either turn on a heater or fan cooling. There are three states the engine can exist in, nominal, under temp, and over temp. The activity program uses a multi decision block to determine which state it is in then branch to control the fan and heater.
See More Examples: Simple Engine State Machine
Video Tutorial
Comments
0 comments
Please sign in to leave a comment.