<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%======================================================================
% Your First MOOS App - The pOdometry MOOS Application
%======================================================================
\newpage
%======================================================================
\section{Build Your First MOOS App - An Odometry MOOS App}
\label{sec_odometry}
%======================================================================

The focus of this section is on building your first MOOS App. Your goals are:

\begin{packed_enumerate}[3]
\item Learn how to generate a MOOS application from scratch using a
  template-generating script.
\item Learn how to add the new MOOS application to the build system.
\item Write your new MOOS app, \app{pOdometry}, to calculate the total
  distance traveled by the vehicle.
\item Test your MOOS app by using it in the Alder example mission to 
  have the vehicle return after traveling 50 meters.
\end{packed_enumerate}

%=====================================================================
\subsection{Part 1: Generating a Template App and Augmenting the Build System}

Your goal in this part is to generate a new application by using a
shell script to generate a full application template. The resulting
template should be buildable immediately without further modification,
but will essentially do nothing meaningful until you add your own
functionality.

%---------------------------------------------------------------------  
\subsubsection{Generate the MOOS App}

To generate the new MOOS app, in a terminal window change directories to
\var{moos-ivp-extend/src/}. From here you should be able to invoke the 
below command:

\begin{consoleverb}
 $ GenMOOSApp Odometry p "Jane Doe"
\end{consoleverb}

\noindent
The above script, \var{GenMOOSApp}, should be in your shell path under
\var{moos-ivp/scripts/}. If this is not in your shell path, add it. The
above script invocation builds a new app called \app{pOdometry}. The third
argument is your name. You can type \var{GenMOOSApp -h} in the future
to remind yourself.

%---------------------------------------------------------------------  
\subsubsection{Add Your New Application to the Build System}

Add your new app to the build system. Edit the file
\var{moos-ivp-extend/src/CMakeLists.txt} and look for the line
referring to \var{pXRelayTest}. Copy that as an example for your new
app. 

\prevblue
\begin{verbatim}
#============================================================================
# List the subdirectories to build...   
#============================================================================ 
ADD_SUBDIRECTORY(lib_behaviors-test)
ADD_SUBDIRECTORY(pXRelayTest)
ADD_SUBDIRECTORY(pExampleApp)
ADD_SUBDIRECTORY(pOdometry)                       &lt;-- Add this line
\end{verbatim}
\postverb

\noindent
Go back and re-run the build script. Check to see that \app{pOdometry}
has been built in the bin directory.

%---------------------------------------------------------------------  
\subsubsection{Add Your Name}


Always, always, always put your name at the top of your source code
files!  This is a good practice in general, but even more so in a
class setting, or an open source environment where people are sharing
code. It wouldn't hurt to add the date and organization information too.

%======================================================================
\subsection{Part 2: Writing the Odometry MOOS App}

The goal of this step is to build a new simple MOOS application that calculates
vehicle odometry. It will:

\begin{packed_enumerate}[3]
\item Register for the \mvar{NAV\_X} and \mvar{NAV\_Y} position of  the vehicle.
\item Repeatedly read in the \mvar{NAV\_X} and \mvar{NAV\_Y} position of
  the vehicle.
\item Update the total distance traveled by calculating the distance between 
the present position and the previous position.
\item Post the odometry information in the MOOS variable \mvar{ODOMETRY\_DIST}.
\end{packed_enumerate}

\pskip

\noindent
We will do this in your newly checked out moos-ivp-extend tree. Begin as follows:

\begin{packed_itemize}[3]

\item Edit \var{Odometry.h} to have six member variables:
 
\begin{verbatim}
bool   first_reading;
double current_x; 
double current_y; 
double previous_x; 
double previous_y; 
double total_distance;
\end{verbatim}

\item Edit \var{Odometry.cpp} initialize the above member variables.

\item Edit \var{Odometry.cpp} to register for \mvar{NAV\_X} and \mvar{NAV\_Y}.

\item Edit the \var{Odometry::OnNewMail()} method to handle the
  updated navigation position. Set \var{previous\_x} to
  \var{current\_x}, and \var{current\_x} to the new \mvar{NAV\_X}
  value. Same for Y.

\item Edit \var{Odometry::Iterate()} method to calculate the new
  distance. Handle the special case of the first navigation
  measurement. Post the total distance to the MOOS variable
  \mvar{ODOMETRY\_DIST}.

\item Verify that everything builds...
\end{packed_itemize}

%================================================================
\subsection{Part 3: Use Your pOdometry app in the Alder mission}

The first goal is to just make sure it runs and posts the correct
information.  The second goal is to use the i nformation to alter the
mission behavior.

\pskip

\noindent
Note: Just to be sure you have the latest class updates, do an svn update
in both the \var{moos-ivp} and \var{moos-ivp-extend} trees and re-build
before proceeding with this step.

%----------------------------------------------------------
\subsubsection{Running the Un-modified Alder Mission}

First make sure that you can run the Alder mission. Try it:

\begin{consoleverb}
 $ cd moos-ivp-extend/missions/alder
 $ pAntler --MOOSTimeWarp=10 alder.moos
\end{consoleverb}

\noindent
It should look something like the video posted at:

\vspace{0.15in}
\begin{figure}[H]
  \centering 
  \includegraphics[width=0.99\textwidth]{educlips/Alder.png}
  \caption{The Alder mission.}
  \label{fig_alder}
  \urlvideo{https://vimeo.com/80730664}{0:13}
\end{figure}


%----------------------------------------------------------
\subsubsection{Run the Alder Mission with pOdometry}

Next we'll add the \app{pOdometry} application to the mission and just
verify it is generating the right output.  Do the following steps:

\begin{packed_itemize}[3]
\item Modify the Alder mission
  (\var{moos-ivp-extend/missions/alder/alder.moos}) to include
  \app{pOdometry} at launch time by editing the \app{Antler} block in the
  alder.moos file.

\item Add \mvar{ODOMETRY\_DIST} to the scope list in
  \app{pMarineViewer}. See the \app{pMarineViewer} documentation to
  see how to do this. It should look something like:

\prevblue
\begin{verbatim}
ProcessConfig = pMarineViewer
{
  AppTick    = 4
  CommsTick  = 4

  ...
  scope = ODOMETRY_DIST    // &lt;-- Add this line
  ...
}
\end{verbatim}
\postverb

\item Re-launch the mission. Now you should be able to see the odometry
distance in the scope field at the bottom of \app{pMarineViewer}. Does
it look correct?

\end{packed_itemize}

\vspace{-0.3cm}
%----------------------------------------------------------
\subsubsection{Modify the Alder Mission Using pOdometry}

In the next step, we will modify the alder mission as follows. Instead
of transiting to the waypoint specified in the waypoint behavior, the
vehicle will return home after it has transited 50 meters. We haven't 
covered the Helm yet in class, so some of this we'll take on faith for 
now. 

\pskip
Take a look inside \var{alder.bhv}. This is where the helm is
configured.  The mission is comprised of two instances of a waypoint
behavior. The first transits to a given point and is called
\var{waypt\_to\_point}. It has two conditions, we'll add a third:

\prevbhv
\begin{verbatim}
condition = RETURN = false
condition = DEPLOY = true
condition = (ODOMETRY_DIST &lt; 50)
\end{verbatim}
\postverb

\noindent
The second waypoint behavior is designed to return after the first one
completes. It also has two conditions:

\prevbhv
\begin{verbatim}
condition = RETURN = true
condition = DEPLOY = true
\end{verbatim}
\postverb

\noindent
We'll change that to:

\prevbhv
\begin{verbatim}
condition = (RETURN = true) or (ODOMETRY_DIST &gt;= 50)
condition = DEPLOY = true
\end{verbatim}
\postverb


\noindent
After the above modifications, re-launch the mission. It should look something
like:

\vspace{0.15in}
\begin{figure}[H]
  \centering 
  \includegraphics[width=0.99\textwidth]{educlips/AlderWithOdometry.png}
  \caption{The Alder mission running with the pOdometry app.}
  \label{fig_alder_with_odo}
  \urlvideo{https://vimeo.com/80755512}{0:06} \\
  \urlvideo{http://18.38.2.158/2.680/clips/alder_using_odometry.mov}{0:09}
\end{figure}


\newpage

\begin{table}[H]
  \wikitablehint{style=graytop1}
  \centering
  \begin{tabular}{|c|c|c|p{0.6\textwidth}|} \hline 

  Goal &amp; Type &amp; Value &amp; Description \\ \hline \hline
  
  2.1  &amp; Self &amp;     &amp; Launch a new MOOSDB and confirm connection \\ \hline
  2.2  &amp; TA &amp;       &amp; Launch a new MOOSDB and confirm connection \\ \hline
  4.1  &amp; Grade &amp;    &amp; Launch a new MOOSDB and confirm connection \\ \hline
  4.2  &amp; Grade &amp;    &amp; Launch a new MOOSDB and confirm connection \\ \hline
  5.1  &amp; Self &amp;     &amp; Launch a new MOOSDB and confirm connection \\ \hline
  5.2  &amp; TA &amp;       &amp; Launch a new MOOSDB and confirm connection \\ \hline
  5.3  &amp; TA &amp;       &amp; Launch a new MOOSDB and confirm connection \\ \hline
 \end{tabular}
\end{table}





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