## Appendix A ROV Dynamics Implementation  
In this Appendix we will present a step by step detailed explanation for the simulation of the ROV dynamics. The framework we used for developing the simulation was the Jupyter notebook, an interactive data science and scientific computing platform [29] mainly for the python language. The core tool for this rigid body dynamic simulation is the SymPy Mechanics, a mechanics python package which generates the necessary symbolic equations of motions for our rigid body system [17]. Some additional supporting packages where also used mainly for plotting and for function generation. The full notebook can be accessed and downloaded for further referencing [48]. The following setup shows the necessary software package tools used in this simulation. The abbreviation \"me\" is used as a synonym for the SymPy mechanics package for compactness. ```
importmatplotlib.pyplotasplt fromsympyimport* importsympy.physics.mechanicsasme fromsympyimportsin,cos,symbols,solve frompydy.codegen.ode_function_generatorsimportgenerate_ode_function fromscipy.integrateimportdefault fromIpython.displayimportSVG me.init_vprinting(use_latex')
```  
**Listing A1**. Setup. Next we define the inertial reference frame, the generalized coordinates which are the ROV position and orientation and the subsequent generalized speeds which are the angular and linear velocities. Figure 29: Final simulation result. Running the simulation opens three windows. The left window is showing an outside view of the simulated ROV including the tether. The images on the right are the images from the simulated camera attached to the ROV (one image is with annotations and the other without). The ROV is controlled using an outside gamepad. ```
Listing A2 Symbols definitions. ``` N=me.ReferenceFrame('N')#InertialReferenceFrame O=me.Point('0')#Defineavorldcoordisympareorigin O.set_vel(N,0)#Settingworldvelocityto0 ```
#generelizedcoordinates
#q0..3=xyzpositionsq4..6=yaw,pitch,rollrotations q=list(me.dynamicsymbols('q0:6'))
#generalizedspeeds u=list(me.dynamicsymbols('u0:6')) kin_diff=Matrix(q).diff()-Matrix(u)
```

In addition we need to define the constants symbols used in our simulation where the geometric aspect of the symbols can be seen in Figure 2:

```
Wx=symbols('W_X') Wh=symbols('W_h') T1=symbols('T_1') T2=symbols('T_2') Sh=symbols('B_h') Bw=symbols('B_W') m_b=symbols('m_b')#Massofthebody v_b=symbols('v_b')#Volumeofthebody m=symbols('m=')#drag mu_r=symbols('un_r')#rotationaldrag g=symbols('g') I=list(symbols('Ixx,Iyy,Izz'))#Momentsofinertiaofbody
```

The ROV reference frame is defined by subsequent Euler angles rotations with respect to the inertial frame:

```
Rz=N.orientnew('R_z','Axis',(q[3+2],N.z)) Rz.set_ang_vel(N,u[3+2]*N.z) Ry=Rz.orientnew('R_y','Axis',(q[3+1],Rz.y)) Ry.set_ang_vel(Rz,u[3+1]*Rz.y) R=Ry.orientnew('R','Axis',(q[3+0],Ry.x)) R.set_ang_vel(Ry,u[3+0]*Ry.x)
```

**Listing A4**. ROV reference frame. In order to apply gravity and buoyancy forces we need to define the COM (Center Of Mass) and COB (Center Of Buoyancy) in the reference frame. ```
#Centerofmassofbody COM=0.locataenev('COM',q[0]*N.x+q[1]*N.y+q[2]*N.z)
#SetthevelocityofCOM COM.set_vel(N,u[0]*N.x+u[1]*N.y+u[2]*N.z)
#centerofbouyency COB=COM.locataenev('COB',R.x*Bw+R.z*Bh) COB.v2 pt_theory(COM,N,R);  
As an input to the Kane method [11] we need to calculate the inertia dyadic or matrix. The next listing defines the rigid body for the Kane equations with the relevant inertia symbols:
```
Ib=me.inertia(R,*I,ixy=0,iyz=0,izz=0) Body=me.RigidBody('Body',COM,R,m_b,(Ib,COM))
```
Listing 6 Rigid Body defentions. Next we define the drag forces that influencing the underwater ROV. ```
v=N.x*u[0]+N.y*u[1]+N.z*u[2] Fd=-v*mu T_z=(R,-u[3+2]*N.z*mu_r) T_x=(R,-u[3+0]*Hz.x*mu_r) T_y=(R,-u[3+1]*Hz.y*mu_r)#rotationaldumpingTorge
```
Listing 7 Rigid Body drag. The following are the buoyancy and gravity constant forces and the thrusters forces.