Skip to content

Commit

Permalink
longcontrol/update: optimize capnp (commaai#23382)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee authored Jan 4, 2022
1 parent 15f88db commit 5dc631f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions selfdrive/controls/lib/longcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ def update(self, active, CS, CP, long_plan, accel_limits):
"""Update longitudinal control. This updates the state machine and runs a PID loop"""
# Interp control trajectory
# TODO estimate car specific lag, use .15s for now
if len(long_plan.speeds) == CONTROL_N:
v_target_lower = interp(CP.longitudinalActuatorDelayLowerBound, T_IDXS[:CONTROL_N], long_plan.speeds)
a_target_lower = 2 * (v_target_lower - long_plan.speeds[0])/CP.longitudinalActuatorDelayLowerBound - long_plan.accels[0]
speeds = long_plan.speeds
if len(speeds) == CONTROL_N:
v_target_lower = interp(CP.longitudinalActuatorDelayLowerBound, T_IDXS[:CONTROL_N], speeds)
a_target_lower = 2 * (v_target_lower - speeds[0])/CP.longitudinalActuatorDelayLowerBound - long_plan.accels[0]

v_target_upper = interp(CP.longitudinalActuatorDelayUpperBound, T_IDXS[:CONTROL_N], long_plan.speeds)
a_target_upper = 2 * (v_target_upper - long_plan.speeds[0])/CP.longitudinalActuatorDelayUpperBound - long_plan.accels[0]
v_target_upper = interp(CP.longitudinalActuatorDelayUpperBound, T_IDXS[:CONTROL_N], speeds)
a_target_upper = 2 * (v_target_upper - speeds[0])/CP.longitudinalActuatorDelayUpperBound - long_plan.accels[0]
a_target = min(a_target_lower, a_target_upper)

v_target_future = long_plan.speeds[-1]
v_target_future = speeds[-1]
else:
v_target_future = 0.0
a_target = 0.0
Expand All @@ -96,7 +97,7 @@ def update(self, active, CS, CP, long_plan, accel_limits):

# tracking objects and driving
elif self.long_control_state == LongCtrlState.pid:
self.v_pid = long_plan.speeds[0]
self.v_pid = speeds[0]

# Toyota starts braking more when it thinks you want to stop
# Freeze the integrator so we don't accelerate to compensate, and don't allow positive acceleration
Expand Down

0 comments on commit 5dc631f

Please sign in to comment.