Skip to content

Commit 4d6abc2

Browse files
committed
Additional controller tweaks.
1 parent b163047 commit 4d6abc2

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/scenic/domains/driving/behaviors.scenic

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,27 @@ behavior WalkForwardBehavior():
4242
behavior 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

src/scenic/domains/driving/controllers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(self, dt=0.1, *, K_P=0.3, K_D=0.2, K_I=0, wg=0):
102102
super().__init__(dt=dt, K_P=K_P, K_D=K_D, K_I=K_I, wg=wg)
103103

104104
def computeSteering(self, trajectory, veh):
105-
cte = trajectory.signedDistanceTo(veh.position)
105+
cte = trajectory.polyline.signedDistanceTo(veh.position)
106106
steer_angle = self.run_step(cte)
107107
return steer_angle
108108

@@ -152,7 +152,7 @@ def _findTargetPoint(self, trajectory, veh, lookaheadDistance):
152152
self._lastTargetPoint = target_point
153153
return Vector(target_point.x, target_point.y)
154154

155-
def computeSteering(self, trajectory, veh, simulation):
155+
def computeSteering(self, trajectory, veh):
156156
# Compute target steering angle
157157
lookaheadDistance = self.lookaheadDistance(veh)
158158
targetPoint = self._findTargetPoint(trajectory, veh, lookaheadDistance)

0 commit comments

Comments
 (0)