33from typing import List , Dict
44
55import numpy as np
6- from scipy .optimize import minimize_scalar
76
8- DEBUG = True # Set to False to disable debug output
7+
8+ DEBUG = True # Set to False to disable debug output
9+
10+ """ Vehicle Configuration """
911GEM_MODEL = 'e4' # e2 or e4
1012buffer_x , buffer_y = 3 , 1
11- # """ Vehicle Dimensions """
1213if GEM_MODEL == 'e2' :
1314 # e2 axle dimensions, refer to GEMstack/knowledge/vehicle/model/gem_e2.urdf
1415 size_x , size_y = 2.53 , 1.35 # measured from base_link.STL
@@ -39,7 +40,7 @@ class PedestrianYielder(Component):
3940 """
4041
4142 def rate (self ):
42- return 4.0
43+ return None
4344
4445 def state_inputs (self ):
4546 return ['agents' , 'vehicle' ]
@@ -60,7 +61,7 @@ def update(self, agents: Dict[str, AgentState], vehicle: VehicleState) -> List[E
6061 check , t_min , min_dist , pt_min = check_collision_in_vehicle_frame (a , vehicle )
6162 if DEBUG :
6263 print (
63- f"[DEBUG] ID: { n } \t relation :{ check } , minimum distance:{ min_dist } , time to min_dist: { t_min } , point of min_dist:{ pt_min } " )
64+ f"[DEBUG] ID { n } , relation :{ check } , minimum distance:{ min_dist } , time to min_dist: { t_min } , point of min_dist:{ pt_min } " )
6465 # collision may occur, slow down
6566 if check == 'YIELD' :
6667 res .append (EntityRelation (type = EntityRelationEnum .YIELDING , obj1 = '' , obj2 = n ))
@@ -238,7 +239,8 @@ def point_dist(x1, y1, x2, y2):
238239 return t_min , min_dist , pt_min
239240
240241
241- # def find_min_distance_and_time(xp, yp, vx, vy, buffer, time_scale):
242+ # def find_min_distance_and_time_by_optimizer(xp, yp, vx, vy, buffer, time_scale):
243+ # from scipy.optimize import minimize_scalar
242244# def pos_t(t):
243245# xt, yt = xp + vx * t, yp + vy * t
244246# return shortest_distance_to_buffer_in_vehicle_frame((xt, yt), buffer)
@@ -252,52 +254,8 @@ def point_dist(x1, y1, x2, y2):
252254# return None, None
253255
254256
255- # # Calculate the shortest distance from an object to vehicle buffer area in vehicle frame
256- # def shortest_distance_to_buffer_in_vehicle_frame(position, buffer):
257- # """
258- # Calculate the distance between a pedestrian's position and the vehicle with buffer
259- # """
260- # x_buff, y_buff = buffer
261- # # consider 2D geometry
262- # x_p, y_p = position
263- # # initiate distance and collision
264- # dist = 0
265- # collision = False
266- #
267- # # calculate distance
268- # # front
269- # if -y_buff <= y_p <= y_buff and x_p > x_buff:
270- # dist = x_p - x_buff
271- # # left front
272- # elif y_p > y_buff and x_p > x_buff:
273- # dist = np.sqrt((x_p - x_buff) ** 2 + (y_p - y_buff) ** 2)
274- # # right front
275- # elif y_p < -y_buff and x_p > x_buff:
276- # dist = np.sqrt((x_p - x_buff) ** 2 + (y_p + y_buff) ** 2)
277- # # left
278- # elif y_p > y_buff and -x_buff <= x_p <= x_buff:
279- # dist = y_p - y_buff
280- # # right
281- # elif y_p < -y_buff and -x_buff <= x_p <= x_buff:
282- # dist = y_p + y_buff
283- # # rear
284- # elif -y_buff <= y_p <= y_buff and x_p < -x_buff:
285- # dist = x_p + x_buff
286- # # left rear
287- # elif y_p > y_buff and x_p < -x_buff:
288- # dist = np.sqrt((x_p - x_buff) ** 2 + (y_p - y_buff) ** 2)
289- # # right rear
290- # elif y_p < -y_buff and x_p < -x_buff:
291- # dist = np.sqrt((x_p - x_buff) ** 2 + (y_p + y_buff) ** 2)
292- # # intersect
293- # else:
294- # dist = 0
295- #
296- # return dist
297-
298-
299257""" Planning in start frame with waypoints """
300- # # TODO: how to get further unreached waypoints only
258+ # # TODO: to get further unreached waypoints only
301259# def get_waypoint_arc_and_new_yaw(curr_x, curr_y, curr_yaw, waypoint):
302260# """
303261# Input:
@@ -333,7 +291,7 @@ def point_dist(x1, y1, x2, y2):
333291# is_crossing: boolean, if the pedestrian is crossing the path
334292# arc_dist_collision: distance from start_point to the closest pedestrian enter or exit point mapped to the path
335293# """
336- # # TODO: compute pedestrian path with yaw_rate?
294+ # # TODO: consider pedestrian path with yaw_rate
337295# xp, yp = pose.x, pose.y
338296# vx, vy = velocity
339297# xc, yc = center
@@ -449,7 +407,6 @@ def point_dist(x1, y1, x2, y2):
449407# """
450408# All calculations are in start frame, origin reference: rear_axle_center (refer to GEMstack/knowledge/calibration)
451409# """
452- # # TODO: confirm origin reference with calibration team
453410# # current states
454411# vehicle = state.vehicle
455412# curr_x = vehicle.pose.x
@@ -458,11 +415,9 @@ def point_dist(x1, y1, x2, y2):
458415# curr_v = vehicle.v
459416#
460417# # determine lookahead distance using current velocity and a decent deceleration
461- # decel_decent = 2.0 # TODO: adjust for a decent deceleration if necessary
462- # t_brake = curr_v / decel_decent # time to brake down to zero
418+ # t_brake = curr_v / comfort_decel # time to brake down to zero
463419# dist_lookahead = curr_v * t_brake
464420#
465- # # TODO: check if it works with straight line waypoints
466421# distance = 0
467422# temp_x, temp_y, temp_yaw = curr_x, curr_y, curr_yaw
468423# is_collision = False
@@ -500,83 +455,3 @@ def point_dist(x1, y1, x2, y2):
500455# break
501456#
502457# return is_collision, dist_collision
503-
504-
505- """ Assume the vehicle move straight forward """
506- # def compute_intersect(A1, B1, C1, A2, B2, C2):
507- # """
508- # calculate intersection point of two lines
509- # A1*x + B1*y + C1 = 0 and A2*x + B2*y + C2 = 0
510- # """
511- # if A1*B2 - A2*B1 == 0:
512- # if C1 == C2:
513- # return "conincide"
514- # else:
515- # return "parallel"
516- # else:
517- # x_inter = (B1*C2 - B2*C1) / (A1*B2 - A2*B1)
518- # y_inter = (C1*A2 - C2*A1) / (A1*B2 - A2*B1)
519- # return x_inter, y_inter
520- #
521- # def yield_in_ego_frame(pedestrian_position_ego, pedestrian_velocity_ego, dist_lookahead, buffer):
522- # """
523- # Calculate the intersection of the pedestrian's path and vehicle path with buffer
524- # Yield if the intersection is in front of the vehicle and within lookahead distance
525- # """
526- # x_buff, y_buff = buffer
527- # # consider 2D geometry
528- # x_p, y_p = pedestrian_position_ego[:2]
529- # v_x, v_y = pedestrian_velocity_ego[:2]
530- # # initiate yielding and distance
531- # yielding = False
532- # distance = None
533- #
534- # # line expression: A*x + B*y + C = 0
535- # # pedestrian's path: v_y * x - v_x * y + (v_x * y_p - v_y * x_p) = 0
536- # A_p, B_p, C_p = v_y, -v_x, v_x * y_p - v_y * x_p
537- # # buffer area: y = y_buff, y = - y_buff
538- # A_left, B_left, C_left = 0, 1, -y_buff
539- # A_right, B_right, C_right = 0, 1, y_buff
540- #
541- # # deal with parallel first
542- # if A_p*B_left - A_left*B_p == 0:
543- # if -y_buff <= y_p <= y_buff:
544- # yielding = True
545- # distance = x_p
546- # else:
547- # yielding = False
548- # distance = None
549- # # compute intersection
550- # else:
551- # left_inter_x, left_inter_y = compute_intersect(A_p, B_p, C_p, A_left, B_left, C_left)
552- # right_inter_x, right_inter_y = compute_intersect(A_p, B_p, C_p, A_right, B_right, C_right)
553- # if -x_buff <= left_inter_x <= dist_lookahead or -x_buff <= right_inter_x <= dist_lookahead:
554- # yielding = True
555- # else:
556- # yielding = False
557- # distance = min(left_inter_x, right_inter_x)
558- #
559- # return yielding, distance
560- #
561- # vehicle = state.vehicle
562- # curr_x = vehicle.pose.x
563- # curr_y = vehicle.pose.y
564- # curr_yaw = vehicle.pose.yaw
565- # curr_v = vehicle.v
566- #
567- # # 2D transformation from start frame to ego frame
568- # R_start2ego = np.array([[np.cos(curr_yaw),-np.sin(curr_yaw)],[np.sin(curr_yaw),np.cos(curr_yaw)]])
569- # t_start2ego = np.array([curr_x, curr_y])
570- #
571- # # check collision distance and break if going to collide
572- # dist_min = np.inf
573- # for ped in pedestrians:
574- # # pedestrian states from perception
575- # pos_p = ped.state.pose # both vectors are x, y in vehicle frame
576- # v_p = ped.state.v
577- # pos_start2ego = R_start2ego @ pos_p + t_start2ego
578- # v_start2ego = v_p @ pos_p + t_start2ego
579- # yielding, distance = yield_in_ego_frame(pos_start2ego,v_start2ego, dist_lookahead, buffer)
580- # if yielding == True and distance is not None:
581- # if distance < dist_min:
582- # dist_min = distance
0 commit comments