@@ -136,7 +136,6 @@ def _declare_topic_parameters(self):
136
136
137
137
def _initialize_publishers (self ):
138
138
"""Initialize all publishers."""
139
-
140
139
los_commands_topic = self .get_parameter ('topics.publishers.los_commands' ).value
141
140
self .get_logger ().info (f"Publishing LOS commands to: { los_commands_topic } " )
142
141
self .guidance_cmd_pub = self .create_publisher (
@@ -221,24 +220,39 @@ def odom_callback(self, msg: Odometry):
221
220
self .filter_initialized = True
222
221
223
222
def calculate_guidance (self ) -> State :
224
- error = self .state .as_pos_array () - self .waypoints [self .current_waypoint_index ].as_pos_array ()
223
+ error = (
224
+ self .state .as_pos_array ()
225
+ - self .waypoints [self .current_waypoint_index ].as_pos_array ()
226
+ )
225
227
_ , crosstrack_y , crosstrack_z = self .rotation_yz @ error
226
- alpha_c = self .guidance_calculator .calculate_alpha_c (self .u , self .v , self .w , self .phi )
227
- beta_c = self .guidance_calculator .calculate_beta_c (self .u , self .v , self .w , self .phi , self .pitch , alpha_c )
228
- psi_d = self .guidance_calculator .compute_psi_d (self .waypoints [self .current_waypoint_index ],
229
- self .waypoints [self .current_waypoint_index + 1 ],
230
- crosstrack_y , beta_c )
231
- theta_d = self .guidance_calculator .compute_theta_d (self .waypoints [self .current_waypoint_index ],
232
- self .waypoints [self .current_waypoint_index + 1 ],
233
- crosstrack_z , alpha_c )
234
- unfiltered_commands = State (surge_vel = self .desired_vel , pitch = theta_d , yaw = psi_d )
235
- filtered_commands = self .guidance_calculator .apply_reference_filter (unfiltered_commands )
228
+ alpha_c = self .guidance_calculator .calculate_alpha_c (
229
+ self .u , self .v , self .w , self .phi
230
+ )
231
+ beta_c = self .guidance_calculator .calculate_beta_c (
232
+ self .u , self .v , self .w , self .phi , self .pitch , alpha_c
233
+ )
234
+ psi_d = self .guidance_calculator .compute_psi_d (
235
+ self .waypoints [self .current_waypoint_index ],
236
+ self .waypoints [self .current_waypoint_index + 1 ],
237
+ crosstrack_y ,
238
+ beta_c ,
239
+ )
240
+ theta_d = self .guidance_calculator .compute_theta_d (
241
+ self .waypoints [self .current_waypoint_index ],
242
+ self .waypoints [self .current_waypoint_index + 1 ],
243
+ crosstrack_z ,
244
+ alpha_c ,
245
+ )
246
+ unfiltered_commands = State (
247
+ surge_vel = self .desired_vel , pitch = theta_d , yaw = psi_d
248
+ )
249
+ filtered_commands = self .guidance_calculator .apply_reference_filter (
250
+ unfiltered_commands
251
+ )
236
252
return unfiltered_commands
237
253
238
-
239
254
def execute_callback (self , goal_handle : ServerGoalHandle ):
240
255
"""Execute waypoint navigation action."""
241
-
242
256
# Initialize navigation goal with lock
243
257
with self ._goal_lock :
244
258
self .goal_handle = goal_handle
@@ -253,8 +267,14 @@ def execute_callback(self, goal_handle: ServerGoalHandle):
253
267
)
254
268
self .waypoints .append (point_as_state )
255
269
256
- self .pi_h = self .guidance_calculator .compute_pi_h (self .waypoints [self .current_waypoint_index ], self .waypoints [self .current_waypoint_index + 1 ])
257
- self .pi_v = self .guidance_calculator .compute_pi_v (self .waypoints [self .current_waypoint_index ], self .waypoints [self .current_waypoint_index + 1 ])
270
+ self .pi_h = self .guidance_calculator .compute_pi_h (
271
+ self .waypoints [self .current_waypoint_index ],
272
+ self .waypoints [self .current_waypoint_index + 1 ],
273
+ )
274
+ self .pi_v = self .guidance_calculator .compute_pi_v (
275
+ self .waypoints [self .current_waypoint_index ],
276
+ self .waypoints [self .current_waypoint_index + 1 ],
277
+ )
258
278
259
279
rotation_y = self .guidance_calculator .compute_rotation_y (self .pi_v )
260
280
rotation_z = self .guidance_calculator .compute_rotation_z (self .pi_h )
@@ -280,22 +300,34 @@ def execute_callback(self, goal_handle: ServerGoalHandle):
280
300
self .goal_handle = None
281
301
result .success = False
282
302
return result
283
-
284
- norm = np .linalg .norm (self .state .as_pos_array () - self .waypoints [self .current_waypoint_index + 1 ].as_pos_array (), 2 )
303
+
304
+ norm = np .linalg .norm (
305
+ self .state .as_pos_array ()
306
+ - self .waypoints [self .current_waypoint_index + 1 ].as_pos_array (),
307
+ 2 ,
308
+ )
285
309
if norm < 0.5 :
286
310
self .get_logger ().info ('Waypoint reached' )
287
311
self .current_waypoint_index += 1
288
312
289
313
if self .current_waypoint_index >= len (self .waypoints ) - 1 :
290
314
self .get_logger ().info ('All waypoints reached!' )
291
- final_commands = State (surge_vel = 0.0 , pitch = self .state .pitch , yaw = self .state .yaw )
315
+ final_commands = State (
316
+ surge_vel = 0.0 , pitch = self .state .pitch , yaw = self .state .yaw
317
+ )
292
318
self .publish_guidance (final_commands )
293
319
result .success = True
294
320
self .goal_handle .succeed ()
295
321
return result
296
-
297
- self .pi_h = self .guidance_calculator .compute_pi_h (self .waypoints [self .current_waypoint_index ], self .waypoints [self .current_waypoint_index + 1 ])
298
- self .pi_v = self .guidance_calculator .compute_pi_v (self .waypoints [self .current_waypoint_index ], self .waypoints [self .current_waypoint_index + 1 ])
322
+
323
+ self .pi_h = self .guidance_calculator .compute_pi_h (
324
+ self .waypoints [self .current_waypoint_index ],
325
+ self .waypoints [self .current_waypoint_index + 1 ],
326
+ )
327
+ self .pi_v = self .guidance_calculator .compute_pi_v (
328
+ self .waypoints [self .current_waypoint_index ],
329
+ self .waypoints [self .current_waypoint_index + 1 ],
330
+ )
299
331
300
332
rotation_y = self .guidance_calculator .compute_rotation_y (self .pi_v )
301
333
rotation_z = self .guidance_calculator .compute_rotation_z (self .pi_h )
@@ -314,6 +346,7 @@ def publish_guidance(self, commands: State):
314
346
msg .yaw = commands .yaw
315
347
self .guidance_cmd_pub .publish (msg )
316
348
349
+
317
350
def main (args = None ):
318
351
"""Main function to initialize and run the guidance node."""
319
352
rclpy .init (args = args )
@@ -332,4 +365,4 @@ def main(args=None):
332
365
333
366
334
367
if __name__ == '__main__' :
335
- main ()
368
+ main ()
0 commit comments