Skip to content

Commit c11a072

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 4dad7df commit c11a072

File tree

2 files changed

+54
-28
lines changed

2 files changed

+54
-28
lines changed

guidance/guidance_los/guidance_los/los_guidance_algorithm.py

+25-9
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,22 @@ def compute_pitch_command(
113113
self.los_params.max_pitch_angle,
114114
)
115115

116-
def compute_desired_speed(self, yaw_error: float, distance_to_target: float, crosstrack_y: float) -> float:
117-
"""
118-
Compute speed command with yaw error, distance and crosstrack-based scaling.
116+
def compute_desired_speed(
117+
self, yaw_error: float, distance_to_target: float, crosstrack_y: float
118+
) -> float:
119+
"""Compute speed command with yaw error, distance and crosstrack-based scaling.
119120
"""
120121
yaw_factor = np.cos(yaw_error)
121-
distance_factor = min(1.0, distance_to_target / self.los_params.lookahead_distance_max)
122+
distance_factor = min(
123+
1.0, distance_to_target / self.los_params.lookahead_distance_max
124+
)
122125
crosstrack_factor = 1.0 / (1.0 + abs(crosstrack_y))
123-
desired_speed = self.los_params.nominal_speed * yaw_factor * distance_factor * crosstrack_factor
126+
desired_speed = (
127+
self.los_params.nominal_speed
128+
* yaw_factor
129+
* distance_factor
130+
* crosstrack_factor
131+
)
124132
return max(self.los_params.min_speed, desired_speed)
125133

126134
def apply_reference_filter(self, commands: State) -> State:
@@ -217,15 +225,23 @@ def compute_theta_d(
217225
return theta_d
218226

219227
def calculate_y_int_dot(self, crosstrack_y, y_int):
220-
y_int_dot = (self.lookahead_h * crosstrack_y) / (self.lookahead_h**2 + (crosstrack_y + self.kappa * y_int)**2)
228+
y_int_dot = (self.lookahead_h * crosstrack_y) / (
229+
self.lookahead_h**2 + (crosstrack_y + self.kappa * y_int) ** 2
230+
)
221231
return y_int_dot
222-
223-
def compute_psi_d(self, current_waypoint: State, next_waypoint: State, crosstrack_y: float, y_int: float) -> float:
232+
233+
def compute_psi_d(
234+
self,
235+
current_waypoint: State,
236+
next_waypoint: State,
237+
crosstrack_y: float,
238+
y_int: float,
239+
) -> float:
224240
pi_h = self.compute_pi_h(current_waypoint, next_waypoint)
225241
psi_d = pi_h - np.arctan((crosstrack_y + self.kappa) / self.lookahead_h)
226242
psi_d = self.ssa(psi_d)
227243
return psi_d
228-
244+
229245
@staticmethod
230246
def calculate_alpha_c(u: float, v: float, w: float, phi: float) -> float:
231247
if u == 0:

guidance/guidance_los/scripts/los_guidance_action_server.py

+29-19
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def __init__(self):
4646
self.declare_parameter('update_rate', 10.0)
4747
update_rate = self.get_parameter('update_rate').value
4848
self.update_period = 1.0 / update_rate
49-
49+
5050
self.waiting_at_waypoint = False
5151
self.wait_cycles = int(1.0 / self.update_period)
5252
self.wait_count = 0
53-
self.y_int = 0.0
53+
self.y_int = 0.0
5454

5555
# Initialize filter status flag
5656
self.filter_initialized = False
@@ -221,40 +221,44 @@ def twist_callback(self, msg: TwistWithCovarianceStamped):
221221
self.state.twist = twist_from_ros(msg.twist.twist)
222222

223223
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+
)
225227
_, crosstrack_y, crosstrack_z = self.rotation_yz @ error
226-
228+
227229
alpha_c = self.guidance_calculator.calculate_alpha_c(
228230
self.state.twist.linear_x,
229-
self.state.twist.linear_y,
231+
self.state.twist.linear_y,
230232
self.state.twist.linear_z,
231-
self.state.pose.pitch
233+
self.state.pose.pitch,
232234
)
233-
235+
234236
beta_c = self.guidance_calculator.calculate_beta_c(
235237
self.state.twist.linear_x,
236238
self.state.twist.linear_y,
237239
self.state.twist.linear_z,
238240
self.state.pose.roll,
239241
self.state.pose.pitch,
240-
alpha_c
242+
alpha_c,
241243
)
242-
244+
243245
psi_d = self.guidance_calculator.compute_psi_d(
244246
self.waypoints[self.current_waypoint_index],
245247
self.waypoints[self.current_waypoint_index + 1],
246248
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
248254
)
249-
250-
y_int_dot = self.guidance_calculator.calculate_y_int_dot(crosstrack_y, self.y_int)
251255
self.y_int += y_int_dot * self.update_period
252-
256+
253257
theta_d = self.guidance_calculator.compute_theta_d(
254258
self.waypoints[self.current_waypoint_index],
255259
self.waypoints[self.current_waypoint_index + 1],
256260
crosstrack_z,
257-
alpha_c
261+
alpha_c,
258262
)
259263

260264
yaw_error = ssa(psi_d - self.state.pose.yaw)
@@ -266,15 +270,17 @@ def calculate_guidance(self) -> State:
266270
unfiltered_commands.twist.linear_x = desired_surge
267271
unfiltered_commands.pose.pitch = theta_d
268272
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+
)
271277
return filtered_commands
272278

273279
def execute_callback(self, goal_handle: ServerGoalHandle):
274280
"""Execute waypoint navigation action."""
275281
with self._goal_lock:
276282
self.goal_handle = goal_handle
277-
283+
278284
self.current_waypoint_index = 0
279285
self.waypoints = [self.state]
280286
for waypoint in goal_handle.request.waypoints:
@@ -296,7 +302,9 @@ def execute_callback(self, goal_handle: ServerGoalHandle):
296302
self.rotation_yz = rotation_y.T @ rotation_z.T
297303

298304
# 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+
)
300308
_, initial_crosstrack_y, _ = self.rotation_yz @ initial_error
301309
self.y_int = -initial_crosstrack_y / self.guidance_calculator.kappa
302310

@@ -343,7 +351,9 @@ def execute_callback(self, goal_handle: ServerGoalHandle):
343351
else:
344352
self.current_waypoint_index += 1
345353
# 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+
)
347357
_, initial_crosstrack_y, _ = self.rotation_yz @ initial_error
348358
self.y_int = -initial_crosstrack_y / self.guidance_calculator.kappa
349359
waiting_at_waypoint = False

0 commit comments

Comments
 (0)