@@ -42,22 +42,27 @@ behavior WalkForwardBehavior():
4242behavior ConstantThrottleBehavior (x ):
4343 take SetThrottleAction (x)
4444
45- def getFollowLanePath (obj , minPathDistance , preferStraight , path_metadata = None ):
45+ def getFollowLanePath (obj , minPathDistance , preferStraight , laneToFollow = None , path_metadata = None ):
4646 import shapely
4747 import itertools
4848
49- def mergeLineStrings (geoms ):
50- return shapely.geometry.LineString (itertools.chain.from_iterable (geom.coords for geom in geoms))
49+ if laneToFollow is None :
50+ laneToFollow = obj.lane
51+ elif not isinstance (laneToFollow, Lane):
52+ raise ValueError (" `laneToFollow` is not a `Lane`." )
5153
5254 if path_metadata is None :
53- current_lane = ego .lane
54- initial_path = obj.lane .centerline.lineString
55+ current_lane = laneToFollow
56+ initial_path = current_lane .centerline.lineString
5557 else :
5658 current_lane = path_metadata[0 ]
5759 initial_path = path_metadata[1 ]
5860
5961 assert isinstance (initial_path, shapely.geometry.LineString)
6062
63+ def mergeLineStrings (geoms ):
64+ return shapely.geometry.LineString (itertools.chain.from_iterable (geom.coords for geom in geoms))
65+
6166 ego_pt = shapely.geometry.Point (* obj.position)
6267 path = shapely.ops.substring (initial_path, initial_path.project (ego_pt), initial_path.length)
6368
@@ -84,7 +89,7 @@ def getFollowLanePath(obj, minPathDistance, preferStraight, path_metadata=None):
8489 assert isinstance (path, shapely.geometry.LineString)
8590 return PolylineRegion (polyline = path), (current_lane, path)
8691
87- behavior FollowLaneBehavior (target_speed = 10 , laneToFollow = None , preferStraight = True ):
92+ behavior FollowLaneBehavior (target_speed = 10 , laneToFollow = None , preferStraight = True ):
8893 """
8994 Follows the lane on which the vehicle is at, unless the laneToFollow is specified.
9095 Once the vehicle reaches an intersection, by default, the vehicle will take the straight route.
@@ -108,7 +113,8 @@ behavior FollowLaneBehavior(target_speed = 10, laneToFollow=None, preferStraight
108113 while True :
109114 replan_time = 10
110115 min_path_distance = max (2 * replan_time* target_speed, 50 )
111- path, path_metadata = getFollowLanePath (self , min_path_distance, preferStraight = preferStraight, path_metadata = path_metadata)
116+ path, path_metadata = getFollowLanePath (self , min_path_distance,
117+ preferStraight = preferStraight, laneToFollow = laneToFollow, path_metadata = path_metadata)
112118 traj = Trajectory.createFixedSpeedTrajectory (path, target_speed, ts = simulation ().timestep)
113119 do FollowTrajectoryBehavior (traj) for replan_time seconds
114120
@@ -180,7 +186,7 @@ behavior FollowTrajectoryBehavior(trajectory, terminationDistance=1):
180186 throttle_action = SetBrakeAction (- throttle)
181187
182188 # Compute steering : Lateral Control
183- steer = self .lateralController.computeSteering (trajectory, self , simulation () )
189+ steer = self .lateralController.computeSteering (trajectory, self )
184190 steer_action = SetSteerAction (steer)
185191
186192 take throttle_action, steer_action
0 commit comments