|
|
|
@ -10,11 +10,12 @@ from selfdrive.modeld.constants import T_IDXS |
|
|
|
|
from selfdrive.controls.lib.longitudinal_planner import LongitudinalPlanner |
|
|
|
|
from selfdrive.controls.lib.radar_helpers import _LEAD_ACCEL_TAU |
|
|
|
|
|
|
|
|
|
class Plant(): |
|
|
|
|
|
|
|
|
|
class Plant: |
|
|
|
|
messaging_initialized = False |
|
|
|
|
|
|
|
|
|
def __init__(self, lead_relevancy=False, speed=0.0, distance_lead=2.0, |
|
|
|
|
only_lead2=False, only_radar=False): |
|
|
|
|
enabled=True, only_lead2=False, only_radar=False): |
|
|
|
|
self.rate = 1. / DT_MDL |
|
|
|
|
|
|
|
|
|
if not Plant.messaging_initialized: |
|
|
|
@ -32,8 +33,9 @@ class Plant(): |
|
|
|
|
self.speeds = [] |
|
|
|
|
|
|
|
|
|
# lead car |
|
|
|
|
self.distance_lead = distance_lead |
|
|
|
|
self.lead_relevancy = lead_relevancy |
|
|
|
|
self.distance_lead = distance_lead |
|
|
|
|
self.enabled = enabled |
|
|
|
|
self.only_lead2 = only_lead2 |
|
|
|
|
self.only_radar = only_radar |
|
|
|
|
|
|
|
|
@ -47,6 +49,7 @@ class Plant(): |
|
|
|
|
|
|
|
|
|
self.planner = LongitudinalPlanner(CarInterface.get_params(CAR.CIVIC), init_v=self.speed) |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def current_time(self): |
|
|
|
|
return float(self.rk.frame) / self.rate |
|
|
|
|
|
|
|
|
@ -104,9 +107,7 @@ class Plant(): |
|
|
|
|
acceleration.x = [float(x) for x in np.zeros_like(T_IDXS)] |
|
|
|
|
model.modelV2.acceleration = acceleration |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
control.controlsState.longControlState = LongCtrlState.pid |
|
|
|
|
control.controlsState.longControlState = LongCtrlState.pid if self.enabled else LongCtrlState.off |
|
|
|
|
control.controlsState.vCruise = float(v_cruise * 3.6) |
|
|
|
|
car_state.carState.vEgo = float(self.speed) |
|
|
|
|
car_state.carState.standstill = self.speed < 0.01 |
|
|
|
@ -141,7 +142,7 @@ class Plant(): |
|
|
|
|
# print at 5hz |
|
|
|
|
if (self.rk.frame % (self.rate // 5)) == 0: |
|
|
|
|
print("%2.2f sec %6.2f m %6.2f m/s %6.2f m/s2 lead_rel: %6.2f m %6.2f m/s" |
|
|
|
|
% (self.current_time(), self.distance, self.speed, self.acceleration, d_rel, v_rel)) |
|
|
|
|
% (self.current_time, self.distance, self.speed, self.acceleration, d_rel, v_rel)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ******** update prevs ******** |
|
|
|
|