# Modifications to ArduSub That Improve BlueROV SITL Accuracy and Design of Hybrid Autopilot
## 5 Controller Tuning Methodology
### Additional Damping Term to Correct for Nonlinear Behavior  
With the effective linear damping approximation selected, step response tests were performed and compared to the theoretical LTI system step response to assess how the controller handled a step input to rotate from a \(0^{\circ}\) heading to a heading of \(90^{\circ}\) and hold the position. A simple step input was generated such that at \(t<0\), \(\psi_{d}=0\) and at \(t\geq 1\), \(\psi_{d}=90^{\circ}\), with all other inputs null and put into comma-separated value (csv) file format. The step input was fed through a ROS csv_reader node into a separate ROS control_law node, which monitored vehicle state and calculated the force outputs according to the PD control law as described in Section 4. The resulting step responses were recorded to csv files with a ROS logger node. This was then graphed against the theoretical step response. The theoretical step response was calculated using the transfer function of the control law in the yaw direction which can be derived from Equation (A13) by taking the Laplace transform and rearranging. The resulting transfer function is  
\[H_{L}=\frac{\Psi(s)}{\Psi_{d}(s)}=\frac{k_{p}(\omega_{d})+sk_{d}(\omega_{d})}{ s^{2}(l_{zz}+N_{r})+s(\tilde{N}_{r}+k_{d}(\omega_{d}))+k_{p}(\omega_{d})} \tag{22}\]  
Figure 12: Nonlinear drag torque vs. velocity along with the trimmed linear fit; the line designated by \(\tilde{N}_{r}=5.97\,\mathrm{Nms/rad}\) fit well in the possible yaw torque range. where \(H_{L}\) is the closed-loop LTI transfer function, \(\Psi(s)\) is the Laplace transform of yaw heading, \(\Psi_{d}(s)\) is the Laplace transform of the desired yaw heading, \(k_{p}\) is proportional gain determined by the \(\omega_{d}\) setting, \(k_{d}\) is derivative gain determined by the \(\omega_{d}\) setting, and \(\dot{N}_{r}\) is the chosen characteristic linear damping. Setting \(\psi_{d}=H(0)\), the Heaviside step function becomes \(\Psi_{d}(s)=1/s\) and performing the inverse Laplace transform on Equation (22), a function for \(\psi(t)\) is obtained, which was used to generate the theoretical step response for various gains. According to the linear function of the LTI system, the chosen \(\omega_{d}\) and resulting \(k_{p}\) and \(k_{d}\) gains theoretically produce a critically damped response, which are shown as the dashed lines in Figure 13. Of note is the theoretical low \(\omega_{d}=2.0\,\mathrm{rad/s}\) step response; there is an initial undershoot due to \(k_{d}<0\) causing the system to become a nonminimum-phase system [40]. The actual response of the nonlinear system, shown with solid lines, produced underdamped step responses, that steadily improved with increasing \(\omega_{d}\), but did not reach critically damped behavior. As the goal is to attain critically damped behavior for the entire range of \(\omega_{d}\), the solution is to increase the damping via the artificial damping enacted by \(k_{d}\). Observing how low \(\omega_{d}\) needs more damping than higher \(\omega_{d}\), the amount of additional damping necessary is inversely related to \(\omega_{d}\). Hence, a small \(\delta k_{d}\) term was added to the original calculated \(k_{d}\), which scales inversely with \(\omega_{d}\), with the form  
\[\delta k_{d}=\frac{\kappa}{\omega_{d}^{2}} \tag{23}\]  
where \(\kappa\) is a constant of proportionality and \(\omega_{d}\) is the desired bandwidth that \(k_{d}\) was originally calculated for. The \(\omega_{d}\) term is squared because of the relatively low values of \(\omega_{d}\) for this system. The new control law becomes  
\[N_{C}=k_{p}(\omega_{d})[\psi_{d}-\psi]+[k_{d}(\omega_{d})+\delta k_{d}(\omega _{d})][\dot{\psi}_{d}-\dot{\psi}], \tag{24}\]  
A range of various constants of proportionality were tested across a wide range of \(\omega_{d}\). It was found that the value for the constant of proportionality that nullified oscillations best resulting in a critically damped or nearly critically damped step response was \(\kappa=20.0\).