1313class ReedsSheppParking :
1414 def __init__ (self , vehicle_pose = (0.0 , 0.0 , 0.0 ), vehicle_dims = (1.7 , 3.2 ), compact_parking_spot_size = (2.44 , 4.88 ),
1515 shift_from_center_to_rear_axis = 1.25 , search_step_size = 0.1 , closest = False , parking_lot_axis_shift_margin = 2.44 ,
16+ search_bound_threshold = 1.0 ,
1617 static_horizontal_curb_size = (2.44 , 0.5 ),
1718 static_horizontal_curb_xy_coordinates = [(0.0 , - 2.44 ),(24.9 , - 2.44 )],
1819 add_static_vertical_curb_as_obstacle = True ,
1920 static_vertical_curb_xy_coordinates = [(12.45 , - 4.88 )],
2021 static_vertical_curb_size = (2.44 , 24.9 ),
2122 add_static_horizontal_curb_as_obstacle = True ,
22- detected_cones = []):
23+ detected_cones = [],
24+ all_parking_spots_in_parking_lot = []):
2325
2426
2527 self .detected_cones = detected_cones
@@ -34,6 +36,8 @@ def __init__(self, vehicle_pose = (0.0, 0.0, 0.0), vehicle_dims = (1.7, 3.2), co
3436 self .static_vertical_curb_xy_coordinates = static_vertical_curb_xy_coordinates
3537 self .add_static_horizontal_curb_as_obstacle = add_static_horizontal_curb_as_obstacle
3638
39+ self .all_parking_spots_in_parking_lot = all_parking_spots_in_parking_lot
40+
3741 self .vehicle_pose = vehicle_pose
3842 self .x_axis_of_search = self .vehicle_pose [0 ]
3943
@@ -43,6 +47,7 @@ def __init__(self, vehicle_pose = (0.0, 0.0, 0.0), vehicle_dims = (1.7, 3.2), co
4347 self .shift_from_center_to_rear_axis = shift_from_center_to_rear_axis # TODO: Check
4448 self .search_step_size = search_step_size
4549 self .parking_lot_axis_shift_margin = parking_lot_axis_shift_margin
50+ self .search_bound_threshold = search_bound_threshold
4651 # TODO: Add thrid option: park in the middle
4752 self .closest = closest # If True, the closest parking spot will be selected, otherwise the farthest one will be selected
4853
@@ -185,7 +190,7 @@ def find_parking_positions(
185190
186191 return slots
187192
188- def all_parking_spots_in_parking_lot (static_horizontal_curb , compact_parking_spot_size , yaw_of_parked_cars = 0.0 , shift_from_center_to_rear_axis = 2.56 / 2 ):
193+ def all_parking_spots_in_parking_lot (static_horizontal_curb , compact_parking_spot_size , yaw_of_parked_cars = 0.0 ):
189194 if not static_horizontal_curb :
190195 raise ValueError ("No static horizontal curb provided." )
191196
@@ -232,7 +237,7 @@ def search_axis_direction(parking_spot_to_go, vehicle_pose):
232237 else :
233238 return False
234239
235- def available_parking_spots (all_parking_spots_in_parking_lot , parked_cars , compact_parking_spot_size , yaw_of_parked_cars = 0.0 , shift_from_center_to_rear_axis = 2.56 / 2 ):
240+ def available_parking_spots (all_parking_spots_in_parking_lot , parked_cars , compact_parking_spot_size , yaw_of_parked_cars = 0.0 ):
236241 available_parking_spots = []
237242 for spot in all_parking_spots_in_parking_lot :
238243 # Check if the parking spot is occupied by a parked car
@@ -387,14 +392,8 @@ def move_point_along_vector(p0, direction, step=0.1, positive_direction=True):
387392
388393
389394
395+ def find_available_parking_spots_and_search_vector (self , detected_cones = [], vehicle_pose = (0.0 , 0.0 , 0.0 ), update_pose = False ):
390396
391-
392-
393-
394-
395-
396- def find_collision_free_trajectory (self , detected_cones = [], vehicle_pose = (0.0 , 0.0 , 0.0 ), update_pose = False ):
397-
398397 # Update detected cones
399398 self .detected_cones = detected_cones
400399
@@ -429,44 +428,67 @@ def find_collision_free_trajectory(self, detected_cones = [], vehicle_pose = (0.
429428 if self .add_static_vertical_curb_as_obstacle :
430429 self .objects_to_avoid_collisions += self .static_vertical_curb
431430
432- # Compute coordinates of parking spots in the parking lot defined by the static horizontal curb
433- self .all_parking_spots_in_parking_lot = ReedsSheppParking .all_parking_spots_in_parking_lot (
434- self .static_horizontal_curb , self .compact_parking_spot_size , yaw_of_parked_cars = self .yaw_of_parked_cars ,
435- shift_from_center_to_rear_axis = self .shift_from_center_to_rear_axis
436- )
437-
431+ # If all the parked cars are not provided, we need to compute the available parking spots
432+ if self .all_parking_spots_in_parking_lot == []:
433+ # Compute coordinates of parking spots in the parking lot defined by the static horizontal curb
434+ self .all_parking_spots_in_parking_lot = ReedsSheppParking .all_parking_spots_in_parking_lot (
435+ self .static_horizontal_curb , self .compact_parking_spot_size , yaw_of_parked_cars = self .yaw_of_parked_cars
436+ )
437+
438438 # Compute the available parking spots in the parking lot
439439 self .available_parking_spots = ReedsSheppParking .available_parking_spots (
440440 self .all_parking_spots_in_parking_lot , self .parked_cars , self .compact_parking_spot_size ,
441- yaw_of_parked_cars = 0.0 , shift_from_center_to_rear_axis = self . shift_from_center_to_rear_axis
441+ yaw_of_parked_cars = 0.0
442442 )
443443
444-
444+ # Check if there are available parking spots
445+ if len (self .available_parking_spots ) == 0 :
446+ raise ValueError ("No parking spot available." )
445447
446448 self .parking_spot_to_go = [ReedsSheppParking .pick_parking_spot (self .available_parking_spots , 0.0 , 0.0 , yaw = 0.0 , closest = self .closest )]
449+ #TODO: Shift according to yaw direction
447450 x_shift = self .parking_spot_to_go [0 ][0 ] - self .shift_from_center_to_rear_axis
448451 self .parking_spot_to_go [0 ] = (x_shift , self .parking_spot_to_go [0 ][1 ], self .parking_spot_to_go [0 ][2 ])
449452 self .x_axis_of_search_direction_positive = ReedsSheppParking .search_axis_direction (self .parking_spot_to_go , self .vehicle_pose )
450453
451454
452455
453456 # Compute axis of search
454- curb_0_xy_shifted , curb_1_xy_shifted , new_axis_direction = ReedsSheppParking .shift_points_perpendicular_ccw (self .static_horizontal_curb_xy_coordinates [0 ],
457+ self . curb_0_xy_shifted , self . curb_1_xy_shifted , self . new_axis_direction = ReedsSheppParking .shift_points_perpendicular_ccw (self .static_horizontal_curb_xy_coordinates [0 ],
455458 self .static_horizontal_curb_xy_coordinates [1 ],
456459 self .parking_lot_axis_shift_margin )
457460
458461 # Compute the projected point on the axis of search
459- vehicle_pose_proj = ReedsSheppParking .project_point_on_axis (curb_0_xy_shifted , curb_1_xy_shifted , self .vehicle_pose [0 :2 ])
462+ self .vehicle_pose_proj = ReedsSheppParking .project_point_on_axis (self .curb_0_xy_shifted , self .curb_1_xy_shifted , self .vehicle_pose [0 :2 ])
463+
464+ # Compute the upper and lower bounds on the axis of search
465+ self .upper_bound_xy = ReedsSheppParking .move_point_along_vector (self .curb_1_xy_shifted , self .new_axis_direction ,
466+ step = 2 * self .compact_parking_spot_size [1 ],
467+ positive_direction = True )
468+ self .lower_bound_xy = ReedsSheppParking .move_point_along_vector (self .curb_0_xy_shifted , self .new_axis_direction ,
469+ step = 2 * self .compact_parking_spot_size [1 ],
470+ positive_direction = False )
460471
461472
473+
474+ def find_collision_free_trajectory (self , detected_cones = [], vehicle_pose = (0.0 , 0.0 , 0.0 ), update_pose = False ):
475+
476+ # Update detected cones
477+ self .detected_cones = detected_cones
478+
479+ # Update vehicle pose
480+ if update_pose :
481+ self .vehicle_pose = vehicle_pose
482+
462483 while True :
463484
464- vehicle_pose_proj = ReedsSheppParking .move_point_along_vector (vehicle_pose_proj , new_axis_direction ,
485+ self . vehicle_pose_proj = ReedsSheppParking .move_point_along_vector (self . vehicle_pose_proj , self . new_axis_direction ,
465486 step = self .search_step_size ,
466487 positive_direction = self .x_axis_of_search_direction_positive )
467488
468- waypoints = ReedsSheppParking .reeds_shepp_path (self .vehicle_pose , (vehicle_pose_proj [0 ], vehicle_pose_proj [1 ], self .yaw_of_parked_cars ))
469- waypoints2 = ReedsSheppParking .reeds_shepp_path ((vehicle_pose_proj [0 ], vehicle_pose_proj [1 ], self .yaw_of_parked_cars ), self .parking_spot_to_go [0 ])
489+ #TODO: Shift according to yaw direction
490+ waypoints = ReedsSheppParking .reeds_shepp_path (self .vehicle_pose , (self .vehicle_pose_proj [0 ]- self .shift_from_center_to_rear_axis , self .vehicle_pose_proj [1 ], self .yaw_of_parked_cars ), step_size = self .search_step_size )
491+ waypoints2 = ReedsSheppParking .reeds_shepp_path ((self .vehicle_pose_proj [0 ]- self .shift_from_center_to_rear_axis , self .vehicle_pose_proj [1 ], self .yaw_of_parked_cars ), self .parking_spot_to_go [0 ], step_size = self .search_step_size )
470492
471493 self .waypoints_for_obstacles_check = waypoints + waypoints2
472494 self .waypoints_to_go = np .array (self .waypoints_for_obstacles_check )[:, :2 ]
@@ -477,14 +499,11 @@ def find_collision_free_trajectory(self, detected_cones = [], vehicle_pose = (0.
477499 self .objects_to_avoid_collisions ):
478500 break
479501
480-
481-
482-
483- # if self.x_axis_of_search_direction_positive:
484- # self.x_axis_of_search += self.search_step_size
485- # if self.x_axis_of_search > self.static_horizontal_curb[1][0] + self.compact_parking_spot_size[1]:
486- # raise ValueError("No parking spot available.")
487- # else:
488- # self.x_axis_of_search -= self.search_step_size
489- # if self.x_axis_of_search < self.static_horizontal_curb[0][0] - self.compact_parking_spot_size[1]:
490- # raise ValueError("No parking spot available.")
502+ # Stop searching if out of bounds
503+ if self .x_axis_of_search_direction_positive :
504+ if np .linalg .norm (np .array (self .vehicle_pose_proj ) - np .array (self .upper_bound_xy )) < self .search_bound_threshold :
505+ raise ValueError ("No collision free trajectory available within bounds." )
506+ else :
507+ if np .linalg .norm (np .array (self .vehicle_pose_proj ) - np .array (self .lower_bound_xy )) < self .search_bound_threshold :
508+ raise ValueError ("No collision free trajectory available within bounds." )
509+
0 commit comments