@ -4,7 +4,7 @@ from common.numpy_fast import interp
from system . swaglog import cloudlog
from system . swaglog import cloudlog
from selfdrive . controls . lib . lateral_mpc_lib . lat_mpc import LateralMpc
from selfdrive . controls . lib . lateral_mpc_lib . lat_mpc import LateralMpc
from selfdrive . controls . lib . lateral_mpc_lib . lat_mpc import N as LAT_MPC_N
from selfdrive . controls . lib . lateral_mpc_lib . lat_mpc import N as LAT_MPC_N
from selfdrive . controls . lib . drive_helpers import CONTROL_N , MIN_SPEED
from selfdrive . controls . lib . drive_helpers import CONTROL_N , MIN_SPEED , get_speed_error
from selfdrive . controls . lib . desire_helper import DesireHelper
from selfdrive . controls . lib . desire_helper import DesireHelper
import cereal . messaging as messaging
import cereal . messaging as messaging
from cereal import log
from cereal import log
@ -51,6 +51,7 @@ class LateralPlanner:
def update ( self , sm ) :
def update ( self , sm ) :
# clip speed , lateral planning is not possible at 0 speed
# clip speed , lateral planning is not possible at 0 speed
measured_curvature = sm [ ' controlsState ' ] . curvature
measured_curvature = sm [ ' controlsState ' ] . curvature
v_ego_car = sm [ ' carState ' ] . vEgo
# Parse model predictions
# Parse model predictions
md = sm [ ' modelV2 ' ]
md = sm [ ' modelV2 ' ]
@ -60,7 +61,7 @@ class LateralPlanner:
self . plan_yaw = np . array ( md . orientation . z )
self . plan_yaw = np . array ( md . orientation . z )
self . plan_yaw_rate = np . array ( md . orientationRate . z )
self . plan_yaw_rate = np . array ( md . orientationRate . z )
self . velocity_xyz = np . column_stack ( [ md . velocity . x , md . velocity . y , md . velocity . z ] )
self . velocity_xyz = np . column_stack ( [ md . velocity . x , md . velocity . y , md . velocity . z ] )
car_speed = np . linalg . norm ( self . velocity_xyz , axis = 1 )
car_speed = np . linalg . norm ( self . velocity_xyz , axis = 1 ) - get_speed_error ( md , v_ego_car )
self . v_plan = np . clip ( car_speed , MIN_SPEED , np . inf )
self . v_plan = np . clip ( car_speed , MIN_SPEED , np . inf )
self . v_ego = self . v_plan [ 0 ]
self . v_ego = self . v_plan [ 0 ]