Skip to content

Commit

Permalink
October 13th, 2024 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogAi committed Oct 13, 2024
1 parent 7363293 commit 5212c29
Show file tree
Hide file tree
Showing 61 changed files with 18 additions and 497 deletions.
4 changes: 2 additions & 2 deletions selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ def _get_params(ret, candidate, fingerprint, car_fw, disable_openpilot_long, exp

if params.get_bool("FrogsGoMoosTweak"):
if candidate in TSS2_CAR or ret.flags & ToyotaFlags.NEW_TOYOTA_TUNE:
tune.kiV = [0.3]
tune.kiV = [0.5]

ret.stoppingDecelRate = 0.01 # reach stopping target smoothly
ret.stoppingDecelRate = 0.1 # reach stopping target smoothly
ret.vEgoStopping = 0.15
ret.vEgoStarting = 0.15

Expand Down
10 changes: 0 additions & 10 deletions selfdrive/classic_modeld/modeld

This file was deleted.

366 changes: 0 additions & 366 deletions selfdrive/classic_modeld/modeld.py

This file was deleted.

3 changes: 0 additions & 3 deletions selfdrive/controls/lib/longcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ def update(self, active, CS, a_target, should_stop, accel_limits):
if output_accel > self.CP.stopAccel:
output_accel = min(output_accel, 0.0)
output_accel -= self.CP.stoppingDecelRate * DT_CTRL
elif output_accel < self.CP.stopAccel:
output_accel = min(output_accel, 0.0)
output_accel += self.CP.stoppingDecelRate * DT_CTRL
self.reset()

elif self.long_control_state == LongCtrlState.starting:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion selfdrive/frogpilot/frogpilot_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def update_frogpilot_params(self, started=True):
radarless_models = self.params.get("RadarlessModels", encoding='utf-8') or ""
toggle.radarless_model = radarless_models and toggle.model in radarless_models.split(',')
toggle.secretgoodopenpilot_model = toggle.model == "secret-good-openpilot"
toggle.secretgoodopenpilot_model_downloaded = os.path.exists(os.path.join(MODELS_PATH, "secret-good-openpilot.thneed"))
velocity_models = self.params.get("VelocityModels", encoding='utf-8') or ""
toggle.velocity_model = velocity_models and toggle.model in velocity_models.split(',')

Expand Down
5 changes: 0 additions & 5 deletions selfdrive/modeld/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ class ModelConstants:
HISTORY_BUFFER_LEN = 24
DESIRE_LEN = 8
TRAFFIC_CONVENTION_LEN = 2
NAV_FEATURE_LEN = 256
NAV_INSTRUCTION_LEN = 150
DRIVING_STYLE_LEN = 12
LAT_PLANNER_STATE_LEN = 4
LATERAL_CONTROL_PARAMS_LEN = 2
PREV_DESIRED_CURV_LEN = 1
RADAR_TRACKS_LEN = 64

# model outputs constants
FCW_THRESHOLDS_5MS2 = np.array([.05, .05, .15, .15, .15], dtype=np.float32)
Expand All @@ -44,7 +40,6 @@ class ModelConstants:
DESIRE_PRED_WIDTH = 8
LAT_PLANNER_SOLUTION_WIDTH = 4
DESIRED_CURV_WIDTH = 1
RADAR_TRACKS_WIDTH = 3

NUM_LANE_LINES = 4
NUM_ROAD_EDGES = 2
Expand Down
17 changes: 7 additions & 10 deletions selfdrive/modeld/fill_model_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

ConfidenceClass = log.ModelDataV2.ConfidenceClass


class PublishState:
def __init__(self):
self.disengage_buffer = np.zeros(ModelConstants.CONFIDENCE_BUFFER_LEN*ModelConstants.DISENGAGE_WIDTH, dtype=np.float32)
Expand Down Expand Up @@ -80,9 +79,7 @@ def fill_model_msg(base_msg: capnp._DynamicStructBuilder, extended_msg: capnp._D
modelV2.frameAge = frame_age
modelV2.frameDropPerc = frame_drop_perc
modelV2.timestampEof = timestamp_eof
modelV2.locationMonoTime = timestamp_llk
modelV2.modelExecutionTime = model_execution_time
modelV2.navEnabled = nav_enabled

# plan
position = modelV2.position
Expand Down Expand Up @@ -185,8 +182,8 @@ def fill_model_msg(base_msg: capnp._DynamicStructBuilder, extended_msg: capnp._D
meta.init('disengagePredictions')
disengage_predictions = meta.disengagePredictions
disengage_predictions.t = ModelConstants.META_T_IDXS
disengage_predictions.brakeDisengageProbs = net_output_data['meta'][0,Meta.BRAKE_DISENGAGE_GB if gas_brake else Meta.BRAKE_DISENGAGE_SECRET if secret_good_openpilot else Meta.BRAKE_DISENGAGE].tolist()
disengage_predictions.gasDisengageProbs = net_output_data['meta'][0,Meta.GAS_DISENGAGE_GB if gas_brake else Meta.GAS_DISENGAGE_SECRET if secret_good_openpilot else Meta.GAS_DISENGAGE].tolist()
disengage_predictions.brakeDisengageProbs = net_output_data['meta'][0,Meta.BRAKE_DISENGAGE].tolist()
disengage_predictions.gasDisengageProbs = net_output_data['meta'][0,Meta.GAS_DISENGAGE].tolist()
disengage_predictions.steerOverrideProbs = net_output_data['meta'][0,Meta.STEER_OVERRIDE].tolist()
disengage_predictions.brake3MetersPerSecondSquaredProbs = net_output_data['meta'][0,Meta.HARD_BRAKE_3].tolist()
disengage_predictions.brake4MetersPerSecondSquaredProbs = net_output_data['meta'][0,Meta.HARD_BRAKE_4].tolist()
Expand All @@ -195,19 +192,19 @@ def fill_model_msg(base_msg: capnp._DynamicStructBuilder, extended_msg: capnp._D
disengage_predictions.brakePressProbs = net_output_data['meta'][0,Meta.BRAKE_PRESS].tolist()

publish_state.prev_brake_5ms2_probs[:-1] = publish_state.prev_brake_5ms2_probs[1:]
publish_state.prev_brake_5ms2_probs[-1] = net_output_data['meta'][0,Meta.HARD_BRAKE_5_GB if gas_brake else Meta.BRAKE_DISENGAGE_SECRET if secret_good_openpilot else Meta.HARD_BRAKE_5][0]
publish_state.prev_brake_5ms2_probs[-1] = net_output_data['meta'][0,Meta.HARD_BRAKE_5][0]
publish_state.prev_brake_3ms2_probs[:-1] = publish_state.prev_brake_3ms2_probs[1:]
publish_state.prev_brake_3ms2_probs[-1] = net_output_data['meta'][0,Meta.HARD_BRAKE_3_GB if gas_brake else Meta.BRAKE_DISENGAGE_SECRET if secret_good_openpilot else Meta.HARD_BRAKE_3][0]
publish_state.prev_brake_3ms2_probs[-1] = net_output_data['meta'][0,Meta.HARD_BRAKE_3][0]
hard_brake_predicted = (publish_state.prev_brake_5ms2_probs > ModelConstants.FCW_THRESHOLDS_5MS2).all() and \
(publish_state.prev_brake_3ms2_probs > ModelConstants.FCW_THRESHOLDS_3MS2).all()
meta.hardBrakePredicted = hard_brake_predicted.item()

# confidence
if vipc_frame_id % (2*ModelConstants.MODEL_FREQ) == 0:
# any disengage prob
brake_disengage_probs = net_output_data['meta'][0,Meta.BRAKE_DISENGAGE_GB if gas_brake else Meta.BRAKE_DISENGAGE_SECRET if secret_good_openpilot else Meta.BRAKE_DISENGAGE]
gas_disengage_probs = net_output_data['meta'][0,Meta.GAS_DISENGAGE_GB if gas_brake else Meta.GAS_DISENGAGE_SECRET if secret_good_openpilot else Meta.GAS_DISENGAGE]
steer_override_probs = net_output_data['meta'][0,Meta.STEER_OVERRIDE_GB if gas_brake else Meta.STEER_OVERRIDE_SECRET if secret_good_openpilot else Meta.STEER_OVERRIDE]
brake_disengage_probs = net_output_data['meta'][0,Meta.BRAKE_DISENGAGE]
gas_disengage_probs = net_output_data['meta'][0,Meta.GAS_DISENGAGE]
steer_override_probs = net_output_data['meta'][0,Meta.STEER_OVERRIDE]
any_disengage_probs = 1-((1-brake_disengage_probs)*(1-gas_disengage_probs)*(1-steer_override_probs))
# independent disengage prob for each 2s slice
ind_disengage_probs = np.r_[any_disengage_probs[0], np.diff(any_disengage_probs) / (1 - any_disengage_probs[:-1])]
Expand Down
92 changes: 8 additions & 84 deletions selfdrive/modeld/modeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from cereal import car, log
from pathlib import Path
from setproctitle import setproctitle
from types import SimpleNamespace
from cereal.messaging import PubMaster, SubMaster
from msgq.visionipc import VisionIpcClient, VisionStreamType, VisionBuf
from openpilot.common.swaglog import cloudlog
Expand All @@ -25,40 +24,16 @@
from openpilot.selfdrive.modeld.constants import ModelConstants
from openpilot.selfdrive.modeld.models.commonmodel_pyx import ModelFrame, CLContext

from openpilot.selfdrive.frogpilot.frogpilot_functions import MODELS_PATH
from openpilot.selfdrive.frogpilot.frogpilot_variables import FrogPilotVariables

PROCESS_NAME = "selfdrive.modeld.modeld"
SEND_RAW_PRED = os.getenv('SEND_RAW_PRED')

MODEL_NAME = frogpilot_toggles.model

DISABLE_NAV = frogpilot_toggles.navigationless_model
DISABLE_POSE = frogpilot_toggles.poseless_model
DISABLE_RADAR = frogpilot_toggles.radarless_model
GAS_BRAKE = frogpilot_toggles.gas_brake_model
SECRET_GOOD_OPENPILOT = frogpilot_toggles.secretgoodopenpilot_model
USE_VELOCITY = frogpilot_toggles.velocity_model

MODEL_PATHS = {
ModelRunner.THNEED: Path(__file__).parent / ('models/supercombo.thneed' if MODEL_NAME == DEFAULT_MODEL else f'{MODELS_PATH}/{MODEL_NAME}.thneed'),
ModelRunner.THNEED: Path(__file__).parent / 'models/supercombo.thneed',
ModelRunner.ONNX: Path(__file__).parent / 'models/supercombo.onnx'}

metadata_file = (
'secret-good-openpilot_metadata.pkl' if SECRET_GOOD_OPENPILOT else
'gas-brake_metadata.pkl' if GAS_BRAKE else
'poseless_metadata.pkl' if DISABLE_POSE else
'classic_metadata.pkl'
)
METADATA_PATH = Path(__file__).parent / f'models/{metadata_file}'

MODEL_WIDTH = 512
MODEL_HEIGHT = 256
MODEL_FRAME_SIZE = MODEL_WIDTH * MODEL_HEIGHT * 3 // 2




METADATA_PATH = Path(__file__).parent / 'models/supercombo_metadata.pkl'


class FrameMeta:
Expand All @@ -78,11 +53,7 @@ class ModelState:
prev_desire: np.ndarray # for tracking the rising edge of the pulse
model: ModelRunner

def __init__(self, context: CLContext, frogpilot_toggles: SimpleNamespace):
# FrogPilot variables
if frogpilot_toggles.secretgoodopenpilot_model_downloaded:
MODEL_PATHS[ModelRunner.THNEED] = Path(__file__).parent / f'{MODELS_PATH}/secret-good-openpilot.thneed'

def __init__(self, context: CLContext):
self.frame = ModelFrame(context)
self.wide_frame = ModelFrame(context)
self.prev_desire = np.zeros(ModelConstants.DESIRE_LEN, dtype=np.float32)
Expand All @@ -92,21 +63,13 @@ def __init__(self, context: CLContext, frogpilot_toggles: SimpleNamespace):

# img buffers are managed in openCL transform code
self.inputs = {
'desire': np.zeros(ModelConstants.DESIRE_LEN * (ModelConstants.HISTORY_BUFFER_LEN_SECRET+1 if SECRET_GOOD_OPENPILOT else ModelConstants.HISTORY_BUFFER_LEN+1), dtype=np.float32),
'desire': np.zeros(ModelConstants.DESIRE_LEN * (ModelConstants.HISTORY_BUFFER_LEN+1), dtype=np.float32),
'traffic_convention': np.zeros(ModelConstants.TRAFFIC_CONVENTION_LEN, dtype=np.float32),
'lateral_control_params': np.zeros(ModelConstants.LATERAL_CONTROL_PARAMS_LEN, dtype=np.float32),
'prev_desired_curv': np.zeros(ModelConstants.PREV_DESIRED_CURV_LEN * (ModelConstants.HISTORY_BUFFER_LEN+1), dtype=np.float32),
**({'nav_features': np.zeros(ModelConstants.NAV_FEATURE_LEN, dtype=np.float32),
'nav_instructions': np.zeros(ModelConstants.NAV_INSTRUCTION_LEN, dtype=np.float32)} if not DISABLE_NAV else {}),
'features_buffer': np.zeros((ModelConstants.HISTORY_BUFFER_LEN_SECRET if SECRET_GOOD_OPENPILOT else ModelConstants.HISTORY_BUFFER_LEN) * ModelConstants.FEATURE_LEN, dtype=np.float32),
**({'radar_tracks': np.zeros(ModelConstants.RADAR_TRACKS_LEN * ModelConstants.RADAR_TRACKS_WIDTH, dtype=np.float32)} if DISABLE_RADAR else {}),
'features_buffer': np.zeros(ModelConstants.HISTORY_BUFFER_LEN * ModelConstants.FEATURE_LEN, dtype=np.float32),
}

self.input_imgs_20hz = np.zeros(MODEL_FRAME_SIZE*5, dtype=np.float32)
self.big_input_imgs_20hz = np.zeros(MODEL_FRAME_SIZE*5, dtype=np.float32)
self.input_imgs = np.zeros(MODEL_FRAME_SIZE*2, dtype=np.float32)
self.big_input_imgs = np.zeros(MODEL_FRAME_SIZE*2, dtype=np.float32)

with open(METADATA_PATH, 'rb') as f:
model_metadata = pickle.load(f)

Expand Down Expand Up @@ -148,7 +111,7 @@ def run(self, buf: VisionBuf, wbuf: VisionBuf, transform: np.ndarray, transform_
return None

self.model.execute()
outputs = self.parser.parse_outputs(self.slice_outputs(self.output), DISABLE_POSE)
outputs = self.parser.parse_outputs(self.slice_outputs(self.output))

self.full_features_20Hz[:-1] = self.full_features_20Hz[1:]
self.full_features_20Hz[-1] = outputs['hidden_state'][0, :]
Expand Down Expand Up @@ -180,7 +143,7 @@ def main(demo=False):
cloudlog.warning("setting up CL context")
cl_context = CLContext()
cloudlog.warning("CL context ready; loading model")
model = ModelState(cl_context, frogpilot_toggles)
model = ModelState(cl_context)
cloudlog.warning("models loaded, modeld starting")

# visionipc clients
Expand Down Expand Up @@ -222,8 +185,6 @@ def main(demo=False):
model_transform_main = np.zeros((3, 3), dtype=np.float32)
model_transform_extra = np.zeros((3, 3), dtype=np.float32)
live_calib_seen = False
nav_features = np.zeros(ModelConstants.NAV_FEATURE_LEN, dtype=np.float32)
nav_instructions = np.zeros(ModelConstants.NAV_INSTRUCTION_LEN, dtype=np.float32)
buf_main, buf_extra = None, None
meta_main = FrameMeta()
meta_extra = FrameMeta()
Expand All @@ -241,9 +202,6 @@ def main(demo=False):

DH = DesireHelper()

# FrogPilot variables
update_toggles = False

while True:
# Keep receiving frames until we are at least 1 frame ahead of previous extra frame
while meta_main.timestamp_sof < meta_extra.timestamp_sof + 25000000:
Expand Down Expand Up @@ -297,38 +255,6 @@ def main(demo=False):
if desire >= 0 and desire < ModelConstants.DESIRE_LEN:
vec_desire[desire] = 1

# Enable/disable nav features
timestamp_llk = sm["navModel"].locationMonoTime
nav_valid = sm.valid["navModel"] # and (nanos_since_boot() - timestamp_llk < 1e9)
nav_enabled = nav_valid and not DISABLE_NAV

if not nav_enabled:
nav_features[:] = 0
nav_instructions[:] = 0

if nav_enabled and sm.updated["navModel"]:
nav_features = np.array(sm["navModel"].features)

if nav_enabled and sm.updated["navInstruction"]:
nav_instructions[:] = 0
for maneuver in sm["navInstruction"].allManeuvers:
distance_idx = 25 + int(maneuver.distance / 20)
direction_idx = 0
if maneuver.modifier in ("left", "slight left", "sharp left"):
direction_idx = 1
if maneuver.modifier in ("right", "slight right", "sharp right"):
direction_idx = 2
if 0 <= distance_idx < 50:
nav_instructions[distance_idx*3 + direction_idx] = 1

radar_tracks = np.zeros(ModelConstants.RADAR_TRACKS_LEN * ModelConstants.RADAR_TRACKS_WIDTH, dtype=np.float32)
if sm.updated["liveTracks"]:
for i, track in enumerate(sm["liveTracks"]):
if i >= ModelConstants.RADAR_TRACKS_LEN:
break
vec_index = i * ModelConstants.RADAR_TRACKS_WIDTH
radar_tracks[vec_index:vec_index+ModelConstants.RADAR_TRACKS_WIDTH] = [track.dRel, track.yRel, track.vRel]

# tracked dropped frames
vipc_dropped_frames = max(0, meta_main.frame_id - last_vipc_frame_id - 1)
frames_dropped = frame_dropped_filter.update(min(vipc_dropped_frames, 10))
Expand All @@ -346,9 +272,7 @@ def main(demo=False):
'desire': vec_desire,
'traffic_convention': traffic_convention,
'lateral_control_params': lateral_control_params,
**({'nav_features': nav_features, 'nav_instructions': nav_instructions} if not DISABLE_NAV else {}),
**({'radar_tracks': radar_tracks,} if DISABLE_RADAR else {}),
}
}

mt1 = time.perf_counter()
model_output = model.run(buf_main, buf_extra, model_transform_main, model_transform_extra, inputs, prepare_only)
Expand Down
Binary file removed selfdrive/modeld/models/classic_metadata.pkl
Binary file not shown.
10 changes: 0 additions & 10 deletions selfdrive/modeld/models/commonmodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ uint8_t* ModelFrame::prepare(cl_mem yuv_cl, int frame_width, int frame_height, i
}
}

float* ModelFrame::prepareSecret(cl_mem yuv_cl, int frame_width, int frame_height, int frame_stride, int frame_uv_offset, const mat3 &projection, cl_mem *output) {
transform_queue(&this->transform, q,
yuv_cl, frame_width, frame_height, frame_stride, frame_uv_offset,
y_cl, u_cl, v_cl, MODEL_WIDTH, MODEL_HEIGHT, projection);
loadyuv_queue(&loadyuv, q, y_cl, u_cl, v_cl, net_input_cl);
CL_CHECK(clEnqueueReadBuffer(q, net_input_cl, CL_TRUE, 0, MODEL_FRAME_SIZE * sizeof(float), &frame[0], 0, nullptr, nullptr));
clFinish(q);
return &frame[0];
}

ModelFrame::~ModelFrame() {
transform_destroy(&transform);
loadyuv_destroy(&loadyuv);
Expand Down
1 change: 0 additions & 1 deletion selfdrive/modeld/models/commonmodel.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ cdef extern from "common/clutil.h":
cdef extern from "selfdrive/modeld/models/commonmodel.h":
cppclass ModelFrame:
int buf_size
int MODEL_FRAME_SIZE
ModelFrame(cl_device_id, cl_context)
unsigned char * prepare(cl_mem, int, int, int, int, mat3, cl_mem*)
Binary file removed selfdrive/modeld/models/gas-brake_metadata.pkl
Binary file not shown.
Binary file removed selfdrive/modeld/models/poseless_metadata.pkl
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion selfdrive/modeld/parse_model_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def parse_mdn(self, name, outs, in_N=0, out_N=1, out_shape=None):
outs[name] = pred_mu_final.reshape(final_shape)
outs[name + '_stds'] = pred_std_final.reshape(final_shape)

def parse_outputs(self, outs: dict[str, np.ndarray], disable_pose) -> dict[str, np.ndarray]:
def parse_outputs(self, outs: dict[str, np.ndarray]) -> dict[str, np.ndarray]:
self.parse_mdn('plan', outs, in_N=ModelConstants.PLAN_MHP_N, out_N=ModelConstants.PLAN_MHP_SELECTION,
out_shape=(ModelConstants.IDX_N,ModelConstants.PLAN_WIDTH))
self.parse_mdn('lane_lines', outs, in_N=0, out_N=0, out_shape=(ModelConstants.NUM_LANE_LINES,ModelConstants.IDX_N,ModelConstants.LANE_LINES_WIDTH))
Expand Down
4 changes: 0 additions & 4 deletions system/athena/manage_athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def main():

try:
while 1:
if dongle_id == "FrogsGoMoo":
time.sleep(60*60*24*365*100)
continue

cloudlog.info("starting athena daemon")
proc = Process(name='athenad', target=launcher, args=('system.athena.athenad', 'athenad'))
proc.start()
Expand Down

0 comments on commit 5212c29

Please sign in to comment.