mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 22:23:56 +08:00
Longitudinal control: interpolate longitudinal plan (#23787)
* interpolate longitudinal actuator delay rename * formatting * interpolate v_target most importantly! * fix interpolation and rename * nicer setup * left in from testing * update refs
This commit is contained in:
@@ -97,6 +97,7 @@ class CarInterfaceBase(ABC):
|
||||
ret.longitudinalTuning.kpV = [1.]
|
||||
ret.longitudinalTuning.kiBP = [0.]
|
||||
ret.longitudinalTuning.kiV = [1.]
|
||||
# TODO estimate car specific lag, use .15s for now
|
||||
ret.longitudinalActuatorDelayLowerBound = 0.15
|
||||
ret.longitudinalActuatorDelayUpperBound = 0.15
|
||||
ret.steerLimitTimer = 1.0
|
||||
|
||||
@@ -492,7 +492,8 @@ class Controls:
|
||||
if not self.joystick_mode:
|
||||
# accel PID loop
|
||||
pid_accel_limits = self.CI.get_pid_accel_limits(self.CP, CS.vEgo, self.v_cruise_kph * CV.KPH_TO_MS)
|
||||
actuators.accel = self.LoC.update(self.active, CS, self.CP, long_plan, pid_accel_limits)
|
||||
t_since_plan = (self.sm.frame - self.sm.rcv_frame['longitudinalPlan']) * DT_CTRL
|
||||
actuators.accel = self.LoC.update(self.active, CS, self.CP, long_plan, pid_accel_limits, t_since_plan)
|
||||
|
||||
# Steering PID loop and lateral MPC
|
||||
lat_active = self.active and not CS.steerWarning and not CS.steerError and CS.vEgo > self.CP.minSteerSpeed
|
||||
|
||||
@@ -53,20 +53,21 @@ class LongControl():
|
||||
self.pid.reset()
|
||||
self.v_pid = v_pid
|
||||
|
||||
def update(self, active, CS, CP, long_plan, accel_limits):
|
||||
def update(self, active, CS, CP, long_plan, accel_limits, t_since_plan):
|
||||
"""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
|
||||
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 = interp(t_since_plan, T_IDXS[:CONTROL_N], speeds)
|
||||
a_target = interp(t_since_plan, T_IDXS[:CONTROL_N], long_plan.accels)
|
||||
|
||||
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]
|
||||
v_target_lower = interp(CP.longitudinalActuatorDelayLowerBound + t_since_plan, T_IDXS[:CONTROL_N], speeds)
|
||||
a_target_lower = 2 * (v_target_lower - v_target) / CP.longitudinalActuatorDelayLowerBound - a_target
|
||||
|
||||
v_target_upper = interp(CP.longitudinalActuatorDelayUpperBound + t_since_plan, T_IDXS[:CONTROL_N], speeds)
|
||||
a_target_upper = 2 * (v_target_upper - v_target) / CP.longitudinalActuatorDelayUpperBound - a_target
|
||||
a_target = min(a_target_lower, a_target_upper)
|
||||
|
||||
v_target = speeds[0]
|
||||
v_target_future = speeds[-1]
|
||||
else:
|
||||
v_target = 0.0
|
||||
|
||||
@@ -1 +1 @@
|
||||
302258d8bdfea779c546f76c191ed451b18062f5
|
||||
24c4d6b8d49b42416f2ca6a59d563f7b8c984e2b
|
||||
Reference in New Issue
Block a user