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