<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%=====================================================================
\section{The AvoidCollision Behavior}
%=====================================================================
%\wikisec{grp=bhvmulti}
%\wikisec{file=BehaviorAvdCollision, short=AvoidCollision Behavior}
\label{bhv_avoidcollision}
%\index{IvP Behaviors Implemented!\var{BHV\_AvoidCollision}}
%\index{AvoidCollision Behavior}

The AvoidCollision behavior will produce IvP objective functions
designed to avoid collisions (and near collisions) with another
specified vehicle. The IvP functions produced by this behavior are
defined over the domain of posssible heading and speed choices. The
utility assigned to a point in this domain (a heading-speed pair)
depends in part on the calculated closest point of approach (CPA)
between the candidate maneuver leg, and the contact leg formed from
the contact's position and trajectory. A further user-defined utility
function is applied to the CPA calculation for a candidate maneuver.

%=====================================================================
\subsection{Configuration Parameters}
\label{sec_collavd_params}

\input{includes/bhv_all_properties}

\input{includes/bhv_contact_properties}

\vspace{0.15in}
\begin{listing}{Configuration Parameters for the AvoidCollision Behavior}
\label{lst_bhv_avd_collision}
\small
\renewcommand{\arraystretch}{1.15}
\begin{longtable}{rp{0.76\textwidth}} 

  {\bf Parameter} &amp; {\bf Description} \\  
  
  \bvar{completed\_dist}: &amp; Range to contact outside of which the 
  behavior completes and dies. The default is 500 meters. \\  
  
  \bvar{max\_util\_cpa\_dist}: &amp; Range to contact outside which a
  considered maneuver will have max utility. Section
  \ref{sec_bhv_avdcol_cpa_params}. The default is 75 meters\\

  \bvar{min\_util\_cpa\_dist}: &amp; Range to contact within which a
  considered maneuver will have min utility. Section
  \ref{sec_bhv_avdcol_cpa_params}. The default is 10 meters. \\

  \bvar{no\_alert\_request}: &amp; If true, the behavior will not send an
  automatic configuration message to the contact manager at startup.
  Section \ref{sec_bhv_avdcol_alerts}. The default is false. \\

  \bvar{pwt\_grade}: &amp; Grade of priority growth as the contact moves
  from the \bvar{pwt\_outer\_dist} to the
  \bvar{pwt\_inner\_dist}. Choices are \var{linear}, \var{quadratic},
  or \var{quasi}. The default is \var{quasi}. Section
  \ref{sec_bhv_avdcol_pwt_params}. \\

  \bvar{pwt\_inner\_dist}: &amp; Range to contact within which the
  behavior has maximum priority weight. Section
  \ref{sec_bhv_avdcol_pwt_params}. The default is 50 meters. \\

  \bvar{pwt\_outer\_dist}: &amp; Range to contact outside which the
  behavior has zero priority weight. Section
  \ref{sec_bhv_avdcol_pwt_params}. The default is 200 meters. \\

  \bvar{use\_refinery}: &amp; If true, the behavior will produce an
  optimized objective function that is faster to produce, uses
  a smaller memory footprint, and contributes to faster helm solution
  time. The default is false, simply for continuity with prior
  releases, but there is no downside to enabling this feature. Section
  \ref{sec_bhv_avdcol_refinery}. \\

\end{longtable}
\end{listing}
\normalsize


\vspace{0.15in}
\begin{listing}{Example Configuration Block}
\label{lst_bhv_avd_collision_ex}

\begin{fileverb}
Behavior = BHV_AvoidCollision
{
  // General Behavior Parameters
  // ---------------------------
  name         = avdcollision_                     // example
  pwt          = 200                               // example
  condition    = AVOID = true                      // example
  updates      = CONTACT_INFO                      // example
  endflag      = CONTACT_RESOLVED = $[CONTACT]     // example
  templating   = spawn                             // example


  // General Contact Behavior Parameters
  // -----------------------------------
      bearing_lines = white:0, green:0.65, yellow:0.8, red:1.0   // example

            contact = henry            // example
              decay = 15,30            // default (seconds)
        extrapolate = true             // default
   on_no_contact_ok = true             // default
        time_on_leg = 60               // default (seconds)


  // Parameters specific to this behavior
  // ------------------------------------
     completed_dist = 500              // default
  max_util_cpa_dist = 75               // default
  min_util_cpa_dist = 10               // default
   no_alert_request = false            // default
          pwt_grade = quasi            // default
     pwt_inner_dist = 50               // default
     pwt_outer_dist = 200              // default
}
\end{fileverb}
\end{listing}

%----------------------------------------------------------------------
\subsection{Variables Published}

The below MOOS variables will be published by the behavior during
normal operation, in addition to any configured flags. A variable
published by any behavior may be supressed or changed to a different
variable name using the \bvar{post\_mapping} configuration parameter
described in Section \ref{sec_bhv_post_mapping}.

\begin{packed_itemize}[2]

\item \mvar{BCM\_ALERT\_REQUEST}: A request to the contact manager
  specifying the conditions for contact alerts.
    
\item \mvar{CLOSING\_SPD\_AVD}: The current closing speed, in meters
  per second, to the contact.
    
\item \mvar{CONTACT\_RESOLVED}: Posted with contact name when the
  behavior completes and dies.

\item \mvar{RANGE\_AVD}: The current range, in meters, to the contact.

\item \mvar{VIEW\_SEGLIST}: A bearing line between ownship and the
  contact if configured for rendering.
\end{packed_itemize}

%=======================================================================
\subsection{Configuring and Using the AvoidCollision Behavior}

The AvoidCollision behavior produces an objective function based on
the relative positions and trajectories between the vehicle and a
given contact. The objective function is based on applying a utility 
to the calculated closest point of approach (CPA) for a candidate
maneuver. The user may configure a priority weight, but this weight
is typically degraded as a function of the range to the contact. The
behavior may be configured for avoidance with respect to a known 
contact, or it may be configured to spawn a new instance upon demand
as contacts present themselves.

%=======================================================================
\subsection{Automatic Requests for Contact Manager Alerts}
\label{sec_bhv_avdcol_alerts}

The collision avoidance behavior is most commonly configured as a {\em
  template}, meaning instances will not be spawned until an outside
event, i.e, posting to the MOOSDB, is received by the helm.
  This was discussed in detail in Section
\ref{sec_bhv_templates}.  The spawning event for the collision
avoidance behavior typically comes from the \app{pBasicContactMgr}
application. This app therefore needs to be informed, by the collision
avoidance behavior, of the desired conditions for generating
behavior-spawning alerts. This is done automatically upon helm startup
with a posting of the form:

\vspace{0.1in}
\begin{fileverb}
  BCM_ALERT_REQUEST = id=avd, onflag=CONTACT_INFO=name=$[VNAME] # contact=$[VNAME],
                      alert_range=80, cpa_range=100
\end{fileverb}
\vspace{0.1in}

\noindent
The values for this posting are chosen as follows:

\begin{packed_itemize}[2]
\item The value from the \var{onflag} component is a posting to be
  made by the contact manager when an alert is triggered. Like all
  MOOS postings, the posting has a variable and value component. The
  variable component is \var{CONTACT\_INFO}. The value component is

\begin{verbatim}
  name=$[VNAME] # contact=$[VNAME]
\end{verbatim}

\item When the contact manager posts the onflag, it will expand the
  \var{\$[VNAME]} macros with the actual name of the contact. The
  variable \var{CONTACT\_INFO} is the variable provided in the
  \bvar{updates} parameter for the behavior.

\item The value from the \var{alert\_range} component, e.g., 80 in the
  example above, is the value specified in the \bvar{pwt\_outer\_dist}
  parameter for the behavior. This is the range between ownship and contact
  beyond which the behavior assigns a priority weight of zero.

\item The value from the \var{cpa\_range} component, e.g., 100 in the
  example above, is the value specified in the \bvar{completed\_dist}
  parameter for the behavior. This is the range, in meters, between
  ownship and contact beyond which the behavior will initiate its own
  completion and de-instatiation.
\end{packed_itemize}

\noindent
If some other contact manager regime is being used other than
\app{pBasicContactMgr}, the above automatic posting is probably
harmless. However, if one really wants to disable this automatic
posting, it can be turned off by setting the configuration parameter
\bvar{no\_alert\_request} to true.

\pskip

Implementation note: One may wonder when or how the behavior can make
this automatic posting when the behavior is configured as a template.
An instance is never spawned until an alert is received, but the alert
parameters are posted by the behavior, creating a bit of a chicken or
the egg conundrum. The alert request is actually posted by an instance
of the behavior created ever so briefly at helm startup. At startup,
the helm creates instances of {\em all} behaviors, even templates, to
ensure the configuration parameters are correct. The ultimate
confirmation of behavior parameter correctness is obtained by a
behavior instance itself confirming each parameter. The helm will then
immediately, before its first iteration, delete any behaviors
temporarily created from template behaviors. During this brief startup
period, the helm will invoke the function \func{onHelmStart()} for all
behaviors. This function is defined at the IvPBehavior superclass
level just like \func{onRunState()}. In the case of the collision
avoidance behavior, this function is implemented to make the automatic
alert configuration posting to \mvar{BCM\_ALERT\_REQUEST}.


%=======================================================================
\subsection{Specifying the Behavior Priority Weight Policy}
\label{sec_bhv_avdcol_pwt_params}

The AvoidCollision behavior may be configured to increase its priority
as it closes range to the contact. The priority weight specified
in its configuration represents the {\em maximum} possible priority
applied to the behavior, presumably in close range to the contact. The
range at which this maximum priority applies is specified in the
\bvar{pwt\_inner\_dist} parameter. Likewise, the
\bvar{pwt\_outer\_dist} parameter specifies a range to the contact
where the priority weight becomes zero, regardless of the priority
weight specified in the configuration file.

\vspace{0.1in}
\noindent
So the {\em current priority} will always be between zero and the maximum
priority set in the behavior \bvar{priority} configuration parmeter. To be
more precise:

\vspace{0.1in}
\noindent
Current Priority =

\begin{packed_itemize}
\item 0 if current range to contct is greater than or equal to \bvar{pwt\_outer\_dist}
\item 100 if current range to contact is less than or equal to \bvar{pwt\_inner\_dist}
\item otherwise ((\bvar{pwt\_outer\_dist} - current range) /
  (\bvar{pwt\_outer\_dist} - \bvar{pwt\_inner\_dist})) * priority
\end{packed_itemize}

\vspace{0.1in}
\noindent
This relationship is shown in Figure \ref{fig_avdcol_pwt}.

\vspace{0.15in}
\begin{figure}[H]
  \centering 
  \includegraphics[width=0.91\textwidth]{figures/bhv_pwt_growth.png}
  \caption{{\bf Scaling priority weights based on ownship range to
      contact}: The range between the two vehicles affects whether the
    behavior is spawned, active and with what priority weight.  Beyond
    the range specified by \bvar{completed\_dist} the behavior is
    likely not inexistence.  Beyond the range specified by
    \bvar{pwt\_outer\_dist}, the behavior is not yet active. Within
    the range of \bvar{pwt\_outer\_dist}, the behavior becomes active
    with a non-zero priority weight growing as the contact closes
    range.  Within the range of \bvar{pwt\_inner\_dist}, the behavior
    is active with 100\% of its configured priority weight.}
  \label{fig_avdcol_pwt}
\end{figure}
\vspace{0.15in}

\noindent
The example shown below in Figure \ref{fig_avdcol_pwt_effect} shows
the effect of the \bvar{pwt\_outer\_dist} parameter. The vehicle on
the left is proceeding east, oblivious to the two approaching
vessels. The two westbound vessels, \var{ben} and \var{cal} are
simulated exactly on top of one another. They are oblivious to one
another, but will use the collision avoidance behavior to avoid the
eastbound vessel, abe. The only difference between \var{ben} and
\var{cal} is that \var{cal} begins winding up its priority weight at
80 meters range to \var{abe}, as opposed to 30 meters for
\var{ben}. The short simulation shows the resulting difference in
trajectory.


\vspace{0.1in}
\begin{figure}[H]
  \centering 
  \includegraphics[width=0.99\textwidth]{figures/bhv_avdcol_pwt_effect.png}
  \caption{Two vehicles use the AvoidCollision behavior to avoid the oblivious and
    non-maneuvering Eastbound vehicle. One vehicle has \bvar{pwt\_outer\_dist}
    set to 80 and the other set to 30. This affects when each vehicle begins
    its maneuver to avoid.}
  \label{fig_avdcol_pwt_effect}
  \urlvideo{https://vimeo.com/457500757}{0:12}
\end{figure}
\vspace{0.1in}

By default, the priority weight decreases linearly between the two
depicted ranges. The \bvar{pwt\_grade} parameter allows the
degradation from maximum priority to zero priority to fall more
steeply by setting \bvar{pwt\_grade}\bsvar{=quadratric}.

%\small
%\begin{align*}
%  pwt(r) &amp;= \begin{cases}
%    0        &amp; r \geq r^+,  \\
%    P_{max}   &amp; r \leq r^-,  \\
%    P_{max} (\frac{3}{4}) &amp; otherwise 
%  \end{cases} \\
%\end{align*}
%\normalsize

%=======================================================================
\subsection{Specifying the Utility Policy of the Behavior}
\label{sec_bhv_avdcol_cpa_params}

Whereas the behavior {\em weight} discussed above in Section
\ref{sec_bhv_avdcol_pwt_params} determines the influence of the
behavior relative to other behaviors, the behavior {\em utility
  function} specifies the relative utility of candidate maneuvers from
the perspective of the collision avoidance goals of this behavior.

\vspace{0.1in}
\noindent
The utility function for the avoid collision behavior is based on two
factors:

\begin{packed_itemize}
\item The range at the closest point of approach (CPA) for a candidate maneuver
\item The determination risk associated with any CPA range.
\end{packed_itemize}

\vspace{0.1in}
\noindent
The first component is just physics. Given ownship and contact current
positions and trajectories, and the assumption that the contact will
stay on its current heading and speed for at least the near future,
the projected CPA range may be calculated for any given heading-speed
maneuver. Consider the example in Figure \ref{fig_avdcol_crossing}
below with particular ownship and contact positions and trajectories
shown on the left. On the right, the projected CPA range values are
plotted for all candidate ownship maneuvers. 

\vspace{0.1in}
\begin{figure}[H]
  \centering 
  \includegraphics[width=0.8\textwidth]{figures/bhv_avdcol_crossing.png}
  \caption{(left) An example collision avoidance situation, where
    ownship would cross behind the contact if it remained on its
    present heading and speed. (right) The evaluation of closest point
    of approach for all possible maneuvers with ownship max speed of 4
    m/s. The darkest blue maneuvers will result in a collision or near
    collision.}
  \label{fig_avdcol_crossing}
\end{figure}
\vspace{0.1in}

\noindent
The second component of the utility function is the mapping of "risk"
to certain CPA range values. This part is very subjective, and of
course is why there are configuration parameters, allow different
users to align the behavior with their own notion of risk. The two key
parameters are \bvar{min\_util\_cpa\_dist} and
\bvar{max\_util\_cpa\_dist}. The former refers the the CPA range with
the minimum utility, essentially equivalent to a collision. For this
value, perhaps pick a range that, while not a collision, someone would
get written up for a safety violation for breaching this range. The
\bvar{max\_util\_cpa} range, on the other hand, is the range that,
above which there is not increase in utility. Everything at this range
or higher is "all clear".

\vspace{0.1in}
\noindent
These two parameters form a function, $g()$, which takes as input the
CPA range value and outputs the utility of a canditate maneuver. This
function is depicted on the left in Figure \ref{fig_avdcol_util}, and
the overall utility function is shown on the right:

\vspace{0.1in}
\begin{figure}[H]
  \centering 
  \includegraphics[width=0.8\textwidth]{figures/bhv_avdcol_util.png}
  \caption{(left) A utility function mapping CPA range values to a
    single risk utility is shown. Up to the range specified by the
    \bvar{min\_util\_cpa} configuration parameter, maneuvers resulting
    in these ranges are considered essentially collisions.  Above the
    range specified by the \bvar{max\_util\_cpa} configuration
    parameter, maneuvers resulting in these ranges are considered
    essentially equivalently optimal. In between are the ranges that
    are in between disaster and optimal. These represent compromise
    maneuvers that the helm may opt for if there are other behaviors
    that find such maneuvers useful for accomplishing their
    objectives.}
  \label{fig_avdcol_util}
\end{figure}
\vspace{0.1in}

\noindent
The \bvar{min\_util\_cpa\_dist} and \bvar{max\_util\_cpa\_dist}
parameters have a default value of 10 and 75 meters respectively. These
values are very subjective and will need to be adjusted per vehicle
and mission. Currently these defaults are used if not specified by
the user, but in future releases overriding these values may be
enforced.

\vspace{0.1in}
\begin{figure}[H]
  \centering 
  \includegraphics[width=0.99\textwidth]{figures/bhv_avdcol_cpa_effect.png}
  \caption{Two vehicles use the AvoidCollision behavior to avoid the
    oblivious and non-maneuvering eastbound vehicle. One vehicle, ben,
    is configured with the \bvar{min\_util\_cpa\_dist} and
    \bvar{max\_util\_cpa\_dist} paremeters set to 5 and 15 meters
    respectively. The other vehicle, cal, is more risk averse and has
    these to parameters set to 15 and 25 meters respectively. The
    resulting trajectories of ben and cal are shown. The two vehicles
    on the right are simulated separately, unaware of each other, with
    the same starting position and parameters except for two above
    parameters. The divergence in trajectory is soley due to the differences
    around these two parameters.}
  \label{fig_avdcol_cpa_effect}
  \urlvideo{https://vimeo.com/458207817}{0:13}
\end{figure}
\vspace{0.1in}

%=======================================================================
\subsection{Specifying Contact Flags}
\label{sec_bhv_avdcol_cnflags}

Contact flags are new feature for all contact behaviors, available in
releases after Release 19.8.1.


%=======================================================================
\subsection{Using the CPA Refinery}
\label{sec_bhv_avdcol_refinery}



%=======================================================================
\subsection{Relevant Example Missions}
\label{sec_bhv_avdcol_xmissions}





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