Skip to content

Commit 383893d

Browse files
authored
Long planner get accel: new function args (commaai#34288)
* Change function args * typo * typo * ref commit
1 parent 1a7c284 commit 383893d

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

selfdrive/controls/lib/longitudinal_planner.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,20 @@ def limit_accel_in_turns(v_ego, angle_steers, a_target, CP):
5050
return [a_target[0], min(a_target[1], a_x_allowed)]
5151

5252

53-
def get_accel_from_plan(CP, speeds, accels):
53+
def get_accel_from_plan(speeds, accels, action_t=DT_MDL, vEgoStopping=0.05):
5454
if len(speeds) == CONTROL_N:
55-
v_target_now = interp(DT_MDL, CONTROL_N_T_IDX, speeds)
56-
a_target_now = interp(DT_MDL, CONTROL_N_T_IDX, accels)
55+
v_now = speeds[0]
56+
a_now = accels[0]
5757

58-
v_target = interp(CP.longitudinalActuatorDelay + DT_MDL, CONTROL_N_T_IDX, speeds)
59-
if v_target != v_target_now:
60-
a_target = 2 * (v_target - v_target_now) / CP.longitudinalActuatorDelay - a_target_now
61-
else:
62-
a_target = a_target_now
63-
64-
v_target_1sec = interp(CP.longitudinalActuatorDelay + DT_MDL + 1.0, CONTROL_N_T_IDX, speeds)
58+
v_target = interp(action_t, CONTROL_N_T_IDX, speeds)
59+
a_target = 2 * (v_target - v_now) / (action_t) - a_now
60+
v_target_1sec = interp(action_t + 1.0, CONTROL_N_T_IDX, speeds)
6561
else:
6662
v_target = 0.0
6763
v_target_1sec = 0.0
6864
a_target = 0.0
69-
should_stop = (v_target < CP.vEgoStopping and
70-
v_target_1sec < CP.vEgoStopping)
65+
should_stop = (v_target < vEgoStopping and
66+
v_target_1sec < vEgoStopping)
7167
return a_target, should_stop
7268

7369

@@ -201,7 +197,9 @@ def publish(self, sm, pm):
201197
longitudinalPlan.longitudinalPlanSource = self.mpc.source
202198
longitudinalPlan.fcw = self.fcw
203199

204-
a_target, should_stop = get_accel_from_plan(self.CP, longitudinalPlan.speeds, longitudinalPlan.accels)
200+
action_t = self.CP.longitudinalActuatorDelay + DT_MDL
201+
a_target, should_stop = get_accel_from_plan(longitudinalPlan.speeds, longitudinalPlan.accels,
202+
action_t=action_t, vEgoStopping=self.CP.vEgoStopping)
205203
longitudinalPlan.aTarget = a_target
206204
longitudinalPlan.shouldStop = should_stop
207205
longitudinalPlan.allowBrake = True

selfdrive/test/process_replay/migration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def migrate_longitudinalPlan(msgs):
107107
if msg.which() != 'longitudinalPlan':
108108
continue
109109
new_msg = msg.as_builder()
110-
new_msg.longitudinalPlan.aTarget, new_msg.longitudinalPlan.shouldStop = get_accel_from_plan(CP, msg.longitudinalPlan.speeds, msg.longitudinalPlan.accels)
110+
new_msg.longitudinalPlan.aTarget, new_msg.longitudinalPlan.shouldStop = get_accel_from_plan(msg.longitudinalPlan.speeds, msg.longitudinalPlan.accels)
111111
ops.append((index, new_msg.as_reader()))
112112
return ops, [], []
113113

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cae12bc0a2960de17104a9e22fafe33d797fbcee
1+
1f37082d56a60f20ba9e36b702a23cbdde3caca7

0 commit comments

Comments
 (0)