Skip to content

Commit

Permalink
lat planner retune + slow down for turns
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Dec 15, 2022
1 parent 883a968 commit 7b97ddb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions selfdrive/controls/lib/lateral_planner.py
Expand Up @@ -15,13 +15,13 @@

PATH_COST = 1.0
LATERAL_MOTION_COST = 0.11
LATERAL_ACCEL_COST = 0.0
LATERAL_ACCEL_COST = 1.0
LATERAL_JERK_COST = 0.05
# Extreme steering rate is unpleasant, even
# when it does not cause bad jerk.
# TODO this cost should be lowered when low
# speed lateral control is stable on all cars
STEERING_RATE_COST = 800.0
STEERING_RATE_COST = 8.0


class LateralPlanner:
Expand Down
8 changes: 6 additions & 2 deletions selfdrive/controls/lib/longitudinal_planner.py
Expand Up @@ -60,7 +60,7 @@ def __init__(self, CP, init_v=0.0, init_a=0.0):
self.solverExecutionTime = 0.0

@staticmethod
def parse_model(model_msg, model_error):
def parse_model(model_msg, model_error, v_ego):
if (len(model_msg.position.x) == 33 and
len(model_msg.velocity.x) == 33 and
len(model_msg.acceleration.x) == 33):
Expand All @@ -73,6 +73,10 @@ def parse_model(model_msg, model_error):
v = np.zeros(len(T_IDXS_MPC))
a = np.zeros(len(T_IDXS_MPC))
j = np.zeros(len(T_IDXS_MPC))
max_lat_accel = interp(v_ego, [5, 10, 20], [1.5, 2.0, 3.0])
curvatures = np.interp(T_IDXS_MPC, T_IDXS, model_msg.orientationRate.z) / np.clip(v, 0.3, 100.0)
max_v = np.sqrt(max_lat_accel / (np.abs(curvatures) + 1e-3)) - 2.0
v = np.minimum(max_v, v)
return x, v, a, j

def update(self, sm):
Expand Down Expand Up @@ -121,7 +125,7 @@ def update(self, sm):
self.mpc.set_weights(prev_accel_constraint)
self.mpc.set_accel_limits(accel_limits_turns[0], accel_limits_turns[1])
self.mpc.set_cur_state(self.v_desired_filter.x, self.a_desired)
x, v, a, j = self.parse_model(sm['modelV2'], self.v_model_error)
x, v, a, j = self.parse_model(sm['modelV2'], self.v_model_error, v_ego)
self.mpc.update(sm['carState'], sm['radarState'], v_cruise, x, v, a, j)

self.v_desired_trajectory = np.interp(T_IDXS[:CONTROL_N], T_IDXS_MPC, self.mpc.v_solution)
Expand Down

0 comments on commit 7b97ddb

Please sign in to comment.