<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.2S01Lab07Controls}
\wikidoc{auth=supun@mit.edu}
\helplevelsubsec

%===================================================================
% Build the Cover Page in an environment style easy for wiki parsing
\begin{labcover}
\labtitle{Lab 7 - Low-level Control Systems of AUVs}
\vspace{0.2in}
\labcourse{2.S01 Introduction to Autonomous Underwater Vehicles}
\vspace{0.5in}
\labpng{0.8}{figures/PID.png}
\vspace{0.25in}
\labdate{Spring 2024}
\vspace{0.23in}
\labauth{Supun Randeni, supun@mit.edu}
\labauth{Michael Benjamin, mikerb@mit.edu}
\labauth{Mike Sacarny, msacarny@mit.edu}
\labauth{Department of Mechanical Engineering}
\labauth{MIT, Cambridge MA 02139}
\labtoc{scriptsize}
\labtocdepth{2}
\end{labcover}

%===================================================================
\blankpage

%===================================================================
% Begin the body of the text
%===================================================================
\section{Objectives}
%===================================================================

\begin{labinfo}
%\labinfoheader{Topics:}
\begin{packed_itemize}[2]
\item Learning how to merge git branches.
\item Learning how to update and rebuilt software using the \cmd{build\_mitfs} script.
\item Learning how to conduct post-mission analysis of vehicle data.
\item Understanding the effects of PID gains on the control performance of an AUV.
\item Understanding how to tune PID gains of an AUV using trial-and-error method.
\end{packed_itemize}
\end{labinfo}


%===================================================================
\section{Updating your git branch with the latest class software features}
%===================================================================

This week, we have updated the MITFrontseat software stack with a number of new features. To obtains these features, you will need to update the \cmd{2.s01} git branch of \cmd{MITFrontseat}, \cmd{MITFrontseat-drivers} and \cmd{missions-seabeaver} repositories, and re-build them. However, as part of the {\em Underwater Navigation} lab, you created a new git branch of \cmd{missions-seabeaver} with your own vehicle's name (e.g. in my case, a branch named \cmd{avi}). In order to pull the code changes that instructors made in the \cmd{2.s01} branch into your own branch, you will need to merge the \cmd{2.s01} branch into your own branch. We highly recommend you to read more about git merging on your own time (\urlx{https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging}).

%===========================
\subsection{Ensuring that you have committed all your local changes}
%===========================

Before we merge the \cmd{2.s01} branch into your own branch, it is good practice to check the status of your branch and make sure there are no uncommitted local changes on your topside laptop:

\vspace{0.1in}
\begin{consoleverb}
$ git status
On branch avi
Your branch is up to date with 'origin/avi'.

nothing to commit, working tree clean
\end{consoleverb}
\vspace{0.1in}

\noindent In my case, the \cmd{avi} branch is does not have any modified files that are not committed, or untracked files. So I am ready to merge. However, if you have untracked files or code modifications that are not committed, you might see something similar to this:

\vspace{0.1in}
\begin{consoleverb}
$ git status
On branch avi
Your branch is up to date with `origin/avi'.

Untracked files:
  (use "git add &lt;file&gt;..." to include in what will be committed)
	vehicle/avi.def
	vehicle/avi_sensor_config.txt

nothing added to commit but untracked files present (use "git add" to track)
\end{consoleverb}
\vspace{0.1in}

\noindent In this case you may choose to either destroy these changes using \cmd{\$ git reset --hard} command or commit these changes (see the {\em Underwater Navigation} lab for more information). 


%===========================
\subsection{Merging the \cmd{2.s01} branch into your own branch}
%===========================

Before we merge, let's ensure that we have pulled the updates to \cmd{2.s01} on to your local topside computer. To do that, let's switch to that branch using \cmd{\$ git checkout 2.s01} command:

\vspace{0.1in}
\begin{consoleverb}
$ git checkout 2.s01 
Switched to branch '2.s01'
Your branch is up to date with 'origin/2.s01'.
\end{consoleverb}
\vspace{0.1in}

\noindent Pull the changes to \cmd{2.s01} from the git remote server on to your topside laptop using \cmd{\$ git pull origin 2.s01} command:

\vspace{0.1in}
\begin{consoleverb}
$ git pull origin 2.s01 
Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.112.4'
Offending key for IP in /home/sb-topside-15/.ssh/known_hosts:4
Matching host key in /home/sb-topside-15/.ssh/known_hosts:60
Are you sure you want to continue connecting (yes/no)? yes
From github.com:supun-randeni/missions-seabeaver
 * branch            2.s01      -&gt; FETCH_HEAD
Already up to date.
\end{consoleverb}
\vspace{0.1in}

\noindent Let's switch back to your own branch (in my case, the branch named \cmd{avi} - using \cmd{\$ git checkout avi} command). {\bf It will very important that you do this properly. Otherwise, you might merge your own branch into the \cmd{2.s01} branch.}

\vspace{0.1in}
\begin{consoleverb}
$ git checkout avi 
Switched to branch 'avi'
Your branch is up to date with 'origin/avi'.
\end{consoleverb}
\vspace{0.1in}

\noindent Finally we can merge the changes to \cmd{2.s01} branch into your own branch using \cmd{\$ git merge 2.s01} command:

\vspace{0.1in}
\begin{consoleverb}
$ git merge 2.s01 
\end{consoleverb}
\vspace{0.1in}

\noindent A terminal window might pop up with nano text editor, asking to the enter a comment about this merge. You may enter a comment and exit by pressing ctrl+x key. Then you should see an output similar to the follows:

\vspace{0.1in}
\begin{consoleverb}
$ git merge 2.s01 
Merge made by the 'recursive' strategy.
 build_scripts/build_mitfs.sh                   | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 cruise/lab_7_control.def                       |  22 ++++++++
 cruise/lab_7_control_pMITFS_MissionScript.plug |  44 ++++++++++++++++
 3 files changed, 211 insertions(+)
 create mode 100755 build_scripts/build_mitfs.sh
 create mode 100644 cruise/lab_7_control.def
 create mode 100644 cruise/lab_7_control_pMITFS_MissionScript.plug
\end{consoleverb}
\vspace{0.1in}

\noindent If you and the instructors both have edited the same file (which should not be the case here, but it will likely happen in the future), you will get a warning about a merge conflict. In such situations both parties need to discuss and resolve the merge conflict. In case if you see a merge conflict, please contact the instructors.

%===========================
\subsection{Pushing your updated branch to the git remote server}
%===========================

By merging \cmd{2.s01} branch into your own branch, you have made some changes to your own branch in the topside computer. We call them local changed. Now you need to push them to the git remote server, so the latest version of your branch (e.g., \cmd{avi} branch in my case) can also be pulled on to your Raspberry Pi and PocketBeagle later:

\vspace{0.1in}
\begin{consoleverb}
$ git push origin avi 
Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.113.4'
Offending key for IP in /home/sb-topside-15/.ssh/known_hosts:9
Matching host key in /home/sb-topside-15/.ssh/known_hosts:60
Are you sure you want to continue connecting (yes/no)? yes
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 282 bytes | 282.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:supun-randeni/missions-seabeaver.git
   15e9fd6..fed544d  avi -&gt; avi
\end{consoleverb}
\vspace{0.1in}


%===================================================================
\section{Updating and rebuilding software using \cmd{build\_mitfs.sh} script}
%===================================================================

As we dsicussed in the {\em Underwater Navigation} lab, updating and rebuilding the software on the vehicle was a lengthy process with several steps:

\begin{itemize}
    \item Update and rebuild \cmd{MITFrontseat} on the topside laptop
    \item Update and rebuild \cmd{MITFrontseat-drivers} on the topside laptop
    \item Update \cmd{missions-seabeaver} on the topside laptop
    \item Update and rebuild \cmd{MITFrontseat} on the Raspberry Pi
    \item Update and rebuild \cmd{MITFrontseat-drivers} on the Raspberry Pi
    \item Update \cmd{missions-seabeaver} on the Raspberry Pi
    \item Update and rebuild \cmd{MITFrontseat} on the PocketBeagle
    \item Update and rebuild \cmd{MITFrontseat-drivers} on the PocketBeagle
    \item Update \cmd{missions-seabeaver} on the PocketBeagle
\end{itemize}

It was important for you to know this process in order to understand the software architecture. However, now we are introducing to an automated shell script that will simplify this process.

The \cmd{build\_mitfs.sh} script will automatically update (i.e. \cmd{git pull}) \cmd{MITFrontseat}, \cmd{MITFrontseat-drivers} and \cmd{missions-seabeaver} to the latest versions of their respective branches. Then it will rebuild \cmd{MITFrontseat} and \cmd{MITFrontseat-drivers}. More interestingly, if you run this script on the Raspberry Pi, it will update and rebuild software on the Raspberry Pi as well as on the PocketBeagle.


Please note that \cmd{build\_mitfs.sh} does not change the branches. It will simply update the current branch that you are in. If you need to change a branch, you will still need to manually do it.

%===========================
\subsection{Running \cmd{build\_mitfs.sh} on the topside computer}
%===========================

This script is located at \cmd{missions-seabeaver/build\_scripts/build\_mitfs.sh}. Let's change the directory and run the script:

\vspace{0.1in}
\begin{consoleverb}
$ cd ~/missions-seabeaver/build_scripts
$ ./build_mitfs.sh 
\end{consoleverb}
\vspace{0.1in}

\noindent It will first show the current branches that your topside laptop is in. followed up an update and rebuild: 

\vspace{0.1in}
\begin{consoleverb}
$ ./build_mitfs.sh 

Building MITFrontseat on sb-topside-15..

MITFrontseat is available.
MITFrontseat is in branch:  2.s01 

MITFrontseat-drivers is available.
MITFrontseat-drivers is in branch:  2.s01 

missions-seabeaver is in branch:  avi 

Updating MITFrontseat..
Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.114.3'
Offending key for IP in /home/sb-topside-15/.ssh/known_hosts:6
Matching host key in /home/sb-topside-15/.ssh/known_hosts:60
Are you sure you want to continue connecting (yes/no)? yes
Already up to date.

Updating MITFrontseat-drivers..
Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.114.3'
Offending key for IP in /home/sb-topside-15/.ssh/known_hosts:6
Matching host key in /home/sb-topside-15/.ssh/known_hosts:60
Are you sure you want to continue connecting (yes/no)? yes
Already up to date.

Updating missions-seabeaver..
Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.114.3'
Offending key for IP in /home/sb-topside-15/.ssh/known_hosts:6
Matching host key in /home/sb-topside-15/.ssh/known_hosts:60
Are you sure you want to continue connecting (yes/no)? yes
Already up to date.

Sending build command to MITFrontseat-drivers on sb-topside-15..
\end{consoleverb}
\vspace{0.1in}

\noindent Once building is complete, it is important to scroll up and inspect the output to ensure that there are no build errors.

%===========================
\subsection{Running \cmd{build\_mitfs.sh} on the Raspberry Pi}
%===========================

This script is a new feature that was added recently. Therefore, you will need to update \cmd{missions-seabeaver} repository on both Raspberry Pi and PocketBeagle before being able to use it. Run the following commands on both Raspberry Pi and PocketBeagle to update:

\vspace{0.1in}
\begin{consoleverb}
$ cd ~/missions-seabeaver/
$ git pull
\end{consoleverb}
\vspace{0.1in}

\noindent From now on, you can simply run \cmd{build\_mitfs.sh} on the Raspberry Pi, and it will automatically update (i.e. run \cmd{git pull}) \cmd{MITFrontseat}, \cmd{MITFrontseat-drivers} and \cmd{missions-seabeaver} to the latest versions of their respective branches, and rebuild \cmd{MITFrontseat} and \cmd{MITFrontseat-drivers}. Then, it will also update and rebuild software on the PocketBeagle. To run \cmd{build\_mitfs.sh} script:

\vspace{0.1in}
\begin{consoleverb}
$ cd ~/missions-seabeaver/build_scripts
$ ./build_mitfs.sh 
\end{consoleverb}
\vspace{0.1in}

\noindent Let it update and build.. Once building is complete, please scroll up and inspect the output to ensure that there are no build errors.

%===================================================================
\section{Tuning the PID gains in software-in-the-loop simulations}
%===================================================================

During the lecture {\em ``Low-level Control Systems of AUVs"}, we discussed about the proportional-integral-derivative (PID) control algorithm, and that tuning of the P, I and D gains is critical to obtain good control performance. 
In this section of the lab, we will try to tune the control gains of your vehicle by conducting software-in-the-loop simulations. 

The PID tuning approach that we will use in this class is called `trial-and-error' method. In this approach, we will adjust the Kp, Ki and Kd gains, one at a time, while keeping in mind how each gain affects the control performance. For example,

\begin{enumerate}
    \item You will conduct a PID tuning mission.
    \item Download the log files to the topside computer (i.e. only if you are running the experiment in hardware-in-the-loop simulations or in-water by conducting actual deployments).
    \item Visualize data using the \cmd{alogview} tool, and examine the motion response of the vehicle.
    \item Decide which gains need to be adjusted, and make the change in the vehicle definition file.
    \item Conduct the PID tuning mission again with the updated PID gains.
    \item Repeat.. 
\end{enumerate}

Later in this class, we will follow the same steps to tune the PID gains of your actual vehicle by conducting in-water experiments. Therefore, it is useful for you to get familiar with the PID tuning process in software-in-the-loop simulations, where you can make mistakes and learn.


%===========================
\subsection{Cleaning up past log files}
%===========================

Every time you launch a MOOS community, a MOOS log file is automatically generated. This happens in all computers; i.e. the topside laptop, Raspberry Pi and PocketBeagle. In each computer, these files are generated in the directory: \cmd{missions-seabeaver/logs}.  If a particular log file is important to you (e.g. you should keep log files from all in-water experiments that you conduct), you should copy it to a different place. Once you copied the logs that are important to you, \cmd{missions-seabeaver/logs} directory can be cleared by running the \cmd{clean\_logs.sh} script:

\vspace{0.1in}
\begin{consoleverb}
$ cd ~/missions-seabeaver/
$ ./clean_logs.sh
\end{consoleverb}
\vspace{0.1in}

\noindent Don't forget that this directory exists in all three computers, and logs will be generated in them (i.e. topside logs in the topside computer, backseat logs in the Raspberry Pi, and frontseat logs in the PocketBeagle). Therefore, it is important that you clean logs in all three.

%===========================
\subsection{Configuring PID gains for your AUV}
%===========================

In {\em Underwater Navigation} lab you created a definition file for your own vehicle in \cmd{missions-seabeaver/vehicle} directory. For instance, for the AUV named \cmd{avi}, these definition files are as follows:

\begin{itemize}
    \item \cmd{avi.def}
    \item \cmd{avi\_sensor\_config.txt}
\end{itemize}

Please inspect the \cmd{*.def} file for your vehicle (e.g. \cmd{avi.def}) using your favorite text editor. Around like 87, under the section {\em PID control related}, you will see the PID gain settings of your vehicle:

\vspace{0.1in}
\begin{consoleverb}
// ************************************************************************************************
// PID control related 
// ************************************************************************************************
#define ENABLE_TRI_FIN_HEADING_CONTROL    true
#define ELEVATOR_HEADING_CONTROL_PERCENT  50

#define PROP_MODE_VEHICLE_PITCH_LIMIT     20

#define PROP_MODE_ROLL_KP                 0
#define PROP_MODE_ROLL_KI                 0
#define PROP_MODE_ROLL_KD                 0
#define PROP_MODE_ROLL_MAX_INTEGRAL       10

#define PROP_MODE_PITCH_KP                0.5
#define PROP_MODE_PITCH_KI                0
#define PROP_MODE_PITCH_KD                0
#define PROP_MODE_PITCH_MAX_INTEGRAL      5

#define PROP_MODE_DEPTH_KP                20
#define PROP_MODE_DEPTH_KI                0.2
#define PROP_MODE_DEPTH_KD                0
#define PROP_MODE_DEPTH_MAX_INTEGRAL      6

#define PROP_MODE_HEADING_KP              0.3
#define PROP_MODE_HEADING_KI              0
#define PROP_MODE_HEADING_KD              0.8
#define PROP_MODE_HEADING_MAX_INTEGRAL    10

#define PROP_MODE_SPEED_KP                20
#define PROP_MODE_SPEED_KI                0.5
#define PROP_MODE_SPEED_KD                0
#define PROP_MODE_SPEED_MAX_INTEGRAL      50

#define PROP_MODE_SPEED_CURVE             0.9:30 | 0.7:25 | 0.3:10 | 1.3:40
\end{consoleverb}
\vspace{0.1in}

\noindent Let's see what each of these parameters mean, and their effects towards the control performance of the vehicle.

%===========================
\subsection{Tuning the heading control sub-system} \label{sec_heading_tuning}
%===========================

The PID gains for the heading sub-system are defined under following section of the \cmd{*.def} file:

\vspace{0.1in}
\begin{consoleverb}
#define PROP_MODE_HEADING_KP              0.3
#define PROP_MODE_HEADING_KI              0
#define PROP_MODE_HEADING_KD              0.8
#define PROP_MODE_HEADING_MAX_INTEGRAL    10
\end{consoleverb}
\vspace{0.1in}

\noindent For example, the P gain for the heading sub-system (\cmd{PROP\_MODE\_HEADING\_KP}) is currently set to 0.3. It can be changed by editing this file. 


%---------------------------
\subsubsection{Observing the heading performance for the current PID gain setting}
%---------------------------

Before we start tuning, let's run a simulation and observe the control performance for the current PID gains. We have created a new cruise called \cmd{lab\_7\_control} for PID tuning. This mission has five legs, each at a constant heading, conducting a zig-zag pattern run. Recall that we need to configure the architecture, vehicle and cruise before running the mission (in my case, the AUV name is \cmd{avi}):

\vspace{0.1in}
\begin{consoleverb}
$ cd ~/missions-seabeaver/launch_scripts/
$ ./configure_architecture.sh seabeaver_ii
$ ./configure_vehicle.sh avi
$ ./configure_cruise.sh lab_7_control
\end{consoleverb}
\vspace{0.1in}

\noindent Now you can launch the mission in software-in-the-loop simulation (I am running the simulation 5 times faster than real-time):

\vspace{0.1in}
\begin{consoleverb}
$ ./launch_simulation.sh 5
\end{consoleverb}
\vspace{0.1in}

The \cmd{pMarineViewer} window will pop up, and you will see the vehicles moving. Once the mission ended, lets visualize the logs using \cmd{alogview}. Go to the directory where logs are generated, and list all the files:

\vspace{0.1in}
\begin{consoleverb}
$ cd ~/missions-seabeaver/logs/
$ ls
LOG_SB2_ALPHA_Backseat_30_4_2024_____22_04_12  LOG_SB2_ALPHA_Frontseat_30_4_2024_____22_04_12  LOG_SB2_ALPHA_VECTORS_30_4_2024_____22_04_12  LOG_VECTORS__hydro_summary_.txt
LOG_SB2_ALPHA_Backseat_30_4_2024_____22_10_46  LOG_SB2_ALPHA_Frontseat_30_4_2024_____22_10_45  LOG_SB2_ALPHA_VECTORS_30_4_2024_____22_10_46
\end{consoleverb}
\vspace{0.1in}

\noindent Since we run three MOOS communities in the topside computer during simulations, you can see logs from all three (i.e. backseat MOOS community, frontseat MOOS community, and VECTORS MOOS community). For PID tuning, we are only interested in the backseat MOOS community. In my case, I have logs from previous missions as well. Therefore we need to choose the correct log file. Usually it is the latest one (i.e. \cmd{LOG\_SB2\_ALPHA\_Backseat\_30\_4\_2024\_\_\_\_\_22\_10\_46}). Let's visualize it using \cmd{alogview}:

\vspace{0.1in}
\begin{consoleverb}
$ cd LOG_SB2_ALPHA_Backseat_30_4_2024_____22_10_46/
$ alogview LOG_SB2_ALPHA_Backseat_30_4_2024_____22_10_46.alog
\end{consoleverb}
\vspace{0.1in}

\noindent The \cmd{alogview} window shown in Figure \ref{fig_alogview} will pop up.


\vspace{0.1in}
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{figures/alogview.png}
\caption{The \cmd{alogview} window}
\label{fig_alogview}
\end{figure}

In \cmd{alogview}, you are able to plot time-series data (\urlx{https://oceanai.mit.edu/ivpman/pmwiki/pmwiki.php?n=IvPTools.ALogView##sec_alogview}). For example, you can plot the variation of \cmd{DESIRED\_HEADING} and \cmd{NAV\_HEADING} with time. For example, load \cmd{NAV\_HEADING} in \cmd{LogPlots(L)} pull-down menu, and \cmd{DESIRED\_HEADING} in \cmd{LogPlots(L)} pull-down menu. You will see a response similar to Figure \ref{fig_LogPlots}. Plot the following MOOS variables, and try to understand their responses:

\begin{itemize}
    \item \cmd{DESIRED\_HEADING}
    \item \cmd{DESIRED\_DEPTH}
    \item \cmd{DESIRED\_SPEED}
    \item \cmd{LOG\_PID\_DESIRED\_PITCH}

    \item \cmd{NAV\_HEADING}
    \item \cmd{NAV\_DEPTH}
    \item \cmd{NAV\_SPEED}
    \item \cmd{NAV\_PITCH}
    
    \item \cmd{LOG\_PID\_HEADING\_ERROR}
    \item \cmd{LOG\_PID\_DEPTH\_ERROR}
    \item \cmd{LOG\_PID\_PITCH\_ERROR}

    \item \cmd{UPPER\_RUDDER}
    \item \cmd{STBD\_ELEVATOR}
    \item \cmd{PORT\_ELEVATOR}
    \item \cmd{PROPELLER}
\end{itemize}

\vspace{0.1in}
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{figures/logplot.png}
\caption{Time-series data of \cmd{DESIRED\_HEADING} and \cmd{NAV\_HEADING}}
\label{fig_LogPlots}
\end{figure}


%---------------------------
\subsubsection{Changing heading PID gains}
%---------------------------

Now you can experiment with different Kp, Ki and Kd gains of the heading sub-system and observe the variation in the motion response (e.g. values such as 0.1, 0.2, 0.4, 0.8, 1.6) for each gain.

%===========================
\subsection{Tuning the depth and pitch control sub-systems}
%===========================

As we discussed during the {\em ``Low-level Control Systems of AUVs"} lecture, the depth control of under-actuated AUVs is achieved in two steps. That is, as shown in Figure \ref{fig_control}, (1) the depth control sub-system computes the desired pitch angle of the AUV to minimize the depth error, and (2) the pitch control sub-system computes the elevator angle to minimize the pitch error.

\vspace{0.1in}
\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{figures/control_diagram.png}
\caption{Low-level control sub-systems of SeaBeaver II AUVs}
\label{fig_control}
\end{figure}

The PID gains for the depth and pitch sub-system are defined under following section of the \cmd{*.def} file:

\vspace{0.1in}
\begin{consoleverb}
#define PROP_MODE_PITCH_KP                0.5
#define PROP_MODE_PITCH_KI                0
#define PROP_MODE_PITCH_KD                0
#define PROP_MODE_PITCH_MAX_INTEGRAL      5

#define PROP_MODE_DEPTH_KP                20
#define PROP_MODE_DEPTH_KI                0.2
#define PROP_MODE_DEPTH_KD                0
#define PROP_MODE_DEPTH_MAX_INTEGRAL      6
\end{consoleverb}
\vspace{0.1in}

\noindent Following the same procedure described in Section \ref{sec_heading_tuning}, try to change the PID gains of both depth and pitch sub-systems (one at a time), and observe the response.  


%===========================
\subsection{Exercise: tuning the heading, depth and pitch PID control sub-systems}
%===========================

Tune the heading, depth and pitch PID gains to obtain a decent control response of the vehicle. Please ensure that the rudder and elevators are not oscillating at a very high frequency by plotting the time-series responses of \cmd{UPPER\_RUDDER}, \cmd{STBD\_ELEVATOR} and \cmd{PORT\_ELEVATOR} MOOS variables.


% %===========================
% \subsection{Speed-to-thrust percentage curve}
% %===========================

%===========================
\subsection{Exercise: Pushing your tuned PID gains to the git remote server}
%===========================

Once you are satisfied with the control performance, you should conduct a hardware-in-the-loop simulation using these new PID gains. To transfer these new gains to the Raspberry Pi and PocketBeagle, we need to commit the changes and push them to your branch in the git remote server. If you don't remember how to do this, please follow the relavant steps in the {\em Underwater Navigation} lab.


%===================================================================
\section{Testing the tuned PID gains by conducting hardware in the loop simulations}
%===================================================================

Once you pushed the updated gains to your branch in the git remote server, we can pull them to the Raspberry Pi and PocketBeagle to test the new gain in hardware-in-the-loop simulations. 

%===========================
\subsection{Updating the software}
%===========================

We can utilize the new \cmd{build\_mitfs.sh} script to update and rebuild the software on the two embedded computers. It's important to remember that this script won't alter git branches; rather, it will update the current branches of \cmd{MITFrontseat}, \cmd{MITFrontseat-drivers}, and \cmd{missions-seabeaver}. Therefore, please ensure that \cmd{missions-seabeaver} on both the Raspberry Pi and PocketBeagle are in the correct branch. 

\vspace{0.1in}
\begin{consoleverb}
$ cd ~/missions-seabeaver/build_scripts
$ ./build_mitfs.sh 
\end{consoleverb}
\vspace{0.1in}

\noindent Let it update and build.. 

We regularly update \cmd{MITFrontseat}, \cmd{MITFrontseat-drivers} and \cmd{missions-seabeaver} repositories. Therefore, we strongly recommend running this script first each day when you turn on the vehicle.


%===========================
\subsection{Running a hardware-in-the-loop simulation}
%===========================

Once you updated the embedded computers with your tuned PID gains, you can run a hardware-in-the loop simulation to test new gains. If you don't remember how to run hardware-in-the-loop simulations, please refer to {\em Software and Hardware in the Loop Simulations} lab.

{\bf If you are running the hardware-in-the-loop simulations on the actual AUV (i.e. not the training-kit), please do not run the thruster for more than 30 seconds continuously. Prolonged operation in air can lead to overheating of the thruster.}


%===========================
\subsection{Exercise: Downloading logs and post-mission data visualization}
%===========================

Finally, you can download the log files (using \cmd{scp} command) from the Raspberry Pi to your topside laptop, and visualize them using \cmd{alogview} tool. Create a directory on your topside laptop where you want to store your logs. For instance, I have created a folder named \cmd{avi\_logs}, and within it, a sub-folder with today's date:

\vspace{0.1in}
\begin{consoleverb}
$ cd ~
$ mkdir avi_logs 
$ cd avi_logs
$ mkdir 20240430
$ cd 20240430
\end{consoleverb}
\vspace{0.1in}

\noindent Now you can copy the logs to this folder using secure-copy:

\vspace{0.1in}
\begin{consoleverb}
$ scp -r seabeaver-raspi@10.42.0.5:/home/seabeaver-raspi/missions-seabeaver/logs/LOG* .
\end{consoleverb}
\vspace{0.1in}

\noindent Now you can visualize these logs using \cmd{alogview}.


\end{document}

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