## 3 Simulating ROV Dynamics
### Method Overview
#### 3.1.1 Kinematics  
For inertial reference frame N and a rigid body B of the ROV, we define the generalized coordinates \(q_{0.2}\) and \(q_{3.5}\) as the ROV position and orientation respectively and the subsequent generalized speeds which are the angular and linear velocities as \(u_{0.2}\) and \(u_{3.5}\), respectively. To properly define the ROV reference frame R we define the order of rotation to be zyx intrinsic rotation order which sometimes referred as yaw, pitch and roll rotations. The rotation is done in three stages and defines three more reference frames, which will also be referenced later as we define more components of the simulation. First, we define a reference frame \(\Phi\), which is rotated around the z axis of N by an angle \(q_{5}\). This is done using the functions \"orientnew\" and \"set_ang_vel\" from SymPy mechanics. We repeat this process and define \(\Theta\) which is rotated with respect to \(\Phi\) around the y axis of \(\Phi\), and finally we define \(\Psi\) (the final ROV frame) which is rotated around the x axis of \(\Theta\). We can use the power of symbolic to display us the rotation matrix as presented in Equation (1).  
\[\begin{bmatrix}\cos\left(q_{4}\right)\cos\left(q_{5}\right)&\sin\left(q_{5} \right)\cos\left(q_{4}\right)&-\sin\left(q_{4}\right)\\ \sin\left(q_{3}\right)\sin\left(q_{4}\right)\cos\left(q_{5}\right)-\sin\left(q _{5}\right)\cos\left(q_{3}\right)&\sin\left(q_{3}\right)\sin\left(q_{4}\right) \sin\left(q_{5}\right)+\cos\left(q_{3}\right)\cos\left(q_{5}\right)&\sin\left(q _{3}\right)\cos\left(q_{4}\right)\\ \sin\left(q_{3}\right)\sin\left(q_{5}\right)+\sin\left(q_{4}\right)\cos\left(q _{3}\right)\cos\left(q_{5}\right)&-\sin\left(q_{3}\right)\cos\left(q_{5} \right)+\sin\left(q_{4}\right)\sin\left(q_{5}\right)\cos\left(q_{3}\right)& \cos\left(q_{3}\right)\cos\left(q_{4}\right)\end{bmatrix} \tag{1}\]  
In order to apply gravity and buoyancy forces we need to define the centre of mass (COM) and centre of buoyancy (COB) in the reference frame. The COM point is defined with respect to the world coordinate origin and are simply \(q_{0.2}\) and the velocity is \(u_{0.2}\) in N. The other points on our rigid body are defined with respect to that point. The position of COB is defined as:  
\[P_{cob}=B_{w}\mathbf{\hat{\Psi}_{x}}+B_{h}\mathbf{\hat{\Psi}_{z}} \tag{2}\]where \(B_{w}\) and \(B_{h}\) are the dimensions presented in Figure 2 and \(\mathbf{\hat{\Psi}_{x}}\) and \(\mathbf{\hat{\Psi}_{z}}\) are the unit vectors of our ROV frame.  
To calculate the velocity of COB in N we use the following equation [13]  
\[{}^{N}V_{cob}=^{N}V_{com}+^{N}\omega^{\Psi}\times\mathbf{r} \tag{3}\]  
where \({}^{N}V_{cob}\) and \({}^{N}V_{com}\) are velocities in the inertial frame \(N\) and \({}^{N}\omega^{\Psi}\) is the angular velocity of \(\Psi\) with respect to \(N\) and \(\mathbf{r}\) is the position vector from COM to COB. In a similar manner we define velocities of the rest of the fixed points in the ROV frame which represent the positions of the thrusters, e.g., \(L_{1}\), \(L_{2}\) and \(L_{3}\) as can be seen in Figure 2.  
Equation (4) is enforcing the relationships between the generalized coordinates and the generalized speeds and referred as the kinematic differential equations which are input to the [PERSON]'s method implementation in SymPy mechanics package we are using [11; 14].  
\[u_{r}=\dot{q}_{r},\quad r=0..6 \tag{4}\]