|
|
|
@ -1,7 +1,6 @@ |
|
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
import math |
|
|
|
|
import numpy as np |
|
|
|
|
from openpilot.common.numpy_fast import clip, interp |
|
|
|
|
|
|
|
|
|
import cereal.messaging as messaging |
|
|
|
|
from opendbc.car.interfaces import ACCEL_MIN, ACCEL_MAX |
|
|
|
@ -30,7 +29,7 @@ _A_TOTAL_MAX_BP = [20., 40.] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_max_accel(v_ego): |
|
|
|
|
return interp(v_ego, A_CRUISE_MAX_BP, A_CRUISE_MAX_VALS) |
|
|
|
|
return np.interp(v_ego, A_CRUISE_MAX_BP, A_CRUISE_MAX_VALS) |
|
|
|
|
|
|
|
|
|
def get_coast_accel(pitch): |
|
|
|
|
return np.sin(pitch) * -5.65 - 0.3 # fitted from data using xx/projects/allow_throttle/compute_coast_accel.py |
|
|
|
@ -43,7 +42,7 @@ def limit_accel_in_turns(v_ego, angle_steers, a_target, CP): |
|
|
|
|
""" |
|
|
|
|
# FIXME: This function to calculate lateral accel is incorrect and should use the VehicleModel |
|
|
|
|
# The lookup table for turns should also be updated if we do this |
|
|
|
|
a_total_max = interp(v_ego, _A_TOTAL_MAX_BP, _A_TOTAL_MAX_V) |
|
|
|
|
a_total_max = np.interp(v_ego, _A_TOTAL_MAX_BP, _A_TOTAL_MAX_V) |
|
|
|
|
a_y = v_ego ** 2 * angle_steers * CV.DEG_TO_RAD / (CP.steerRatio * CP.wheelbase) |
|
|
|
|
a_x_allowed = math.sqrt(max(a_total_max ** 2 - a_y ** 2, 0.)) |
|
|
|
|
|
|
|
|
@ -55,9 +54,9 @@ def get_accel_from_plan(speeds, accels, action_t=DT_MDL, vEgoStopping=0.05): |
|
|
|
|
v_now = speeds[0] |
|
|
|
|
a_now = accels[0] |
|
|
|
|
|
|
|
|
|
v_target = interp(action_t, CONTROL_N_T_IDX, speeds) |
|
|
|
|
v_target = np.interp(action_t, CONTROL_N_T_IDX, speeds) |
|
|
|
|
a_target = 2 * (v_target - v_now) / (action_t) - a_now |
|
|
|
|
v_target_1sec = interp(action_t + 1.0, CONTROL_N_T_IDX, speeds) |
|
|
|
|
v_target_1sec = np.interp(action_t + 1.0, CONTROL_N_T_IDX, speeds) |
|
|
|
|
else: |
|
|
|
|
v_target = 0.0 |
|
|
|
|
v_target_1sec = 0.0 |
|
|
|
@ -139,7 +138,7 @@ class LongitudinalPlanner: |
|
|
|
|
if reset_state: |
|
|
|
|
self.v_desired_filter.x = v_ego |
|
|
|
|
# Clip aEgo to cruise limits to prevent large accelerations when becoming active |
|
|
|
|
self.a_desired = clip(sm['carState'].aEgo, accel_limits[0], accel_limits[1]) |
|
|
|
|
self.a_desired = np.clip(sm['carState'].aEgo, accel_limits[0], accel_limits[1]) |
|
|
|
|
|
|
|
|
|
# Prevent divergence, smooth in current v_ego |
|
|
|
|
self.v_desired_filter.x = max(0.0, self.v_desired_filter.update(v_ego)) |
|
|
|
@ -151,7 +150,7 @@ class LongitudinalPlanner: |
|
|
|
|
|
|
|
|
|
if not self.allow_throttle: |
|
|
|
|
clipped_accel_coast = max(accel_coast, accel_limits_turns[0]) |
|
|
|
|
clipped_accel_coast_interp = interp(v_ego, [MIN_ALLOW_THROTTLE_SPEED, MIN_ALLOW_THROTTLE_SPEED*2], [accel_limits_turns[1], clipped_accel_coast]) |
|
|
|
|
clipped_accel_coast_interp = np.interp(v_ego, [MIN_ALLOW_THROTTLE_SPEED, MIN_ALLOW_THROTTLE_SPEED*2], [accel_limits_turns[1], clipped_accel_coast]) |
|
|
|
|
accel_limits_turns[1] = min(accel_limits_turns[1], clipped_accel_coast_interp) |
|
|
|
|
|
|
|
|
|
if force_slow_decel: |
|
|
|
@ -176,7 +175,7 @@ class LongitudinalPlanner: |
|
|
|
|
|
|
|
|
|
# Interpolate 0.05 seconds and save as starting point for next iteration |
|
|
|
|
a_prev = self.a_desired |
|
|
|
|
self.a_desired = float(interp(self.dt, CONTROL_N_T_IDX, self.a_desired_trajectory)) |
|
|
|
|
self.a_desired = float(np.interp(self.dt, CONTROL_N_T_IDX, self.a_desired_trajectory)) |
|
|
|
|
self.v_desired_filter.x = self.v_desired_filter.x + self.dt * (self.a_desired + a_prev) / 2.0 |
|
|
|
|
|
|
|
|
|
def publish(self, sm, pm): |
|
|
|
@ -200,9 +199,9 @@ class LongitudinalPlanner: |
|
|
|
|
action_t = self.CP.longitudinalActuatorDelay + DT_MDL |
|
|
|
|
a_target, should_stop = get_accel_from_plan(longitudinalPlan.speeds, longitudinalPlan.accels, |
|
|
|
|
action_t=action_t, vEgoStopping=self.CP.vEgoStopping) |
|
|
|
|
longitudinalPlan.aTarget = a_target |
|
|
|
|
longitudinalPlan.shouldStop = should_stop |
|
|
|
|
longitudinalPlan.aTarget = float(a_target) |
|
|
|
|
longitudinalPlan.shouldStop = bool(should_stop) |
|
|
|
|
longitudinalPlan.allowBrake = True |
|
|
|
|
longitudinalPlan.allowThrottle = self.allow_throttle |
|
|
|
|
longitudinalPlan.allowThrottle = bool(self.allow_throttle) |
|
|
|
|
|
|
|
|
|
pm.send('longitudinalPlan', plan_send) |
|
|
|
|