<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}

%===================================================================
% Include common packages, environments, counters etc
\input{common_latex/common_latex_packages}
\input{common_latex/common_latex_lab_format}
\input{common_latex/common_latex_definitions}
%===================================================================
\setcounter{tocdepth}{2}
%===================================================================

\begin{document}
\wikidoc{file=Lab.ClassRescue1}
\wikidoc{auth=mikerb@mit.edu}
\helplevelsubsec


%===================================================================
% Build the Cover Page in an environment style easy for wiki parsing
\begin{labcover}
\labtitle{Lab 13 - Autonomous Rescue Challenge - Part 1 }
\vspace{0.1in}
\labcourse{2.680 Unmanned Marine Vehicle Autonomy, Sensing and Communications}
\vspace{0.3in}
\labpng{0.85}{figures/rescue_field.png}
\vspace{0.3in}
\labdate{April 17th 2025}
\vspace{0.1in}
\labauth{Michael Benjamin, mikerb@mit.edu}
\labauth{Department of Mechanical Engineering}
\labauth{MIT, Cambridge MA 02139}
\vspace{0.2in}
\labtoc{footnotesize}
\labtocdepth{2}
\end{labcover}

%====================================================================
% Add a blank page so first body page is on the right when doubleside
\blankpage
%====================================================================
\newpage \section{Overview and Objectives}

The Autonomous Rescue Challenge is a multi-lab sequence culminating the
lab work of MIT 2.680 for the Spring 2024 semester. It introduces to
2.680 the first truly adversarial head-to-head mission where teams
will be fielding their robots on the same playing field in a zero-sum
competition. There will be several variants to the competition as we
progress through the multi-week lab sequence. In it's simplest form,
the problem is similar to the Traveling Salesman Problem (TSP) from
Labs 7 and 8. A given set of "swimmers" and their locations are
provided to an autonomous vehicle. The mission is to visit and rescue
each swimmer: 

\vspace{0.1in}
\begin{figure}[H]
  \centering
  \includegraphics[width=0.55\textwidth]{figures/prob_overview.png}
  \caption{{\bf The Problem Overview:} A robot is provided a list of
    swimmers and their locations, and is tasked with visiting and rescuing
    all of them as quickly as possible.}
\label{fig_prob_overview}
\end{figure}
\vspace{0.1in}

\noindent
In adversarial variants of this lab, two teams will each launch a
rescue vehicle and will compete to rescue the most swimmers. The team
with the most swimmers, after all have been rescued, or after a fixed
amount of time, will be the winner. This can be compared to an Easter
egg hunt. 

\vspace{0.1in}
\begin{figure}[H]
  \centering
  \includegraphics[width=0.65\textwidth]{figures/head_to_head.png}
  \caption{{\bf Adversarial Rescue:} Two robots are each provided
    information about a set of swimmers and their locations. Each
    proceeds by trying to rescue as many as possible. They operate in
    an adversarial manner, each trying to rescue as many as
    possible. Once a swimmer has been rescued by one vehicle, it
    cannot be rescued by the other.  The winning vehicle is the one
    who rescues the most swimmers.}
\label{fig_head_to_head}
\end{figure}
\vspace{0.1in}

\vspace{0.1in}
\noindent
In the first part of this lab sequence, Lab 13 will focus on the above
two variants, first in simulation and then on the water with
Herons. In the last part of this sequence, Lab 17, each team will
deploy a second collaborative vehicle acting as a sensor vehicle. The
exact locations of a some of the swimmers in this case will not be
known to the rescue vehicle at the outset, but will instead be
discovered by the sensor vehicle.

\vspace{0.1in}
\begin{figure}[H]
  \centering
  \includegraphics[width=0.85\textwidth]{figures/rescue_field.png}
  \caption{{\bf Field Competitions:} The in-water portion of the lab
    will be at the MIT Sailing Pavilion, where the playing field is
    aligned with the docks as shown. The rescue vehicles will be the
    Clearpath M300 Heron unmanned surface vehicles (USVs). }
\label{fig_rescue_field}
\end{figure}
\vspace{0.1in}

\noindent
A summary of topics:

\begin{labinfo}
\begin{packed_itemize}[2]
\item Path planning revisited
\item Path re-planning in the face of new information
\item Path re-planning that considers adversarial intent
\item Collision avoidance
\end{packed_itemize}
\end{labinfo}

%===================================================================
\section{Preliminaries}
%===================================================================
\label{sec_prelims}

\input{common_rescue/doc_conventions}
\input{common_rescue/update_code}
\input{common_rescue/pav_coords}
\input{common_rescue/shell_path}

%=======================================================================
\subsection{The uFldRescueMgr MOOS App for the Rescue Lab}

The core staff-provided app for the rescue lab is the the
\app{uFldResueMgr} app. It is found in the \var{moos-ivp-2680} tree.
You can think of this as being similar to the \app{pPointAssign} app
from Lab 7, since it will be informing vehicles about visit points, or
in this case, {\em swimmers}. But unlike \app{pPointAssign}, (a) it
will not necessary announce all swimmers at the outset, and (b) it
will keep track of which swimmers have been visited, and by whom. It
will serve as the competition mediator and judge for these labs.  As
the layout in Figure \ref{fig_rescue_topology} shows,
\app{uFldRescueMgr} runs on the shoreside, and the \app{pGenRescue}
app runs on the vehicle. The latter app is comparable to the
\app{pGenPath} app from lab 7.

\vspace{0.1in}
\begin{figure}[H]
  \centering
  \includegraphics[width=0.65\textwidth]{figures/rescue_topology.png}
  \caption{{\bf Software Topology:} The \aapp{uFldRescueMgr} app will
    run on the shoreside and is distributed as part of this lab. The
    \aapp{pGenRescue} app is provided by the student to handle path
    planning on on the vehicle.}
\label{fig_rescue_topology}
\end{figure}
\vspace{0.1in}

\noindent
The interface and capability for this app will be described in later
sections, but salient points for this lab can be summarized:

\begin{packed_itemize}
\item The \app{uFldRescueMgr} will ingest a {\em swim file}, with
  pre-calculated locations of swimmers.
\item The \app{uFldRescueMgr} will broadcast locations of swimmers to
  the vehicles with a \mvar{SWIMMER\_ALERT} message including a unique
  ID per swimmer and its location.
\item Vehicles will send a \mvar{RESCUE\_REQUEST} message to
  \app{uFldRescueMgr} to attempt a swimmer rescue. The rescue manager will
  either grant or deny the request based on the vehicle proximity to the
  swimmer and whether or not the swimmer has been rescued already by
  another vehicle.
\end{packed_itemize}


%==========================================================================
%\subsection*{More Resources}

%\begin{itemize}

%\item The slides from lecture "Writing Behaviors": \newline 
%  \urlx{http://oceanai.mit.edu/2.680/docs/2.680-12-writing_behaviors_2022.pdf}

%\item The IvP Behavior Utility Functions \newline
%  \urlx{http://oceanai.mit.edu/ivpman/help/bhv_functions}

%\item The IvPBuild Toolbox ZAIC documentation \newline
%  \urlx{http://oceanai.mit.edu/ivpman/chap/ivpbuild_zaics}

%\end{itemize}

%======================================================================
\newpage
\section{Running the Autonomous Rescue Mission in Simulation}
%======================================================================
\label{sec_new_bhv}

The goals of this section are:

\begin{packed_itemize}
  \item Run the autonomous rescue baseline mission
  \item Modify your Lab 7 \app{pGenPath} app to work in this mission 
  \item Run the rescue baseline mission in simulation with your app
\end{packed_itemize}

%======================================================================
\subsection{The Autonomous Rescue Baseline Mission}
\label{sec_baseline}

The baseline mission resides in the \var{moos-ivp-2680} tree. This
tree, per the steps described in Section \ref{sec_get_code}, should
now be downloaded onto your laptop. The baseline mission is located
here:

\vspace{0.1in}
\begin{consoleverb}
$ cd moos-ivp-2680/missions/rescue_basline
$ ls
clean.sh*            meta_shoreside.moos  mit_01.txt
launch.sh*           meta_vehicle.bhv     mit_02.txt
launch_shoreside.sh* meta_vehicle.moos    mit_03.txt
launch_vehicle.sh*   mit_00.txt           plugs.moos
\end{consoleverb}
\vspace{0.1in}

\paragraph{IMPORTANT NOTE:}
Unlike other labs where the baseline mission was to be copied into
your \var{moos-ivp-extend} tree, we will all work from the
\var{rescue\_baseline} mission folder in \var{moos-ivp-2680/missions}.
This allows the staff to modify the baseline mission if needed, with
only a version control update needed on the user's end. The mission
is carefully constructed such that student contributions are primarily
limited to student versions of the rescue MOOS app, and scout IvP behavior.

\noindent
This mission, like some other of our baseline missions involving
multi-machine or in-water experiments, is structured to be launched in
one of three ways:

\begin{packed_itemize}
\item \var{launch.sh}: Full simulation, launching shoreside and vehicle.
\item \var{launch\_vehicle.sh}: Launching on vehicle only (sim or on the water).
\item \var{launch\_shoreside.sh}: Launching the shoreside only.
\end{packed_itemize}

\vspace{0.1in}
\noindent
Like virtually all other launch scripts, these script supports the
\var{--help, or -h} and \var{--just\_make, or -j} options. The latter is
useful for using the launch script to build the \var{targ\_*} files without
launching the mission. This can help in debugging sometimes.

\vspace{0.1in}
\noindent
In this first lab (13), you will launch a full simulation on your
laptop, acting as shoreside and vehicle. In the next lab (14), we will
move to the river, and you will launch just the vehicle portion of the
mission on your Heron, and {\em the staff or lab partner will launch
  the shoreside independently}.

%======================================================================
\subsection{The Swimmer File}
\label{sec_swim_file}

The rescue manager app, \app{uFldRescueMgr}, is initialized with a file
containing the list of swimmers and locations. The example used in the
baseline mission is in the file \var{mit\_01.txt}, and shown below. 

\vspace{0.1in}
\begin{fileverb}
// gen_swimmers --swimmers=5 --pav90 --sep=5
poly = pts={60,10:-75.5402,-54.2561:-36.9866,-135.58:98.5536,-71.3241}
swimmer = name=p01, x=64.7, y=-39.7
swimmer = name=p02, x=4.7, y=-99.4
swimmer = name=p03, x=27.3, y=-58.6
swimmer = name=p04, x=50.1, y=-91
swimmer = name=p05, x=41.2, y=-24
\end{fileverb}
\vspace{0.1in}

\noindent
This file is generated with another utility, \cmd{gen\_swimmers}, which
is a separate command-line utility in the \var{moos-ivp-2680} tree. The
command to create the above file was:

\vspace{0.1in}
\begin{consoleverb}
$ gen_swimmers --swimmers=5 --pav90 --sep=5
\end{consoleverb}
\vspace{0.1in}

\noindent
The resulting locations listed above are also rendered in Figure
\ref{fig_baseline_00}. The baseline mission contains the two
swimmer files, \var{mit\_00.txt} and \var{mit\_01.txt}. When the
baseline mission is run with the first file, it will proceed nicely,
visiting each swimmer. The baseline mission is configured to run a
waypoint behavior with hard-coded waypoints matching the swimmer
locations in \var{mit\_00.txt}. When the mission is run with the
second swimmer file, the vehicle will perform poorly since the
waypoints were configured to match the first file. To make your
vehicle work generally, you will need to abandon the hard-coded
waypoint approach and instead utilize a version of your \app{pGenPath}
app, as discussed below.

%======================================================================
\subsection{Assignment 1: (self check off) - Running the Baseline Mission}
\label{sec_runbase}

The baseline mission folder has at least two swim files,
\var{mit\_00.txt}, and \var{mit\_01.txt}. Launch the first mission
with:

\vspace{0.1in}
\begin{consoleverb}
  $ cd moos-ivp-2680/missions/rescue_baseline
  $ ./launch.sh 10                            (--swim_file=mit_00.txt is default)
\end{consoleverb}
\vspace{0.1in}

\noindent
It should look similar to the example image, or video, in Figure
\ref{fig_baseline_00} below. The vehicle visits each of the five
swimmers directly and efficiently. While you are watching this run,
you may want to select the appcasting output for \app{uFldRescueMgr}. This
app will be discussed in more detail later, but most of the output
may be discernible just by looking at it while it runs.

\vspace{0.1in}
\begin{figure}[H]
  \centering 
  \includegraphics[width=0.85\textwidth]{figures/baseline_00.png}
  \caption{In the first baseline mission, the vehicle will proceed to
    visit all five swimmer locations, before returning home. The circle moving
    with the vehicle represents the sensor range for performing rescues.}
  \label{fig_baseline_00}
  \gif{figures/baseline_00.gif}
\end{figure}
\vspace{0.1in}

\noindent
There is {\em not} a lot of intelligence in this baseline mission. If
you look under the hood, in the \var{meta\_vehicle.bhv} file, you will
notice the initial deployment results in a waypoint behavior that
traverses the waypoints that conveniently overlay very closely the
location of each swimmer. The order is even more-or-less optimal. This
same mission applied to a different swim file will fail badly. Launch
the same mission using another swim file named \var{mit\_01.txt}:

\vspace{0.1in}
\begin{consoleverb}
  $ cd moos-ivp-2680/missions/rescue_baseline
  $ ./launch.sh --swim_file=mit_01.txt 10        (time warp 10)
\end{consoleverb}
\vspace{0.1in}

\begin{figure}[H]
  \centering 
  \includegraphics[width=0.85\textwidth]{figures/baseline_01.png}
  \caption{In the second baseline mission, the vehicle will proceed to
    to visit all the hard-coded points as in the first baseline mission. In
    this case the points do not match up with swimmer locations and none
    of the swimmers are rescued.}
  \label{fig_baseline_01}
  \gif{figures/baseline_01.gif}
\end{figure}

\noindent
In a nutshell, your strategy will be to add an app, like your
\app{pGenPath} app from Lab 7, to this mission. It will register for
information comparable to the \var{VISIT\_POINT} messages from Lab
7. In this case the information will come from the shoreside
\app{uFldRescueMgr} app, with format described in Section
\ref{sec_swimalert}. As in Lab 7, your app will then post updates to
the waypoint behavior. In this first lab, it will not get much more
complicated than this, but as we progress the strategy will become
more involved.

%Things to notice or try:

%drop a new swimmer
%change the Pd

%======================================================================
\section{Building a Path Planning App for Rescue Traversals}
%======================================================================
\label{sec_pgenrescue}

In this lab, a key app will be the one that generates a waypoint path
to visit and "rescue" each swimmer. As with Lab 7, this app will
receive coordinates from the shoreside, formulate a strategic decision
in the form of a waypoint path, and then pass that path to the helm in
the form of an update to the waypoint behavior. At first, in this lab,
our primary focus is to get this new app running and ingesting the
slightly different format of incoming information from the shoreside.

%======================================================================
\subsection{Assignment 2 (self check off) Creating a New Path Planning App}

The path planning app in this lab should be called \app{pGenRescue}.

\vspace{0.1in}
\noindent
The \app{pGenPath} app from Lab 7 is a good place to start.  You have
two options. (a) You could modify that app to suit the needs for this
lab, and superficially rename the app, or (b) you can make a {\em
  copy} of that app to suit the needs of this lab. My recommendation
is the latter. Even though your code is under version control and you
can revert changes, a good rule of thumb is to leave a perfectly
working app alone, in case you want to come back to it later. We suggest
that you make a copy of \app{pGenPath}, calling it \app{pGenRescue}:

\vspace{0.1in}
\begin{consoleverb}
  $ cd moos-ivp-extend/src
  $ cp -rp pGenPath pGenRescue  
\end{consoleverb}
\vspace{0.1in}

\noindent
Once this folder is copied, you will need to do the following

\begin{packed_itemize}
\item Edit the \var{CMakeLists.txt} file in \app{pGenRescue}
\item Rename files like \var{GenPath.cpp} to \var{GenRescue.cpp} etc., and edit
  the file contents, including \var{main.cpp}
\item Add \app{pGenRescue} to the \var{CMakeLists.txt} file in the
  \var{moos-ivp-extend/src} directory.
\end{packed_itemize}

\vspace{0.1in}
\noindent
The goal of this assignment is to simply get your new app to build,
creating the binary in your \var{moos-ivp-extend/bin} folder alongside
your previous apps. (so, no change required for your shell path.)


%======================================================================
\subsection{Swimmer Alert Messages from the Shoreside}
\label{sec_swimalert}

The shoreside app \app{uFldRescueMgr} will convey the swimmer
coordinates to vehicles in the form of the MOOS variable
\mvar{SWIMMER\_ALERT}. Here are two examples:

\vspace{0.1in}
\begin{fileverb}
SWIMMER_ALERT = x=23, y=54, id=04
SWIMMER_ALERT = x=-4, y=95, id=09
\end{fileverb}
\vspace{0.1in}

\noindent
This message can be thought of as a "man overboard!" alert sent to all
vehicles. Unlike Lab 7, with \app{pPointAssign}, there will be no
bookend messages indicating that the first or last swimmer info has been
sent. Two things to keep in mind:

\begin{packed_itemize}
\item A swimmer alert may come at any point in the mission, ranging
  from right up front, until very late in the mission. In this first
  lab, they will be all given right up front at the outset.
\item The swimmer alerts, will be repeated every 15 seconds from the
  shoreside.  This makes handshaking a bit easier, i.e., we don't have
  to worry about which app has started first and so on. But you do
  need to make sure that when successive swimmer alerts are received,
  that you note the swimmer ID and just ignore swimmers that you know
  about already.
\item The location of swimmers will not change over time.
\item Even after a swimmer has been rescued, you may still get an
  alert about it.
\end{packed_itemize}

\vspace{0.1in}
\noindent
Since there are no guarantees about when or if further
\mvar{SWIMMER\_ALERT} messages will arrive, when should you generate a
path an update your behavior? Ultimately this is a decision up to you
and you may want to apply your own strategy, but for now, in this lab,
you should re-generate a path and update the behavior {\em each time a
  new swimmer alert is received}.


%======================================================================
\subsection{Found Swimmer Messages from the Shoreside}

The shoreside app \app{uFldRescueMgr} will also convey the swimmer
status to vehicles in the form of the MOOS variable
\mvar{FOUND\_SWIMMER}.  Here are two examples:

\vspace{0.1in}
\begin{fileverb}
FOUND_SWIMMER = id=01, finder=abe
FOUND_SWIMMER = id=07, finder=ben
\end{fileverb}
\vspace{0.1in}

\noindent
Note that one vehicle may receive \mvar{FOUND\_SWIMMER} messages
indicating a swimmer has been rescued by another vehicle. In this lab,
only one vehicle will be deployed, but in subsequent labs, multiple
vehicles will be deployed at the same time. Your goal in those later
labs will be to use information about swimmers that have been rescued
by others. Presumably your \app{pGenRescue} app would recalculate a
path that removes visits to swimmers that have already been rescued.

%======================================================================
\subsection{Assignment 3 (check off) - Demonstrate Dynamic Path Planning}

The goal of this lab is to run the baseline mission with your
\app{pGenRescue} app accepting \mvar{SWIMMER\_ALERT} messages from the
shoreside. The goal is to launch the baseline mission as described
in Section \ref{sec_runbase}, using the \var{mit\_01.txt} swim file:

\vspace{0.1in}
\begin{consoleverb}
  $ cd moos-ivp-2680/missions/rescue_baseline
  $ ./launch.sh --swim_file=mit_01.txt 10
\end{consoleverb}
\vspace{0.1in}

\noindent
Recall that in the baseline mission, the waypoints are hard coded, and
the vehicle performs poorly for this swimmer file, as in Figure
\ref{fig_baseline_01}. Your goal is to apply your \app{pGenRescue}
app to perform nicely with this set of coordinates, similar to how the
vehicle efficiently visited swimmers in Figure
\ref{fig_baseline_00}.

\vspace{0.1in}
\noindent
{\bf Note 1:} In the \var{rescue\_baseline} mission, the
\app{pGenRescue} app, by default, is not launched on the vehicle. In
this configuration, the simple hard-coded waypoints will be traversed
as in Figures \ref{fig_baseline_00} and \ref{fig_baseline_01}. Once a
\app{pGenRescue} has been built and in the shell path, it can be
included in the vehicle mission and it will overwrite the hard-coded
waypoints. To invoke the mission using \app{pGenRescue}, simply launch
with the \var{--rescue} or \var{-r} flag:

\vspace{0.1in}
\begin{consoleverb}
  $ cd moos-ivp-2680/missions/rescue_baseline
  $ ./launch.sh --swim_file=mit_01.txt -r 10       (Notice the -r arg)
\end{consoleverb}
\vspace{0.1in}

\noindent
{\bf Note 2:} Recall that you can check to see if your
\app{pGenRescue} has been built and will be found when launched, by
running \cmd{which pGenRescue}.

\vspace{0.1in}
\noindent
{\bf Note 3:} The config block for \app{pGenRescue} in the baseline
mission, in \var{meta\_vehicle.moos} does exist, but has no
configuration parameters.  (My version for testing has no config
params.) If your version of \app{pGenRescue} has configuration
parameters, you will need to add them also to the
\var{meta\_vehicle.moos} file.

%=======================================================================
\newpage \section{Instructions for Handing In Assignments}
%=======================================================================

%=======================================================================
\subsection{Requested File Structure}
\label{sec_hand_in}

The assignment for this lab is to demonstrate a working simulation
of the rescue mission using your newly created \app{pGenRescue} app.

\vspace{0.1in}
\begin{consoleverb}
  moos-ivp-extend/
    src/
       pGenRescue         (created by you)
\end{consoleverb}
\vspace{0.1in}


%=======================================================================
\subsection{Due Date}

This lab should be completed by the end of lab next Tuesday. (April
22nd, 2025).

\end{document}

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