Skip to content

Commit c51b740

Browse files
committed
BlueRobotics 2018b properties added
1 parent 124a5b6 commit c51b740

File tree

9 files changed

+139
-576
lines changed

9 files changed

+139
-576
lines changed

.DS_Store

6 KB
Binary file not shown.

diffUV/dynamics.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from casadi import SX, horzcat, inv, sin,cos, fabs, Function
1+
from casadi import SX, horzcat, inv, sin,cos, fabs, Function, diag, pinv
22
from diffUV.base import Base
33
from diffUV.utils.symbol import *
44
from diffUV.utils.operators import cross_product
@@ -39,7 +39,7 @@ def get_inertia_matrix(self):
3939

4040
def coriolis_centripetal_matrix(self):
4141
"""Compute and return the Coriolis and centripetal matrix based on current vehicle state."""
42-
M = self.inertia_matrix()
42+
M = self.get_inertia_matrix()
4343
M11 = M[:3, :3]
4444
M12 = M[:3, 3:]
4545
M21 = M[3:, :3]
@@ -64,29 +64,36 @@ def gvect(self):
6464
sin(phi) - (y_g*W - y_b*B)*sin(thet)
6565
# For neutrally buoyant vehicles W = B
6666
return g
67+
68+
def gvect_quat(self):
69+
"""Compute and return the hydrostatic restoring forces using quaternions."""
70+
g_quat = SX(6, 1)
71+
g_quat[0, 0] = (B-W)*(2*eps1*eps3 - 2*eps2*eta)
72+
g_quat[1, 0] = (B-W)*(2*eps2*eps3 - 2*eps1*eta)
73+
g_quat[2, 0] = (W-B)*(2*eps1**2 - 2*eps2**2 -1)
74+
g_quat[3, 0] = z_g*W*(2*eps2*eps3 + 2*eps1*eta)
75+
g_quat[4, 0] = z_g*W*(2*eps1*eps3 + 2*eps2*eta)
76+
g_quat[5, 0] = 0
77+
# For neutrally buoyant vehicles W = B
78+
return g_quat
79+
6780

6881
def damping(self):
6982
"""Compute and return the total damping forces, including both linear and nonlinear components."""
70-
D = SX(6, 6)
71-
D[0, 0] = X_u
72-
D[1, 1] = Y_v
73-
D[2, 2] = Z_w
74-
D[3, 3] = K_p
75-
D[4, 4] = M_q
76-
D[5, 5] = N_r
77-
linear_damping = D@x_nb
7883

79-
Dn_vars = [Dn1, Dn2, Dn3, Dn4, Dn5, Dn6]
80-
Dn_list = [(fabs(x_nb).T @ Dn @ x_nb) for Dn in Dn_vars]
81-
nonlinear_damping = vertcat(*Dn_list)
82-
83-
damping = linear_damping + nonlinear_damping
84-
return damping
84+
linear_damping = -diag(vertcat(X_u,Y_v,Z_w,K_p,M_q,N_r))
85+
nonlinear_damping = -diag(vertcat(X_uu,Y_vv,Z_ww,K_pp,M_qq,N_rr))@fabs(x_nb)
86+
D_v = linear_damping + nonlinear_damping
87+
return D_v
8588

8689
def forward_dynamics(self):
87-
body_acc = inv(self.inertia_matrix())@(tau -self.coriolis_centripetal_matrix()@x_nb - self.gvect() -self.damping())
90+
body_acc = inv(self.get_inertia_matrix())@(tau - self.coriolis_centripetal_matrix()@x_nb - self.gvect() -self.damping()@x_nb)
8891
return body_acc
8992

9093
def inverse_dynamics(self):
91-
resultant_torque = self.inertia_matrix()@dx_nb + self.coriolis_centripetal_matrix()@x_nb + self.gvect() + self.damping()
94+
resultant_torque = self.get_inertia_matrix()@dx_nb + self.coriolis_centripetal_matrix()@x_nb + self.gvect() + self.damping()@x_nb
9295
return resultant_torque
96+
97+
def control_Allocation(self):
98+
u = inv(K)@pinv(T)@tau
99+
return u

diffUV/utils/parameters.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import numpy as np
2+
3+
class Params:
4+
thrust_config = np.array([[-0.707, -0.707, 0.707, 0.707, 0.0, 0.0, 0.0, 0.0],
5+
[0.707, -0.707, 0.707, -0.707, 0.0, 0.0, 0.0, 0.0],
6+
[0.0, 0.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0],
7+
[0.0, 0.0, 0.0, 0.0, -0.218, -0.218, 0.218, 0.218],
8+
[0.0, 0.0, 0.0, 0.0, -0.12, 0.12, -0.12, 0.12],
9+
[0.1888, -0.1888, -0.1888, 0.1888, 0.0, 0.0, 0.0, 0.0]])
10+
11+
#thrust coefficient matrix
12+
K = np.diag([40, 40, 40, 40, 40, 40, 40, 40])
13+
14+
# parameters in rigid body dynamics and restoring forces
15+
m = 11.5 #(kg)
16+
W = 112.8 #(N)
17+
B = 114.8 #(N)
18+
rb = np.array([[0], [0], [0]]) #(m)
19+
rg = np.array([[0], [0], [0.02]]) #(m)
20+
I_x = 0.16 #(kg m2)
21+
I_y = 0.16 #(kg m2)
22+
I_z = 0.16 #(kg m2)
23+
24+
# added mass parameters
25+
X_du = -5.5 #(kg)
26+
Y_dv = -12.7 #(kg)
27+
Z_dw = -14.57 #(kg)
28+
K_dp = -0.12 #(kg m2/rad)
29+
M_dq = -0.12 #(kg m2/rad)
30+
N_dr = -0.12 #(kg m2/rad)
31+
32+
Xu = -4.03 #(Ns/m)
33+
Xuu = -18.18 #(Ns2/m2)
34+
Yv = -6.22 #(Ns/m)
35+
Yvv = -21.66 #(Ns2/m2)
36+
Zw = -5.18 #(Ns/m)
37+
Zww = -36.99 #(Ns2/m2)
38+
Kp = -0.07 #(Ns/rad)
39+
Kpp = -1.55 #(Ns2/rad2)
40+
Mq = -0.07 #(Ns/rad)
41+
Mqq = -1.55 #(Ns2/rad2)
42+
Nr = -0.07 #(Ns/rad)
43+
Nrr = -1.55 #(Ns2/rad2)
44+

diffUV/utils/symbol.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@
126126

127127
###################################################################
128128

129-
X_u = SX.sym('X_u') # Drag coefficient in surge
130-
Y_v = SX.sym('Y_v') # Drag coefficient in sway
131-
Z_w = SX.sym('Z_w') # Drag coefficient in heave
132-
K_p = SX.sym('K_p') # Drag coefficient in roll
133-
M_q = SX.sym('M_q') # Drag coefficient in pitch
134-
N_r = SX.sym('N_r') # Drag coefficient in yaw
129+
X_u = SX.sym('X_u') # linear Drag coefficient in surge
130+
Y_v = SX.sym('Y_v') # linear Drag coefficient in sway
131+
Z_w = SX.sym('Z_w') # linear Drag coefficient in heave
132+
K_p = SX.sym('K_p') # linear Drag coefficient in roll
133+
M_q = SX.sym('M_q') # linear Drag coefficient in pitch
134+
N_r = SX.sym('N_r') # linear Drag coefficient in yaw
135135

136136
K_v = SX.sym('K_v') # coupled Drag coefficient in sway & roll
137137
N_v = SX.sym('N_v') # coupled Drag coefficient in sway & yaw
@@ -142,16 +142,20 @@
142142
Y_r = SX.sym('Y_r') # coupled Drag coefficient in sway & yaw
143143
K_r = SX.sym('K_r') # coupled Drag coefficient in roll & yaw
144144

145-
Dn1 = SX.sym('Dn1',6,6) # nonlinear and coupled coefficient for surge
146-
Dn2 = SX.sym('Dn2',6,6) # nonlinear and coupled coefficient for sway
147-
Dn3 = SX.sym('Dn3',6,6) # nonlinear and coupled coefficient for heave
148-
Dn4 = SX.sym('Dn4',6,6) # nonlinear and coupled coefficient for roll
149-
Dn5 = SX.sym('Dn5',6,6) # nonlinear and coupled coefficient for pitch
150-
Dn6 = SX.sym('Dn6',6,6) # nonlinear and coupled coefficient for yaw
145+
146+
X_uu = SX.sym('X_uu') # quadratic Drag coefficient in surge
147+
Y_vv = SX.sym('Y_vv') # quadratic Drag coefficient in sway
148+
Z_ww = SX.sym('Z_ww') # quadratic Drag coefficient in heave
149+
K_pp = SX.sym('K_pp') # quadratic Drag coefficient in roll
150+
M_qq = SX.sym('M_qq') # quadratic Drag coefficient in pitch
151+
N_rr = SX.sym('N_rr') # quadratic Drag coefficient in yaw
151152

152153
###################################################################
153154
tau = SX.sym('tau',6,1)
154155

156+
K = SX.sym('k',6,6) #thrust coefficient matrix
157+
T = SX.sym('T',6,6) #thruster configuration
158+
155159
###################################################################
156160
# Starboard–port symmetrical underwater vehicles config
157161
star_board_config = DM([[1, 0, 1, 0, 1, 0],

examples/BlueRobotics 2018b.png

325 KB
Loading
Loading

examples/user/forward_dynamics.ipynb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 4,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"ename": "ModuleNotFoundError",
10+
"evalue": "No module named 'diffUV'",
11+
"output_type": "error",
12+
"traceback": [
13+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
14+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
15+
"Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mdiffUV\u001b[39;00m\n",
16+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'diffUV'"
17+
]
18+
}
19+
],
20+
"source": [
21+
"import diffUV"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"metadata": {},
28+
"outputs": [],
29+
"source": []
30+
}
31+
],
32+
"metadata": {
33+
"kernelspec": {
34+
"display_name": "Python 3",
35+
"language": "python",
36+
"name": "python3"
37+
},
38+
"language_info": {
39+
"codemirror_mode": {
40+
"name": "ipython",
41+
"version": 3
42+
},
43+
"file_extension": ".py",
44+
"mimetype": "text/x-python",
45+
"name": "python",
46+
"nbconvert_exporter": "python",
47+
"pygments_lexer": "ipython3",
48+
"version": "3.11.7"
49+
}
50+
},
51+
"nbformat": 4,
52+
"nbformat_minor": 2
53+
}

0 commit comments

Comments
 (0)