<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%=================================================================
\section{Use of Logic Expressions}
%=================================================================
\wikisec{grp=appendix,file=AppendixLogic,short=Appendix: Logic}
\label{appx_logic}
\index{Logic Expressions}

Logic conditions are employed in both the \app{pHelmIvP},
\app{uTimerScript}, \app{uQueryDB} and \app{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 (\var{.bhv} file). For the
\app{uTimerScript} application, logic conditions are used in the
configuration block of the mission file (\var{.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
\ref{fig_logic}:

\vspace{0.1in}
\begin{figure}[ht]
  \centering 
  \includegraphics[width=0.71\linewidth]{figs_util/util_logic.png}
  \caption{{\bf 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.}
\label{fig_logic}
\end{figure}

\vspace{0.1in}
\noindent
The logic conditions are configured as follows:

\index{Conditions}

\prevblue
\begin{verbatim}
  condition = &lt;logic-expression&gt;
\end{verbatim}
\postverb

\noindent 
The parameter \pvar{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 \var{&lt;logic-expression&gt;} is
described.

%=====================================================================
\subsection*{Simple Relational Expressions}

Each logic expression is comprised of either Boolean operators (and,
or, not) or relation operators ($\leq, &lt;, \geq, &gt;, =, !=$). 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:

\prevblue
\begin{verbatim}
   condition = (DEPLOY   = true)    // Example 1
   condition = (QUALITY &gt;= 75)      // Example 2 
\end{verbatim}
\postverb

\noindent
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 {\em case insensitive}. If for example, in
Example 1 above, the MOOS variable \msvar{DEPLOY} had the value
\var{"TRUE"}, this would satisfy the condition. But if the MOOS
variable \msvar{deploy} (lowercase is unconventional, but legal) had
the value \var{"true"}, this would not satisfy Example 1.

%=====================================================================
\subsection*{Simple Logical Expressions with Two MOOS Variables}

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 \var{\$()}. For example:

\prevblue
\begin{verbatim}
    condition = (REQUESTED_STATE != $(RUN_STATE))     // Example 3
\end{verbatim}
\postverb

\noindent
The variable types need to match or the expression will evaluate to
\var{false} regardless of the relation. The expression in Example 3
will evaluate to \var{false} if, for example,
\msvar{REQUESTED\_STATE="run"} and \msvar{RUN\_STATE=7}, simply because
they are of different type, and regardless of the relation being the
inequality relation.

%=====================================================================
\subsection*{Complex Logic Expressions}

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:

\prevblue
\begin{verbatim}
   condition = (DEPLOY = true) or (QUALITY &gt;= 75)              // Example 4

   condition = (MSG != error) and !((K &lt;= 10) or (w != 0))     // Example 5
\end{verbatim}
\postverb

A relational expression such as \var{(w != 0)} above is false if the
variable \var{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 \var{false} if the variable
in the expression is the wrong type, compared to the literal. For
example \var{(w != 0)} in Example 5 would evaluate to \var{false} even
if the variable \var{w} had the string value \var{"alpha"} which is
clearly not equal to zero.

</pre></body></html>