Skip to content

Commit d63c4c4

Browse files
committed
fix value error
1 parent 34831a4 commit d63c4c4

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

GEMstack/onboard/planning/reeds_shepp_parking.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def all_parking_spots_in_parking_lot(self,
204204
List of (x, y, yaw) poses for each parking spot.
205205
"""
206206
if len(static_horizontal_curb) != 2:
207+
return None
207208
raise ValueError("Exactly two curb endpoints are required.")
208209

209210
# Extract center points of the curb rectangles
@@ -225,6 +226,7 @@ def all_parking_spots_in_parking_lot(self,
225226
spacing = spot_length
226227

227228
if total_length < spot_length:
229+
return None
228230
raise ValueError("Insufficient curb length to place even one spot.")
229231

230232
# Number of full spots that can fit along the curb
@@ -398,6 +400,7 @@ def shift_points_perpendicular_ccw(self, p1, p2, shift_amount):
398400
# 2) Compute its magnitude |v|
399401
length = math.hypot(v_x, v_y)
400402
if length == 0:
403+
return None, None, None
401404
raise ValueError("p1 and p2 must be distinct points to define a direction.")
402405

403406
# 3) Normalize v to get unit direction v̂ = (v_x, v_y) / |v|
@@ -453,6 +456,7 @@ def project_point_on_axis(self, p1, p2, p3):
453456
dot_vv = v_x * v_x + v_y * v_y # v · v
454457

455458
if dot_vv == 0:
459+
return (None, None)
456460
raise ValueError("p1 and p2 must be distinct to define an axis.")
457461

458462
# Parameter t gives the position along the line: p_proj = p1 + t * v
@@ -486,6 +490,7 @@ def move_point_along_vector(self, p0, direction, step, positive_direction=True):
486490
# Compute the length of the direction vector
487491
length = math.hypot(dx, dy)
488492
if length == 0:
493+
print(None, None)
489494
raise ValueError("Direction vector must be non-zero to define a movement direction.")
490495

491496
# Normalize the direction vector to unit length
@@ -627,20 +632,28 @@ def find_available_parking_spots_and_search_vector(self, detected_cones=[], vehi
627632
self.parking_lot_axis_shift_margin
628633
)
629634

635+
if self.curb_0_xy_shifted is None:
636+
return
637+
630638
# Horizontal axis search direction
631639
_ , _, self.horizontal_search_axis_direction = self.shift_points_perpendicular_ccw(
632640
self.static_horizontal_curb_xy_coordinates[0],
633641
self.curb_0_xy_shifted,
634642
self.parking_lot_axis_shift_margin
635643
)
644+
645+
if self.horizontal_search_axis_direction is None:
646+
return
636647

637648
# Project vehicle pose onto the search axis
638649
self.vehicle_pose_proj = self.project_point_on_axis(
639650
self.curb_0_xy_shifted,
640651
self.curb_1_xy_shifted,
641652
self.vehicle_pose[0:2]
642653
)
643-
654+
655+
if self.vehicle_pose_proj is None:
656+
return
644657
# Compute bounds for the search axis
645658
self.upper_bound_xy = self.move_point_along_vector(
646659
self.curb_1_xy_shifted,
@@ -680,7 +693,9 @@ def find_collision_free_trajectory_to_park(self, detected_cones=[], vehicle_pose
680693
self.vehicle_pose[0:2]
681694
)
682695

683-
696+
if self.vehicle_pose_proj is None:
697+
return
698+
684699
while True:
685700
# Move projected pose along the search axis
686701
self.vehicle_pose_proj = self.move_point_along_vector(
@@ -751,7 +766,8 @@ def find_collision_free_trajectory_to_park(self, detected_cones=[], vehicle_pose
751766
# Use self.horizontal_search_axis_direction_var
752767
break # Give up in this direction
753768

754-
# If both directions fail
769+
# If both directions fail
770+
return
755771
raise ValueError("No collision-free trajectory available in either direction for parking.")
756772

757773

@@ -767,7 +783,9 @@ def find_collision_free_trajectory_to_unpark(self, detected_cones=[], vehicle_po
767783
self.curb_0_xy_shifted,
768784
self.curb_1_xy_shifted,
769785
self.vehicle_pose[0:2]
770-
)
786+
)
787+
if self.vehicle_pose_proj is None:
788+
return
771789

772790
# Move projected pose along the search axis
773791
self.vehicle_pose_proj = self.move_point_along_vector(
@@ -824,5 +842,6 @@ def find_collision_free_trajectory_to_unpark(self, detected_cones=[], vehicle_po
824842
if dist_to_upper_bound < self.search_bound_threshold or dist_to_lower_bound < self.search_bound_threshold:
825843
break # Give up in this direction
826844

827-
# If both directions fail
845+
# If both directions fail
846+
return
828847
raise ValueError("No collision-free trajectory available for unparking.")

0 commit comments

Comments
 (0)