<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[onecolumn,letterpaper,11pt]{article}

%===================================================================
\input{common_latex/common_latex_packages}
\input{common_latex/common_latex_definitions}
\input{common_latex/common_latex_help_format}
%===================================================================

\begin{document}

\begin{labcover}
\labtitle{Help Topic: Scripted Pokes to the MOOSDB}
\vspace{0.1in}
\labdate{Spring 2020}
\vspace{0.1in}
\labauth{Michael Benjamin, mikerb@mit.edu}
\labauth{Department of Mechanical Engineering}
\labauth{MIT, Cambridge MA 02139}
\labline
\end{labcover}

\wikidoc{file=Help.MIPScripted}
\wikidoc{auth=mikerb@mit.edu}

%====================================================================
\section*{Scripted Pokes to the MOOSDB}
%====================================================================
\label{sec_scripted_pokes}

Here we cover how to have a script of pre-arranged pokes to the
\app{MOOSDB}. This may be useful for a number of reasons besides
debugging. The primary tool described here is the \app{uTimerScript}
MOOS application. It is capable of (a) scripted pokes at pre-defined
times after launch, (b) pokes having a poke-time specified to fall
randomly within a specified interval, (c) pokes having numerical
values falling with a uniformly random interval, and several other
features including conditioning the running of the script based on
other MOOS variables.

\pskip
\noindent
Where to get more information:

\begin{packed_itemize}[0]
\item \app{uTimerScript}: \urlx{http://oceanai.mit.edu/ivpman/apps/uTimerScript}
\end{packed_itemize}

\vspace{0.1in}
\noindent
Or simply:

\vspace{0.1in}
\begin{consoleverb}
$ uTimerscript --web
\end{consoleverb}
\vspace{0.1in}


%====================================================================
\subsection*{Basic uTimerScript Usage}

\app{uTimerScript} is configured with its own block in the MOOS
configuration file. The general format is below. The primary entries
are the events themselves, defined by a MOOS variable, value, and time
or time-range when the event is to occur. There are many options for
configuring the script. These options are described in the
documentation, but a quick look at the options can be seen by typing
\cmd{uTimerScript --example} on the command line.

\vspace{0.15in}
\begin{fileverb}
ProcessConfig = uTimerScript
{
  event = var=&lt;MOOSVar&gt;, val=&lt;value&gt;, time=&lt;value&gt;
  event = var=&lt;MOOSVar&gt;, val=&lt;value&gt;, time=&lt;value&gt;
  ...
  event = var=&lt;MOOSVar&gt;, val=&lt;value&gt;, time=&lt;value&gt;

  [OPTIONS]
}
\end{fileverb}
\vspace{0.15in}

%====================================================================
\newpage
\subsection*{A Simple Example with uTimerScript}

The below mission file contains a \cmd{uTimerScript} script for
repeatedly posting the variable \var{COUNTER\_A} with values 1-10 in
ascending order roughly once every half second. The last event in the
script is posted at time chosen from a random five second interval.

\vspace{0.15in}
\begin{listing}{A simple counter example with uTimerScript}
\label{lst_utscript_counter}

\begin{fileverb}
// (wget http://oceanai.mit.edu/2.680/examples/utscript.moos)
ServerHost = localhost
ServerPort = 9000
Community  = alpha

ProcessConfig = ANTLER
{
  MSBetweenLaunches = 200

  Run = MOOSDB       @ NewConsole = false
  Run = uXMS         @ NewConsole = true
  Run = uTimerScript @ NewConsole = false
}

ProcessConfig = uXMS
{
  VAR            = COUNTER_A, DB_CLIENTS, DB_UPTIME
  COLOR_MAP      = COUNTER_A, red
  HISTORY_VAR    = COUNTER_A
}

ProcessConfig = uTimerScript
{
  paused = false

  event  = var=COUNTER_A, val=1,  time=0.5
  event  = var=COUNTER_A, val=2,  time=1.0
  event  = var=COUNTER_A, val=3,  time=1.5
  event  = var=COUNTER_A, val=4,  time=2.0
  event  = var=COUNTER_A, val=5,  time=2.5
  event  = var=COUNTER_A, val=6,  time=3.0
  event  = var=COUNTER_A, val=7,  time=3.5
  event  = var=COUNTER_A, val=8,  time=4.0
  event  = var=COUNTER_A, val=9,  time=4.5
  event  = var=COUNTER_A, val=10, time=5:10

  reset_max  = nolimit
  reset_time = all-posted
}
\end{fileverb}
\end{listing}
\vspace{0.15in}

\noindent
The mission may be launched from the command-line with:

\vspace{0.1in}
\begin{consoleverb}
 $ pAntler utscript.moos
\end{consoleverb}
\vspace{0.15in}

\noindent
This should open a new console window for \app{uXMS} displaying the
variables \var{COUNTER\_A} variable repeatedly incrementing from 1 to
10. Note that reaching 10 happens somewhere between 0.5 and 5.5
seconds after reaching 9.

%====================================================================
\subsection*{Exercises}

\noindent
Your goals in this part are:

\begin{packed_enumerate}[3]
\item Create a copy of the example mission file 
  in Listing \ref{lst_utscript_counter} above and save it locally.

\item Launch the mission. It should open a \app{uXMS} window. Follow
  the progress of the counter script.

\begin{consoleverb}
 $ pAntler utscript.moos
\end{consoleverb}

\item Take a look at the \app{uTimerScript} documentation linked from
  the web page. In particular, Section 3 Script Flow
  Control. Configure the script such that is paused when
  \app{uTimerScript} is launched. Launch the same mission and confirm
  that the script is initially not running. Then use \app{uPokeDB} to
  un-pause the script, and confirm it is running. Hint: to un-pause the 
  script with \app{uPokeDB}, you'll need to know which variable to poke, 
  and this also can be found in the \app{uTimerScript} documentation or
  by typing \cmd{uTimerScript -i} on the command line.

\item This is a bit of a \cmd{pAntler} exercise. Configure your mission to
  launch two versions of the script, the second version publishing
  to \msvar{COUNTER\_B}. Note you will need two configuration blocks,
  each with a unique name. And you will need to
  launch \app{uTimerScript} twice within the Antler block, each with
  an alias.  Hint: see the \app{pXRelay} example at the end of Lab 3.

\item Confirm your new mission launches and executes the two separate
  scripts and both counters are incrementing.

\item Configure the second script with a \pvar{condition} parameter.
  See Section 3.2 of the \app{uTimerScript} documentation. Use a
  condition such as \pvar{"condition = COUNTER\_A &gt; 5"}. Re-launch
  your mission. Confirm that the second script is paused periodically
  based on the state of the first script.

\item Add the \app{pLogger} application to your mission. You will need
  to add a \app{pLogger} entry to your ANTLER configuration block, and
  add the following \app{pLogger} configuration block at the end of
  your file.

\vspace{0.1in} 
\footnotesize
\begin{Verbatim}[frame=single]
ProcessConfig = pLogger 
{
  AsyncLog = true
  WildCardLogging = true
  WildCardOmitPattern = *_STATUS
}
\end{Verbatim}
\normalsize
\vspace{0.1in} 

\noindent
Re-run the mission. Confirm that you see the \app{pLogger} application
listed in the \mvar{DB\_CLIENTS} variable in the \app{uXMS} scope.

\item Verify that a log file has been created. Since we didn't specify
  a name for the log file, by default it should be in a subdirectory
  of where you launched the mission, looking something like
  \var{MOOSLog\_11\_21\_2024\_\_\_\_\_11\_31\_13/}. Enter the directory
  and confirm that you see an \var{.alog} file.

\item Take a look a the file by typing \var{more filename.alog}. Then
  take at look at the \mvar{COUNTER} variables using \app{aloggrep}
  (substituting of course the name of your \var{.alog} file:

\begin{consoleverb}
 $ aloggrep COUNTER_A COUNTER_B   MOOSLog_11_23_2016_____11_31_13.alog
\end{consoleverb}

\end{packed_enumerate}


\end{document}

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