Skip to content

Commit 3fd665a

Browse files
committed
Basic adjustments
1 parent 87b4973 commit 3fd665a

2 files changed

Lines changed: 77 additions & 43 deletions

File tree

GEMstack/onboard/planning/parallel_parking.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,31 @@ def __init__(self, routefn: str, vehicle_interface: GEMInterface, frame: str = '
3030
else:
3131
raise ValueError("Unknown route file extension", ext)
3232

33-
# SLOT 4 (17.33, -2.44, 0.0, (1.7, 3.2))
34-
# SLOT 5 (22.11, -2.44, 0.0, (1.7, 3.2))
35-
self.parked_cars = [
33+
# SLOT 1 (2.69, -2.44), SLOT 2 (7.47, -2.44)
34+
# SLOT 3 (12.25, -2.44), SLOT 4 (17.33, -2.44)
35+
# SLOT 5 (22.11, -2.44)
3636

37+
self.parked_cars = [
38+
39+
(7.47, -2.44),
40+
(12.25, -2.44),
3741
(17.33, -2.44),
38-
(22.11, -2.44)
42+
(22.11, -2.44)
43+
3944
]
40-
self.parking_utils = ReedsSheppParking()
41-
self.parking_utils.closest = False
42-
self.parking_utils.find_collision_free_trajectory(self.parked_cars)
45+
self.all_parking_spots_in_parking_lot = [
46+
(3.94, -2.44, 0.0, (2.44, 4.88)),
47+
(7.47, -2.44, 0.0, (2.44, 4.88)),
48+
(12.25, -2.44, 0.0, (2.44, 4.88)),
49+
(17.33, -2.44, 0.0, (2.44, 4.88)),
50+
(22.11, -2.44, 0.0,(2.44, 4.88))
51+
]
52+
self.reedssheppparking = ReedsSheppParking()
53+
self.reedssheppparking.closest = False
54+
self.reedssheppparking.all_parking_spots_in_parking_lot = self.all_parking_spots_in_parking_lot
55+
self.reedssheppparking.find_available_parking_spots_and_search_vector(self.parked_cars)
56+
self.reedssheppparking.find_collision_free_trajectory(self.parked_cars)
57+
4358

4459

4560

@@ -54,7 +69,7 @@ def rate(self):
5469

5570
def update(self, vehicle: VehicleState, x=0.0):
5671
self.current_pose = vehicle.pose
57-
self.waypoints_to_go = self.parking_utils.waypoints_to_go
58-
self.parking_utils.find_collision_free_trajectory(self.parked_cars)
72+
#self.reedssheppparking.find_collision_free_trajectory(self.parked_cars)
73+
self.waypoints_to_go = self.reedssheppparking.waypoints_to_go
5974
self.route = Route(frame=ObjectFrameEnum.START, points=self.waypoints_to_go.tolist())
6075
return self.route

GEMstack/onboard/planning/reeds_shepp_parking.py

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
class 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

Comments
 (0)