Use of Logic Expressions
Maintained by: mikerb@mit.edu Get PDF
src: project-pavlab/chapters/chap_appendix_logic
1 Use of Logic Expressions
1 Use of Logic Expressions
Logic conditions are employed in both the pHelmIvP, uTimerScript, uQueryDB and alogcheck applications, and others, to condition certain activities based on the prescribed logic state of elements of the MOOSDB. The use of logic conditions in the helm is done in behavior file (.bhv file). For the uTimerScript application, logic conditions are used in the configuration block of the mission file (.moos file). The MOOS application using logic conditions maintains a local buffer representing a snapshot of the MOOSDB for variables involved in the logic expressions. The key relationships and steps are shown in :
Figure 1.1: Logic conditions in a MOOS application: Step 1: the applications registers to the MOOSDB for any MOOS variables involved in the logic expressions. Step 2: The MOOS application reads incoming mail from the MOOSDB. Step 3: Any new mail results in an update to the information buffer. Step 4: Within the application's Iterate() method, the logic expressions are evaluated based on the contents of the information buffer.
The logic conditions are configured as follows:
condition = <logic-expression>
The parameter condition is case insensitive. When multiple conditions are specified, it is implied that the overall criteria for meeting conditions is the conjunction of all such conditions. In what remains below, the allowable syntax for <logic-expression> is described.
Simple Relational Expressions [top]
Each logic expression is comprised of either Boolean operators (and, or, not) or relation operators (). All expressions have at least one relational expression, where the left-hand side of the expression is a MOOS variable, and the right-hand side is a literal (either a string or numerical value). The literals are treated as a string value if quoted, or if the value is non-numerical. Some examples:
condition = (DEPLOY = true) // Example 1 condition = (QUALITY >= 75) // Example 2
Variable names are case sensitive since MOOS variables in general are case sensitive. In matching string values of MOOS variables in Boolean conditions, the matching is case insensitive. If for example, in Example 1 above, the MOOS variable DEPLOY had the value "TRUE", this would satisfy the condition. But if the MOOS variable deploy (lowercase is unconventional, but legal) had the value "true", this would not satisfy Example 1.
Simple Logical Expressions with Two MOOS Variables [top]
A relational expression generally involves a variable and a literal, and the form is simplified by insisting the variable is on the left and the literal on the right. A relational expression can also involve the comparison of two variables by surrounding the right-hand side with $(). For example:
condition = (REQUESTED_STATE != $(RUN_STATE)) // Example 3
The variable types need to match or the expression will evaluate to false regardless of the relation. The expression in Example 3 will evaluate to false if, for example, REQUESTED_STATE="run" and RUN_STATE=7, simply because they are of different type, and regardless of the relation being the inequality relation.
Complex Logic Expressions [top]
Individual relational expressions can be combined with Boolean connectors into more complex expressions. Each component of a Boolean expression must be surrounded by a pair of parentheses. Some examples:
condition = (DEPLOY = true) or (QUALITY >= 75) // Example 4 condition = (MSG != error) and !((K <= 10) or (w != 0)) // Example 5
A relational expression such as (w != 0) above is false if the variable w is undefined. In MOOS, this occurs if the variable has yet to be published with a value by any MOOS client connected to the MOOSDB. A relational expression is also false if the variable in the expression is the wrong type, compared to the literal. For example (w != 0) in Example 5 would evaluate to false even if the variable w had the string value "alpha" which is clearly not equal to zero.
Document Maintained by: mikerb@mit.edu
Page built from LaTeX source using texwiki, developed at MIT. Errata to issues@moos-ivp.org. Get PDF