11import numpy as np
22import yaml
33from acados_template import AcadosOcp , AcadosOcpSolver , AcadosModel
4- from casadi import evalf , SX , mtimes , pinv , vertcat , hessian , Function , jacobian , dot , fmin , fmax , sumsqr , cos , sin , pi
4+ from casadi import (
5+ evalf ,
6+ SX ,
7+ mtimes ,
8+ pinv ,
9+ vertcat ,
10+ Function ,
11+ jacobian ,
12+ dot ,
13+ fmin ,
14+ fmax ,
15+ sumsqr ,
16+ cos ,
17+ sin ,
18+ pi ,
19+ )
520from scipy .linalg import block_diag
621import sys
722
@@ -178,13 +193,17 @@ def frustum_barrier(
178193
179194 Args:
180195 x (ca.MX): The AUV's current state vector (12x1).
181- xr (ca.MX): The AUV's reference state vector (12x1), including target position and orientation.
196+ xr (ca.MX): The AUV's reference state vector (12x1), including
197+ target position and orientation.
198+
182199 p_start (ca.MX): The start point of the frustum's axis (3x1).
183200 start_radius (float): The radius of the corridor at the start point.
184201 end_radius (float): The radius of the corridor at the end point.
185- orientation_weight (float): Tuning parameter to scale the orientation constraint's importance.
186- max_align_angle_rad (float): The maximum allowed angle (in radians) between the AUV's
187- forward vector and the target's forward vector.
202+ orientation_weight (float): Tuning parameter to scale the orientation
203+ constraint's importance.
204+
205+ max_align_angle_rad (float): The maximum allowed angle (in radians)
206+ between the AUV's forward vector and the target's forward vector.
188207
189208 Returns:
190209 ca.MX: The value of the combined barrier function.
@@ -203,7 +222,7 @@ def frustum_barrier(
203222
204223 # --- 2. Orientation Barrier (Aligns AUV frame with Target frame) ---
205224 # AUV's current orientation
206- phi_auv , theta_auv , psi_auv = x [3 ], x [4 ], x [5 ]
225+ _ , theta_auv , psi_auv = x [3 ], x [4 ], x [5 ]
207226
208227 # AUV's forward vector (body x-axis) in the world frame
209228 v_auv_x = cos (psi_auv ) * cos (theta_auv )
@@ -212,7 +231,7 @@ def frustum_barrier(
212231 v_auv = vertcat (v_auv_x , v_auv_y , v_auv_z )
213232
214233 # Target's orientation from the reference state
215- phi_target , theta_target , psi_target = xr [3 ], xr [4 ], xr [5 ]
234+ _ , theta_target , psi_target = xr [3 ], xr [4 ], xr [5 ]
216235
217236 # Target's forward vector (body x-axis) in the world frame
218237 v_target_orient_x = cos (psi_target ) * cos (theta_target )
@@ -228,8 +247,9 @@ def frustum_barrier(
228247 # The cosine of the maximum allowed alignment angle
229248 cos_max_angle = cos (max_align_angle_rad )
230249
231- # The orientation barrier is positive when the frames are aligned within the allowed cone
232- b_orientation = cos_angle_error - cos_max_angle
250+ # The orientation barrier is positive when the frames are aligned within the
251+ # allowed cone
252+ cos_angle_error - cos_max_angle
233253
234254 # --- 3. Combined Barrier ---
235255 b_combined = b_position # + orientation_weight * b_orientation
@@ -259,7 +279,8 @@ def tube_barrier(x, p_start, p_end, tube_radius):
259279
260280 # Calculate the projection parameter 't'.
261281 # This determines the closest point on the infinite line.
262- # Add a small epsilon to prevent division by zero if start and end points are the same.
282+ # Add a small epsilon to prevent division by zero if start and end
283+ # points are the same.
263284 t = dot (w , v ) / (dot (v , v ) + 1e-9 )
264285
265286 # Clamp 't' to the range [0, 1] to stay on the line *segment*.
@@ -363,8 +384,8 @@ def create_ocp_solver_description(self):
363384 self .acados_ocp .dims .N = self .horizon
364385 self .acados_ocp .parameter_values = np .zeros (2 * self .vehicle_state_dim )
365386
366- xr = self .acados_model .p [0 : self .vehicle_state_dim ]
367- residual = self .acados_model .p [self .vehicle_state_dim :]
387+ xr = self .acados_model .p [0 : self .vehicle_state_dim ]
388+ residual = self .acados_model .p [self .vehicle_state_dim :]
368389
369390 self .acados_ocp .cost .cost_type = "NONLINEAR_LS"
370391 self .acados_ocp .cost .cost_type_e = "NONLINEAR_LS"
@@ -433,7 +454,7 @@ def optimize(self, x, x_ref, residual):
433454 x0 = x [0 :12 , :]
434455 N = self .horizon
435456
436- nx = self .acados_ocp .model .x .shape [0 ]
457+ self .acados_ocp .model .x .shape [0 ]
437458 nu = self .acados_ocp .model .u .shape [0 ]
438459
439460 # set initial state constraint
0 commit comments