@@ -46,11 +46,11 @@ def __init__(self):
46
46
self .declare_parameter ('update_rate' , 10.0 )
47
47
update_rate = self .get_parameter ('update_rate' ).value
48
48
self .update_period = 1.0 / update_rate
49
-
49
+
50
50
self .waiting_at_waypoint = False
51
51
self .wait_cycles = int (1.0 / self .update_period )
52
52
self .wait_count = 0
53
- self .y_int = 0.0
53
+ self .y_int = 0.0
54
54
55
55
# Initialize filter status flag
56
56
self .filter_initialized = False
@@ -221,40 +221,44 @@ def twist_callback(self, msg: TwistWithCovarianceStamped):
221
221
self .state .twist = twist_from_ros (msg .twist .twist )
222
222
223
223
def calculate_guidance (self ) -> State :
224
- error = self .guidance_calculator .state_as_pos_array (self .state - self .waypoints [self .current_waypoint_index ])
224
+ error = self .guidance_calculator .state_as_pos_array (
225
+ self .state - self .waypoints [self .current_waypoint_index ]
226
+ )
225
227
_ , crosstrack_y , crosstrack_z = self .rotation_yz @ error
226
-
228
+
227
229
alpha_c = self .guidance_calculator .calculate_alpha_c (
228
230
self .state .twist .linear_x ,
229
- self .state .twist .linear_y ,
231
+ self .state .twist .linear_y ,
230
232
self .state .twist .linear_z ,
231
- self .state .pose .pitch
233
+ self .state .pose .pitch ,
232
234
)
233
-
235
+
234
236
beta_c = self .guidance_calculator .calculate_beta_c (
235
237
self .state .twist .linear_x ,
236
238
self .state .twist .linear_y ,
237
239
self .state .twist .linear_z ,
238
240
self .state .pose .roll ,
239
241
self .state .pose .pitch ,
240
- alpha_c
242
+ alpha_c ,
241
243
)
242
-
244
+
243
245
psi_d = self .guidance_calculator .compute_psi_d (
244
246
self .waypoints [self .current_waypoint_index ],
245
247
self .waypoints [self .current_waypoint_index + 1 ],
246
248
crosstrack_y ,
247
- self .y_int
249
+ self .y_int ,
250
+ )
251
+
252
+ y_int_dot = self .guidance_calculator .calculate_y_int_dot (
253
+ crosstrack_y , self .y_int
248
254
)
249
-
250
- y_int_dot = self .guidance_calculator .calculate_y_int_dot (crosstrack_y , self .y_int )
251
255
self .y_int += y_int_dot * self .update_period
252
-
256
+
253
257
theta_d = self .guidance_calculator .compute_theta_d (
254
258
self .waypoints [self .current_waypoint_index ],
255
259
self .waypoints [self .current_waypoint_index + 1 ],
256
260
crosstrack_z ,
257
- alpha_c
261
+ alpha_c ,
258
262
)
259
263
260
264
yaw_error = ssa (psi_d - self .state .pose .yaw )
@@ -266,15 +270,17 @@ def calculate_guidance(self) -> State:
266
270
unfiltered_commands .twist .linear_x = desired_surge
267
271
unfiltered_commands .pose .pitch = theta_d
268
272
unfiltered_commands .pose .yaw = psi_d
269
-
270
- filtered_commands = self .guidance_calculator .apply_reference_filter (unfiltered_commands )
273
+
274
+ filtered_commands = self .guidance_calculator .apply_reference_filter (
275
+ unfiltered_commands
276
+ )
271
277
return filtered_commands
272
278
273
279
def execute_callback (self , goal_handle : ServerGoalHandle ):
274
280
"""Execute waypoint navigation action."""
275
281
with self ._goal_lock :
276
282
self .goal_handle = goal_handle
277
-
283
+
278
284
self .current_waypoint_index = 0
279
285
self .waypoints = [self .state ]
280
286
for waypoint in goal_handle .request .waypoints :
@@ -296,7 +302,9 @@ def execute_callback(self, goal_handle: ServerGoalHandle):
296
302
self .rotation_yz = rotation_y .T @ rotation_z .T
297
303
298
304
# Initialize integral control
299
- initial_error = self .guidance_calculator .state_as_pos_array (self .state - self .waypoints [self .current_waypoint_index ])
305
+ initial_error = self .guidance_calculator .state_as_pos_array (
306
+ self .state - self .waypoints [self .current_waypoint_index ]
307
+ )
300
308
_ , initial_crosstrack_y , _ = self .rotation_yz @ initial_error
301
309
self .y_int = - initial_crosstrack_y / self .guidance_calculator .kappa
302
310
@@ -343,7 +351,9 @@ def execute_callback(self, goal_handle: ServerGoalHandle):
343
351
else :
344
352
self .current_waypoint_index += 1
345
353
# Reset integral term for new waypoint
346
- initial_error = self .guidance_calculator .state_as_pos_array (self .state - self .waypoints [self .current_waypoint_index ])
354
+ initial_error = self .guidance_calculator .state_as_pos_array (
355
+ self .state - self .waypoints [self .current_waypoint_index ]
356
+ )
347
357
_ , initial_crosstrack_y , _ = self .rotation_yz @ initial_error
348
358
self .y_int = - initial_crosstrack_y / self .guidance_calculator .kappa
349
359
waiting_at_waypoint = False
0 commit comments