Skip to content

Commit

Permalink
Merge 1dc0b69 into 3292767
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenevinitsky committed Mar 4, 2020
2 parents 3292767 + 1dc0b69 commit 19ae7f3
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions flow/controllers/velocity_controllers.py
Expand Up @@ -116,6 +116,54 @@ def get_accel(self, env):
return (v_cmd - this_vel) / env.sim_step


class NonLocalFollowerStopper(FollowerStopper):
"""Follower stopper that uses the average system speed to compute its acceleration."""

def get_accel(self, env):
"""See parent class."""
lead_id = env.k.vehicle.get_leader(self.veh_id)
this_vel = env.k.vehicle.get_speed(self.veh_id)
lead_vel = env.k.vehicle.get_speed(lead_id)
self.v_des = np.mean(env.k.vehicle.get_speed(env.k.vehicle.get_ids()))

if self.v_des is None:
return None

if lead_id is None:
v_cmd = self.v_des
else:
dx = env.k.vehicle.get_headway(self.veh_id)
dv_minus = min(lead_vel - this_vel, 0)

dx_1 = self.dx_1_0 + 1 / (2 * self.d_1) * dv_minus ** 2
dx_2 = self.dx_2_0 + 1 / (2 * self.d_2) * dv_minus ** 2
dx_3 = self.dx_3_0 + 1 / (2 * self.d_3) * dv_minus ** 2
v = min(max(lead_vel, 0), self.v_des)
# compute the desired velocity
if dx <= dx_1:
v_cmd = 0
elif dx <= dx_2:
v_cmd = v * (dx - dx_1) / (dx_2 - dx_1)
elif dx <= dx_3:
v_cmd = v + (self.v_des - this_vel) * (dx - dx_2) \
/ (dx_3 - dx_2)
else:
v_cmd = self.v_des

edge = env.k.vehicle.get_edge(self.veh_id)

if edge == "":
return None

if self.find_intersection_dist(env) <= 10 and \
env.k.vehicle.get_edge(self.veh_id) in self.danger_edges or \
env.k.vehicle.get_edge(self.veh_id)[0] == ":":
return None
else:
# compute the acceleration from the desired velocity
return (v_cmd - this_vel) / env.sim_step


class PISaturation(BaseController):
"""Inspired by Dan Work's... work.
Expand Down

0 comments on commit 19ae7f3

Please sign in to comment.