Skip to content

Commit

Permalink
update pypi yml
Browse files Browse the repository at this point in the history
  • Loading branch information
edxmorgan committed Jun 9, 2024
1 parent d29f1ce commit 162868d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ jobs:
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
repository-url: https://test.pypi.org/legacy/
19 changes: 10 additions & 9 deletions diffUV/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, func_opts=None, use_jit=True):
for k, v in self.jit_func_opts.items():
self.func_opts[k] = v
self._initialize_inertia_matrix()
self.body_state_vector = x_nb

def __repr__(self) -> str:
return "differentiable underwater dynamics"
Expand All @@ -44,20 +45,20 @@ def _initialize_inertia_matrix(self):
self.M = substitute(self.M, I_yz, SX(0))


def get_body_inertia_matrix(self):
def body_inertia_matrix(self):
"""Compute and return the UV inertia matrix with configuration adjustments."""
# M = Function("M", syms , [M], self.func_opts)
return self.M

def coriolis_body_centripetal_matrix(self):
def body_coriolis_centripetal_matrix(self):
"""Compute and return the Coriolis and centripetal matrix based on current vehicle state in body"""
M = self.get_body_inertia_matrix()
M = self.body_inertia_matrix()
C_rb = M
CA = coriolis_lag_param(MA, x_nb)
C = C_rb+CA
return C

def gvect_body(self):
def body_restoring_vector(self):
"""Compute and return the hydrostatic restoring forces."""
g = SX(6, 1)
g[0, 0] = (W - B)*sin(thet)
Expand All @@ -72,19 +73,19 @@ def gvect_body(self):
# For neutrally buoyant vehicles W = B
return g

def damping_body(self):
def body_damping_matrix(self):
"""Compute and return the total damping forces, including both linear and nonlinear components in body"""
linear_damping = -diag(vertcat(X_u,Y_v,Z_w,K_p,M_q,N_r))
nonlinear_damping = -diag(vertcat(X_uu,Y_vv,Z_ww,K_pp,M_qq,N_rr))@fabs(x_nb)
D_v = linear_damping + nonlinear_damping
return D_v

def forward_dynamics_body(self):
body_acc = inv(self.get_body_inertia_matrix())@(tau_body - self.coriolis_body_centripetal_matrix()@x_nb - self.gvect_body() -self.damping_body()@x_nb)
def body_forward_dynamics(self):
body_acc = inv(self.body_inertia_matrix())@(tau_body - self.body_coriolis_centripetal_matrix()@x_nb - self.body_restoring_vector() -self.body_damping_matrix()@x_nb)
return body_acc

def inverse_dynamics_body(self):
resultant_torque = self.get_body_inertia_matrix()@dx_nb + self.coriolis_body_centripetal_matrix()@x_nb + self.gvect_body() + self.damping_body()@x_nb
def body_inverse_dynamics(self):
resultant_torque = self.body_inertia_matrix()@dx_nb + self.body_coriolis_centripetal_matrix()@x_nb + self.body_restoring_vector() + self.body_damping_matrix()@x_nb
return resultant_torque

# def control_Allocation(self):
Expand Down
28 changes: 14 additions & 14 deletions diffUV/dynamics_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@ def __init__(self):
self.J, R, T = T_eul.J_kin(eul)
self.J_INV, _,_ = T_eul.inv_J_kin(eul)
self.J_INV_T = self.J_INV.T
self.state_vector = vertcat(n,dn)
self.ned_state_vector = vertcat(n,dn)
self.J_dot, _, _ = T_eul.J_dot(eul,deul,dT_sp,eul_sp,w_nb)

def __repr__(self) -> str:
"""Euler representation of the Dynamics instance in ned frame"""
return f'{super().__repr__()} --> (euler in ned frame)'

def get_ned_inertia_matrix(self):
def ned_euler_inertia_matrix(self):
"""Compute and return the UV inertia matrix with configuration adjustments in ned"""
M = self.get_body_inertia_matrix()
M = self.body_inertia_matrix()
M_ned = self.J_INV_T@M@self.J_INV
return M_ned

def coriolis_ned_centripetal_matrix(self):
def ned_euler_coriolis_centripetal_matrix(self):
"""Compute and return the Coriolis and centripetal matrix based on current vehicle state in body"""
C = self.coriolis_body_centripetal_matrix()
M = self.get_body_inertia_matrix()
C = self.body_coriolis_centripetal_matrix()
M = self.body_inertia_matrix()
C_ned = self.J_INV_T@(C - M@self.J_INV@self.J_dot)@self.J_INV
return C_ned

def gvect_ned(self):
g = self.gvect_body()
def ned_euler_restoring_vector(self):
g = self.body_restoring_vector()
g_ned = self.J_INV_T@g
return g_ned

def damping_ned(self):
D_v = self.damping_body()
def ned_euler_damping(self):
D_v = self.body_damping_matrix()
D = self.J_INV_T@D_v@self.J_INV
return D

def forward_dynamics_ned(self):
ned_acc = inv(self.get_ned_inertia_matrix())@(self.J_INV_T@tau_body - self.coriolis_ned_centripetal_matrix()@dn - self.gvect_ned() -self.damping_ned()@dn)
def ned_euler_forward_dynamics(self):
ned_acc = inv(self.ned_euler_inertia_matrix())@(self.J_INV_T@tau_body - self.ned_euler_coriolis_centripetal_matrix()@dn - self.ned_euler_restoring_vector() - self.ned_euler_damping()@dn)
return ned_acc

def inverse_dynamics_ned(self):
resultant_torque = self.get_ned_inertia_matrix()@ddn + self.coriolis_ned_centripetal_matrix()@dn + self.gvect_ned() + self.damping_ned()@dn
def ned_euler_inverse_dynamics(self):
resultant_torque = self.ned_euler_inertia_matrix()@ddn + self.ned_euler_coriolis_centripetal_matrix()@dn + self.ned_euler_restoring_vector() + self.ned_euler_damping()@dn
return resultant_torque
22 changes: 11 additions & 11 deletions diffUV/dynamics_quat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ def __init__(self):
super().__init__()
self.Jq_INV, _,_ = Tquat.inv_Jq_kin(uq)
self.Jq_INV_T = self.Jq_INV.T
self.state_vector = vertcat(n,dn)
# self.state_vector = vertcat(uq,..)

def __repr__(self) -> str:
"""Quaternion representation of the Dynamics instance in ned frame"""
return f'{super().__repr__()} --> (quat in ned frame)'

def get_ned_inertia_matrix_quat(self):
def quat_inertia_matrix(self):
"""Compute and return the UV inertia matrix with configuration adjustments in ned for quaternion"""
M = self.get_body_inertia_matrix()
M = self.body_inertia_matrix()
M_ned_q = self.Jq_INV_T@M@self.Jq_INV
return M_ned_q

def coriolis_ned_centripetal_matrix_quat(self):
"""Compute and return the Coriolis and centripetal matrix based on current vehicle state in body"""
C = self.coriolis_body_centripetal_matrix()
M = self.get_body_inertia_matrix()
C_ned_q = self.Jq_INV_T@(C - M@self.Jq_INV@self.Jq_dot)@self.Jq_INV
return C_ned_q
# def quat_coriolis_ned_centripetal_matrix_quat(self):
# """Compute and return the Coriolis and centripetal matrix based on current vehicle state in body"""
# C = self.body_coriolis_centripetal_matrix()
# M = self.body_inertia_matrix()
# C_ned_q = self.Jq_INV_T@(C - [email protected][email protected]_dot)@self.Jq_INV
# return C_ned_q

def gvect_ned_quat(self):
g = self.gvect_body()
g = self.body_restoring_vector()
g_ned = self.Jq_INV_T@g
return g_ned

def damping_ned_quat(self):
D_v = self.damping_body()
D_v = self.body_damping_matrix()
D = self.Jq_INV_T@D_v@self.Jq_INV
return D

Expand Down
11 changes: 6 additions & 5 deletions diffUV/utils/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@
eta,eps1,eps2,eps3 = SX.sym('eta'),SX.sym('eps1'),SX.sym('eps2'),SX.sym('eps3')
uq = vertcat(eta,eps1,eps2,eps3) #unit quaternion

deta = -0.5*(eps1*p + eps2*q + eps3*r)
deps1 = 0.5*(eta*p - eps3*q + eps2*r)
deps2 = 0.5*(eps3*p + eta*q - eps1*r)
deps3 = 0.5*(-eps2*p + eps1*q - eta*r)
duq = vertcat(deta,deps1,deps2,deps3) # differential unit quaternion
# deta = -0.5*(eps1*p + eps2*q + eps3*r)
# deps1 = 0.5*(eta*p - eps3*q + eps2*r)
# deps2 = 0.5*(eps3*p + eta*q - eps1*r)
# deps3 = 0.5*(-eps2*p + eps1*q - eta*r)
# duq = vertcat(deta,deps1,deps2,deps3) # differential unit quaternion

nq = vertcat(p_n, uq)
# dnq = vertcat(dp_n, uq)
###################################################


Expand Down

0 comments on commit 162868d

Please sign in to comment.