Skip to content

Commit f4eb32e

Browse files
committed
FEAT: Working fin class for configurable fins. Added some comments
1 parent 3f6c538 commit f4eb32e

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/python_vehicle_simulator/lib/fin.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,19 @@ class fin:
1818
Coordinate system: Right-handed, x-forward, y-starboard, z-down
1919
'''
2020

21-
22-
######################### TODO add actuator dynamics
23-
# - saturating
2421
def __init__(
2522
self,
2623
a,
2724
CL,
2825
x,
2926
c = 0,
3027
angle = 0,
31-
control_subsystem='heading',
3228
rho = 1026, # Default density of seawater
3329
):
3430

3531
self.area = a # Fin area (m^2)
3632
self.CL = CL # Coefficient of lift (dimensionless)
3733
self.angle_rad = np.deg2rad(angle) # Convert angle to radians
38-
self.control = control_subsystem
3934
self.rho = rho # Fluid density (kg/m^3)
4035

4136
self.fin_actual = 0.0 #Actual position of the fin (rad)
@@ -82,7 +77,7 @@ def torque(self, Ur):
8277
numpy array: tau vector [Fx, Fy, Fz, Tx, Ty, Tz] (N*m) in body-fixed frame
8378
"""
8479

85-
ur = self.velocity_in_rotated_plane(Ur[:3]) # Use only linear velocities
80+
ur = self.velocity_in_rotated_plane(Ur[:3]) # Calulate relative velocity in plane of the fin
8681

8782
# Calculate lift force magnitude
8883
f = 0.5 * self.rho * self.area * self.CL * self.fin_actual * ur**2 # N
@@ -92,18 +87,17 @@ def torque(self, Ur):
9287
fz = -np.cos(self.angle_rad) * f # N
9388

9489
F = np.array([0, fy, fz]) # Force vector (N)
95-
# print("Force", F)
96-
# print("Radius:", self.R)
9790

9891
# Calculate torque using cross product of force and moment arm
9992
torque = np.cross(self.R, F) # N*m
10093
return np.append(F, torque)
10194

10295
def actuate(self, sampleTime, command):
103-
104-
delta_dot = (command - self.fin_actual) / self.T_delta
105-
self.fin_actual += sampleTime * delta_dot
96+
# Actuator dynamics
97+
delta_dot = (command - self.fin_actual) / self.T_delta
98+
self.fin_actual += sampleTime * delta_dot # Euler integration
10699

100+
# Amplitude Saturation
107101
if abs(self.fin_actual) >= self.deltaMax:
108102
self.fin_actual = np.sign(self.fin_actual) * self.deltaMax
109103

src/python_vehicle_simulator/vehicles/torpedo.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
psi_d: desired yaw angle (deg)
1818
n_d: desired propeller revolution (rpm)
1919
V_c: current speed (m/s)
20-
beta_c: current direction (deg)
20+
beta_c: current direction (deg)
21+
fins: number of fins (equally spaced)
2122
2223
Methods:
2324
2425
[nu,u_actual] = dynamics(eta,nu,u_actual,u_control,sampleTime ) returns
2526
nu[k+1] and u_actual[k+1] using Euler's method. The control input is:
2627
27-
u_control = [ delta_r rudder angle (rad)
28-
delta_s stern plane angle (rad)
28+
u_control = [ delta_r_top rudder angle (rad)
29+
delta_r_bottom rudder angle (rad)
30+
delta_s_star stern plane angle (rad)
31+
delta_s_port stern plane angle (rad)
2932
n propeller revolution (rpm) ]
3033
3134
u = depthHeadingAutopilot(eta,nu,sampleTime)
@@ -115,7 +118,6 @@ def __init__(
115118

116119
self.nu = np.array([0, 0, 0, 0, 0, 0], float) # velocity vector
117120
self.u_actual = np.zeros(fins+1, float) # control input vector
118-
# TODO make this the length of the fins
119121
self.controls = [
120122
"T Tail rudder (deg)",
121123
"B Tail rudder (deg)",
@@ -189,14 +191,14 @@ def __init__(
189191
self.w_pitch = math.sqrt( self.W * ( self.r_bg[2]-self.r_bb[2] ) /
190192
self.M[4][4] )
191193

192-
S_fin = 0.00665; # one fin area
194+
S_fin = 0.00665; # fin area
193195
CL_delta_r = 0.5 # rudder lift coefficient
194196
CL_delta_s = 0.7 # stern-plane lift coefficient
195197

196-
portSternFin = fin(S_fin, CL_delta_s, -a, angle=0)
197-
bottomRudderFin = fin(S_fin, CL_delta_r, -a, angle=90)
198-
starSternFin = fin(S_fin, CL_delta_s, -a, angle=180)
199-
topRudderFin = fin(S_fin, CL_delta_r, -a, angle=270)
198+
portSternFin = fin(S_fin, CL_delta_s, -a, angle=0, rho=self.rho)
199+
bottomRudderFin = fin(S_fin, CL_delta_r, -a, angle=90, rho=self.rho)
200+
starSternFin = fin(S_fin, CL_delta_s, -a, angle=180, rho=self.rho)
201+
topRudderFin = fin(S_fin, CL_delta_r, -a, angle=270, rho=self.rho)
200202
self.fins = [topRudderFin, bottomRudderFin , starSternFin, portSternFin]
201203

202204
# Low-speed linear damping matrix parameters
@@ -344,17 +346,16 @@ def dynamics(self, eta, nu, u_actual, u_control, sampleTime):
344346
# Restoring forces and moments
345347
g = gvect(self.W,self.B,eta[4],eta[3],self.r_bg,self.r_bb)
346348

347-
# Fin torques
349+
# Fin force vector
348350
tau_fins = np.zeros(6,float)
349351
for i in range(len(self.fins)):
350352
tau_fins += self.fins[i].torque(nu_r)
351-
u_actual[i] = self.fins[i].actuate(sampleTime, u_control[i])
353+
u_actual[i] = self.fins[i].actuate(sampleTime, u_control[i]) # Actuator Dynamics
352354

353-
# Generalized force vector
355+
# Thrust force vector
354356
# K_Prop scaled down by a factor of 10 to match exp. results
355357
tau_thrust = np.array([(1-t_prop) * X_prop, 0, 0, K_prop / 10, 0, 0], float)
356358

357-
tau_debug = tau_fins + tau_thrust
358359
# AUV dynamics
359360
tau_sum = tau_thrust + tau_fins + tau_liftdrag + tau_crossflow - np.matmul(C+D,nu_r) - g
360361
nu_dot = Dnu_c + np.matmul(self.Minv, tau_sum)
@@ -382,7 +383,7 @@ def stepInput(self, t):
382383
n propeller revolution (rpm) ]
383384
"""
384385
delta_r = 5 * self.D2R # rudder angle (rad)
385-
delta_s = 5 * self.D2R # stern angle (rad)
386+
delta_s = -5 * self.D2R # stern angle (rad)
386387
n = 1525 # propeller revolution (rpm)
387388

388389
if t > 100:

0 commit comments

Comments
 (0)