|
|
|
@ -21,17 +21,20 @@ from opendbc.car.car_helpers import get_demo_car_params |
|
|
|
|
from openpilot.common.swaglog import cloudlog |
|
|
|
|
from openpilot.common.params import Params |
|
|
|
|
from openpilot.common.filter_simple import FirstOrderFilter |
|
|
|
|
from openpilot.common.realtime import config_realtime_process |
|
|
|
|
from openpilot.common.realtime import config_realtime_process, DT_MDL |
|
|
|
|
from openpilot.common.transformations.camera import DEVICE_CAMERAS |
|
|
|
|
from openpilot.common.transformations.model import get_warp_matrix |
|
|
|
|
from openpilot.system import sentry |
|
|
|
|
from openpilot.selfdrive.controls.lib.desire_helper import DesireHelper |
|
|
|
|
from openpilot.selfdrive.controls.lib.drive_helpers import get_accel_from_plan |
|
|
|
|
from openpilot.selfdrive.modeld.parse_model_outputs import Parser |
|
|
|
|
from openpilot.selfdrive.modeld.fill_model_msg import fill_model_msg, fill_pose_msg, PublishState |
|
|
|
|
from openpilot.selfdrive.modeld.constants import ModelConstants |
|
|
|
|
from openpilot.selfdrive.modeld.constants import ModelConstants, Plan |
|
|
|
|
from openpilot.selfdrive.modeld.models.commonmodel_pyx import DrivingModelFrame, CLContext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PROCESS_NAME = "selfdrive.modeld.modeld" |
|
|
|
|
SEND_RAW_PRED = os.getenv('SEND_RAW_PRED') |
|
|
|
|
|
|
|
|
@ -40,6 +43,30 @@ POLICY_PKL_PATH = Path(__file__).parent / 'models/driving_policy_tinygrad.pkl' |
|
|
|
|
VISION_METADATA_PATH = Path(__file__).parent / 'models/driving_vision_metadata.pkl' |
|
|
|
|
POLICY_METADATA_PATH = Path(__file__).parent / 'models/driving_policy_metadata.pkl' |
|
|
|
|
|
|
|
|
|
LAT_SMOOTH_SECONDS = 0.0 |
|
|
|
|
LONG_SMOOTH_SECONDS = 0.0 |
|
|
|
|
|
|
|
|
|
def smooth_value(val, prev_val, tau): |
|
|
|
|
alpha = 1 - np.exp(-DT_MDL / tau) if tau > 0 else 1 |
|
|
|
|
return alpha * val + (1 - alpha) * prev_val |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_action_from_model(model_output: dict[str, np.ndarray], prev_action: log.ModelDataV2.Action, |
|
|
|
|
lat_action_t: float, long_action_t: float,) -> log.ModelDataV2.Action: |
|
|
|
|
plan = model_output['plan'][0] |
|
|
|
|
desired_accel, should_stop = get_accel_from_plan(plan[:,Plan.VELOCITY][:,0], |
|
|
|
|
plan[:,Plan.ACCELERATION][:,0], |
|
|
|
|
ModelConstants.T_IDXS, |
|
|
|
|
action_t=long_action_t) |
|
|
|
|
desired_accel = smooth_value(desired_accel, prev_action.desiredAcceleration, LONG_SMOOTH_SECONDS) |
|
|
|
|
|
|
|
|
|
desired_curvature = model_output['desired_curvature'][0, 0] |
|
|
|
|
desired_curvature = smooth_value(desired_curvature, prev_action.desiredCurvature, LAT_SMOOTH_SECONDS) |
|
|
|
|
|
|
|
|
|
return log.ModelDataV2.Action(desiredCurvature=float(desired_curvature), |
|
|
|
|
desiredAcceleration=float(desired_accel), |
|
|
|
|
shouldStop=bool(should_stop)) |
|
|
|
|
|
|
|
|
|
class FrameMeta: |
|
|
|
|
frame_id: int = 0 |
|
|
|
|
timestamp_sof: int = 0 |
|
|
|
@ -221,7 +248,10 @@ def main(demo=False): |
|
|
|
|
cloudlog.info("modeld got CarParams: %s", CP.brand) |
|
|
|
|
|
|
|
|
|
# TODO this needs more thought, use .2s extra for now to estimate other delays |
|
|
|
|
steer_delay = CP.steerActuatorDelay + .2 |
|
|
|
|
# TODO Move smooth seconds to action function |
|
|
|
|
lat_delay = CP.steerActuatorDelay + .2 + LAT_SMOOTH_SECONDS |
|
|
|
|
long_delay = CP.longitudinalActuatorDelay + LONG_SMOOTH_SECONDS |
|
|
|
|
prev_action = log.ModelDataV2.Action() |
|
|
|
|
|
|
|
|
|
DH = DesireHelper() |
|
|
|
|
|
|
|
|
@ -263,7 +293,7 @@ def main(demo=False): |
|
|
|
|
is_rhd = sm["driverMonitoringState"].isRHD |
|
|
|
|
frame_id = sm["roadCameraState"].frameId |
|
|
|
|
v_ego = max(sm["carState"].vEgo, 0.) |
|
|
|
|
lateral_control_params = np.array([v_ego, steer_delay], dtype=np.float32) |
|
|
|
|
lateral_control_params = np.array([v_ego, lat_delay], dtype=np.float32) |
|
|
|
|
if sm.updated["liveCalibration"] and sm.seen['roadCameraState'] and sm.seen['deviceState']: |
|
|
|
|
device_from_calib_euler = np.array(sm["liveCalibration"].rpyCalib, dtype=np.float32) |
|
|
|
|
dc = DEVICE_CAMERAS[(str(sm['deviceState'].deviceType), str(sm['roadCameraState'].sensor))] |
|
|
|
@ -306,7 +336,9 @@ def main(demo=False): |
|
|
|
|
modelv2_send = messaging.new_message('modelV2') |
|
|
|
|
drivingdata_send = messaging.new_message('drivingModelData') |
|
|
|
|
posenet_send = messaging.new_message('cameraOdometry') |
|
|
|
|
fill_model_msg(drivingdata_send, modelv2_send, model_output, v_ego, steer_delay, |
|
|
|
|
|
|
|
|
|
action = get_action_from_model(model_output, prev_action, lat_delay + DT_MDL, long_delay + DT_MDL) |
|
|
|
|
fill_model_msg(drivingdata_send, modelv2_send, model_output, action, |
|
|
|
|
publish_state, meta_main.frame_id, meta_extra.frame_id, frame_id, |
|
|
|
|
frame_drop_ratio, meta_main.timestamp_eof, model_execution_time, live_calib_seen) |
|
|
|
|
|
|
|
|
|