Skip to content

Commit

Permalink
Merge branch 'master' into PA-dev2
Browse files Browse the repository at this point in the history
  • Loading branch information
Edison-CBS committed Sep 25, 2024
2 parents 2ed6fd0 + b4865dc commit 67ccbbd
Show file tree
Hide file tree
Showing 56 changed files with 1,163 additions and 711 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ui_preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
run: >-
sudo apt-get install -y imagemagick
scenes="homescreen settings_device settings_toggles offroad_alert update_available prime onroad onroad_sidebar onroad_wide onroad_wide_sidebar onroad_alert_small onroad_alert_mid onroad_alert_full driver_camera body keyboard"
scenes="homescreen settings_device settings_toggles offroad_alert update_available prime onroad onroad_disengaged onroad_override onroad_sidebar onroad_wide onroad_wide_sidebar onroad_alert_small onroad_alert_mid onroad_alert_full driver_camera body keyboard"
A=($scenes)
DIFF=""
Expand Down
2 changes: 1 addition & 1 deletion cereal/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -714,5 +714,5 @@ struct CarParams {
brakeMaxVDEPRECATED @16 :List(Float32);
directAccelControlDEPRECATED @30 :Bool;
maxSteeringAngleDegDEPRECATED @54 :Float32;
longitudinalActuatorDelayLowerBoundDEPRECATEDDEPRECATED @61 :Float32;
longitudinalActuatorDelayLowerBoundDEPRECATED @61 :Float32;
}
2 changes: 1 addition & 1 deletion cereal/log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,7 @@ struct Event {
uiDebug @102 :UIDebug;

# *********** debug ***********
testJoystick @52 :Joystick;
roadEncodeData @86 :EncodeData;
driverEncodeData @87 :EncodeData;
wideRoadEncodeData @88 :EncodeData;
Expand Down Expand Up @@ -2482,6 +2483,5 @@ struct Event {
uiPlanDEPRECATED @106 :UiPlan;
liveLocationKalmanDEPRECATED @72 :LiveLocationKalman;
liveTracksDEPRECATED @16 :List(LiveTracksDEPRECATED);
testJoystickDEPRECATED @52 :Joystick;
}
}
1 change: 1 addition & 0 deletions cereal/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, should_log: bool, frequency: float, decimation: Optional[int]

# debug
"uiDebug": (True, 0., 1),
"testJoystick": (True, 0.),
"alertDebug": (True, 20., 5),
"roadEncodeData": (False, 20.),
"driverEncodeData": (False, 20.),
Expand Down
4 changes: 2 additions & 2 deletions docs/CARS.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ A supported vehicle is one that just works when you install a comma device. All
|Volkswagen|Golf R 2015-19|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Golf R 2015-19">Buy Here</a></sub></details>||
|Volkswagen|Golf SportsVan 2015-20|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Golf SportsVan 2015-20">Buy Here</a></sub></details>||
|Volkswagen|Grand California 2019-24|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|31 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 angled mount (8 degrees)<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Grand California 2019-24">Buy Here</a></sub></details>|<a href="https://youtu.be/4100gLeabmo" target="_blank"><img height="18px" src="assets/icon-youtube.svg"></img></a>|
|Volkswagen|Jetta 2018-24|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Jetta 2018-24">Buy Here</a></sub></details>||
|Volkswagen|Jetta GLI 2021-24|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Jetta GLI 2021-24">Buy Here</a></sub></details>||
|Volkswagen|Jetta 2018-23|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Jetta 2018-23">Buy Here</a></sub></details>||
|Volkswagen|Jetta GLI 2021-23|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Jetta GLI 2021-23">Buy Here</a></sub></details>||
|Volkswagen|Passat 2015-22[<sup>10</sup>](#footnotes)|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Passat 2015-22">Buy Here</a></sub></details>||
|Volkswagen|Passat Alltrack 2015-22|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Passat Alltrack 2015-22">Buy Here</a></sub></details>||
|Volkswagen|Passat GTE 2015-22|Adaptive Cruise Control (ACC) & Lane Assist|openpilot available[<sup>1,12</sup>](#footnotes)|0 mph|0 mph|[![star](assets/icon-star-full.svg)](##)|[![star](assets/icon-star-full.svg)](##)|<details><summary>Parts</summary><sub>- 1 USB-C coupler<br>- 1 VW J533 connector<br>- 1 comma 3X<br>- 1 harness box<br>- 1 long OBD-C cable<br>- 1 mount<br>- 1 right angle OBD-C cable (1.5 ft)<br><a href="https://comma.ai/shop/comma-3x.html?make=Volkswagen&model=Passat GTE 2015-22">Buy Here</a></sub></details>||
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ All of these are examples of good PRs:

### First contribution

[Bounties](https://comma.ai/bounties) are the best place to get started.
[Projects / openpilot bounties](https://github.com/orgs/commaai/projects/26/views/1?pane=info) is the best place to get started and goes in-depth on what's expected when working on a bounty.
There's lot of bounties that don't require a comma 3/3X or a car.

## Pull Requests
Expand Down
31 changes: 24 additions & 7 deletions docs/car-porting/what-is-a-car-port.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
# What is a car port?

A car port enables openpilot support on a particular car. Each car model openpilot supports needs to be individually ported. All car ports live in `openpilot/selfdrive/car/car_specific.py` and `opendbc_repo/opendbc/car`.
A car port enables openpilot support on a particular car. Each car model openpilot supports needs to be individually ported. The complexity of a car port varies depending on many factors including:

The complexity of a car port varies depending on many factors including:
* existing openpilot support for similar cars
* architecture and APIs available in the car


# Structure of a car port

Virtually all car-specific code is contained in two other repositories: [opendbc](https://github.com/commaai/opendbc) and [panda](https://github.com/commaai/panda).

## opendbc

Each car brand is supported by a standard interface structure in `opendbc/car/[brand]`:

* `interface.py`: Interface for the car, defines the CarInterface class
* `carstate.py`: Reads CAN from car and builds openpilot CarState message
* `carcontroller.py`: Builds CAN messages to send to car
* `carstate.py`: Reads CAN messages from the car and builds openpilot CarState messages
* `carcontroller.py`: Control logic for executing openpilot CarControl actions on the car
* `[brand]can.py`: Composes CAN messages for carcontroller to send
* `values.py`: Limits for actuation, general constants for cars, and supported car documentation
* `radar_interface.py`: Interface for parsing radar points from the car
* `radar_interface.py`: Interface for parsing radar points from the car, if applicable

## panda

* `board/safety/safety_[brand].h`: Brand-specific safety logic
* `tests/safety/test_[brand].py`: Brand-specific safety CI tests

## openpilot

For historical reasons, openpilot still contains a small amount of car-specific logic. This will eventually be migrated to opendbc or otherwise removed.

* `selfdrive/car/car_specific.py`: Brand-specific event logic

# Overiew
# Overview

[Jason Young](https://github.com/jyoung8607) gave a talk at COMMA_CON with an overview of the car porting process. The talk is available on YouTube:

https://youtu.be/KcfzEHB6ms4?si=5szh1PX6TksOCKmM
https://www.youtube.com/watch?v=XxPS5TpTUnI
2 changes: 1 addition & 1 deletion panda
Submodule panda updated 90 files
+3 −1 SConscript
+7 −0 board/can.h
+6 −6 board/can_comms.h
+0 −5 board/can_declarations.h
+5 −12 board/critical.h
+17 −0 board/critical_declarations.h
+7 −6 board/drivers/bootkick.h
+5 −0 board/drivers/bootkick_declarations.h
+14 −12 board/drivers/bxcan.h
+22 −0 board/drivers/bxcan_declarations.h
+8 −43 board/drivers/can_common.h
+87 −0 board/drivers/can_common_declarations.h
+1 −2 board/drivers/clock_source.h
+7 −0 board/drivers/clock_source_declarations.h
+5 −5 board/drivers/fake_siren.h
+7 −16 board/drivers/fan.h
+20 −0 board/drivers/fan_declarations.h
+15 −26 board/drivers/fdcan.h
+28 −0 board/drivers/fdcan_declarations.h
+3 −26 board/drivers/harness.h
+34 −0 board/drivers/harness_declarations.h
+6 −24 board/drivers/interrupts.h
+31 −0 board/drivers/interrupts_declarations.h
+3 −13 board/drivers/registers.h
+24 −0 board/drivers/registers_declarations.h
+2 −7 board/drivers/simple_watchdog.h
+10 −0 board/drivers/simple_watchdog_declarations.h
+20 −43 board/drivers/spi.h
+52 −0 board/drivers/spi_declarations.h
+1 −1 board/drivers/timers.h
+9 −36 board/drivers/uart.h
+40 −0 board/drivers/uart_declarations.h
+240 −362 board/drivers/usb.h
+115 −0 board/drivers/usb_declarations.h
+1 −1 board/drivers/watchdog.h
+1 −1 board/early_init.h
+1 −35 board/faults.h
+43 −0 board/faults_declarations.h
+7 −0 board/flasher.h
+9 −5 board/main.c
+2 −2 board/main_comms.h
+10 −11 board/main_declarations.h
+15 −0 board/main_definitions.h
+2 −3 board/power_saving.h
+11 −0 board/power_saving_declarations.h
+2 −2 board/provision.h
+211 −156 board/safety.h
+10 −6 board/safety/safety_body.h
+123 −115 board/safety/safety_chrysler.h
+7 −2 board/safety/safety_defaults.h
+6 −1 board/safety/safety_elm327.h
+80 −73 board/safety/safety_ford.h
+66 −54 board/safety/safety_gm.h
+71 −57 board/safety/safety_honda.h
+51 −48 board/safety/safety_hyundai.h
+116 −113 board/safety/safety_hyundai_canfd.h
+27 −13 board/safety/safety_hyundai_common.h
+25 −22 board/safety/safety_mazda.h
+43 −39 board/safety/safety_nissan.h
+49 −50 board/safety/safety_subaru.h
+29 −26 board/safety/safety_subaru_preglobal.h
+67 −64 board/safety/safety_tesla.h
+77 −68 board/safety/safety_toyota.h
+7 −4 board/safety/safety_volkswagen_common.h
+43 −39 board/safety/safety_volkswagen_mqb.h
+39 −35 board/safety/safety_volkswagen_pq.h
+83 −68 board/safety_declarations.h
+5,884 −5,416 board/stm32f4/inc/stm32f413xx.h
+3 −21 board/stm32f4/llbxcan.h
+28 −0 board/stm32f4/llbxcan_declarations.h
+1 −1 board/stm32f4/llfan.h
+4 −3 board/stm32f4/llspi.h
+2 −7 board/stm32f4/lluart.h
+3 −14 board/stm32f4/llusb.h
+16 −0 board/stm32f4/llusb_declarations.h
+4 −0 board/stm32f4/peripherals.h
+2 −5 board/stm32f4/stm32f4_config.h
+1 −1 board/stm32h7/clock.h
+1 −1 board/stm32h7/lladc.h
+1 −1 board/stm32h7/llfan.h
+5 −47 board/stm32h7/llfdcan.h
+53 −0 board/stm32h7/llfdcan_declarations.h
+6 −3 board/stm32h7/llspi.h
+3 −3 board/stm32h7/lluart.h
+3 −15 board/stm32h7/llusb.h
+16 −0 board/stm32h7/llusb_declarations.h
+4 −0 board/stm32h7/peripherals.h
+2 −5 board/stm32h7/stm32h7_config.h
+2 −2 tests/libpanda/panda.c
+0 −6 tests/misra/suppressions.txt
19 changes: 0 additions & 19 deletions selfdrive/car/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions selfdrive/controls/lib/drive_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def clip_curvature(v_ego, prev_curvature, new_curvature):

def get_speed_error(modelV2: log.ModelDataV2, v_ego: float) -> float:
# ToDo: Try relative error, and absolute speed
if len(modelV2.temporalPose.trans):
vel_err = clip(modelV2.temporalPose.trans[0] - v_ego, -MAX_VEL_ERR, MAX_VEL_ERR)
if len(modelV2.velocity.x):
vel_err = clip(modelV2.velocity.x[0] - v_ego, -MAX_VEL_ERR, MAX_VEL_ERR)
return float(vel_err)
return 0.0
4 changes: 2 additions & 2 deletions selfdrive/controls/radard.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def update(self, sm: messaging.SubMaster, rr: car.RadarData):
self.radar_state.radarErrors = list(rr.errors)
self.radar_state.carStateMonoTime = sm.logMonoTime['carState']

if len(sm['modelV2'].temporalPose.trans):
model_v_ego = sm['modelV2'].temporalPose.trans[0]
if len(sm['modelV2'].velocity.x):
model_v_ego = sm['modelV2'].velocity.x[0]
else:
model_v_ego = self.v_ego
leads_v3 = sm['modelV2'].leadsV3
Expand Down
24 changes: 12 additions & 12 deletions selfdrive/modeld/dmonitoringmodeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from openpilot.common.params import Params
from openpilot.common.realtime import set_realtime_priority
from openpilot.selfdrive.modeld.runners import ModelRunner, Runtime
from openpilot.selfdrive.modeld.models.commonmodel_pyx import sigmoid
from openpilot.selfdrive.modeld.parse_model_outputs import sigmoid

CALIB_LEN = 3
REG_SCALE = 0.25
Expand Down Expand Up @@ -88,15 +88,15 @@ def fill_driver_state(msg, ds_result: DriverStateResult):
msg.faceOrientationStd = [math.exp(x) for x in ds_result.face_orientation_std]
msg.facePosition = [x * REG_SCALE for x in ds_result.face_position[:2]]
msg.facePositionStd = [math.exp(x) for x in ds_result.face_position_std[:2]]
msg.faceProb = sigmoid(ds_result.face_prob)
msg.leftEyeProb = sigmoid(ds_result.left_eye_prob)
msg.rightEyeProb = sigmoid(ds_result.right_eye_prob)
msg.leftBlinkProb = sigmoid(ds_result.left_blink_prob)
msg.rightBlinkProb = sigmoid(ds_result.right_blink_prob)
msg.sunglassesProb = sigmoid(ds_result.sunglasses_prob)
msg.occludedProb = sigmoid(ds_result.occluded_prob)
msg.readyProb = [sigmoid(x) for x in ds_result.ready_prob]
msg.notReadyProb = [sigmoid(x) for x in ds_result.not_ready_prob]
msg.faceProb = float(sigmoid(ds_result.face_prob))
msg.leftEyeProb = float(sigmoid(ds_result.left_eye_prob))
msg.rightEyeProb = float(sigmoid(ds_result.right_eye_prob))
msg.leftBlinkProb = float(sigmoid(ds_result.left_blink_prob))
msg.rightBlinkProb = float(sigmoid(ds_result.right_blink_prob))
msg.sunglassesProb = float(sigmoid(ds_result.sunglasses_prob))
msg.occludedProb = float(sigmoid(ds_result.occluded_prob))
msg.readyProb = [float(sigmoid(x)) for x in ds_result.ready_prob]
msg.notReadyProb = [float(sigmoid(x)) for x in ds_result.not_ready_prob]

def get_driverstate_packet(model_output: np.ndarray, frame_id: int, location_ts: int, execution_time: float, dsp_execution_time: float):
model_result = ctypes.cast(model_output.ctypes.data, ctypes.POINTER(DMonitoringModelResult)).contents
Expand All @@ -105,8 +105,8 @@ def get_driverstate_packet(model_output: np.ndarray, frame_id: int, location_ts:
ds.frameId = frame_id
ds.modelExecutionTime = execution_time
ds.dspExecutionTime = dsp_execution_time
ds.poorVisionProb = sigmoid(model_result.poor_vision_prob)
ds.wheelOnRightProb = sigmoid(model_result.wheel_on_right_prob)
ds.poorVisionProb = float(sigmoid(model_result.poor_vision_prob))
ds.wheelOnRightProb = float(sigmoid(model_result.wheel_on_right_prob))
ds.rawPredictions = model_output.tobytes() if SEND_RAW_PRED else b''
fill_driver_state(ds.leftDriverData, model_result.driver_state_lhd)
fill_driver_state(ds.rightDriverData, model_result.driver_state_rhd)
Expand Down
7 changes: 0 additions & 7 deletions selfdrive/modeld/fill_model_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@ def fill_model_msg(base_msg: capnp._DynamicStructBuilder, extended_msg: capnp._D
(publish_state.prev_brake_3ms2_probs > ModelConstants.FCW_THRESHOLDS_3MS2).all()
meta.hardBrakePredicted = hard_brake_predicted.item()

# temporal pose
temporal_pose = modelV2.temporalPose
temporal_pose.trans = net_output_data['sim_pose'][0,:3].tolist()
temporal_pose.transStd = net_output_data['sim_pose_stds'][0,:3].tolist()
temporal_pose.rot = net_output_data['sim_pose'][0,3:].tolist()
temporal_pose.rotStd = net_output_data['sim_pose_stds'][0,3:].tolist()

# confidence
if vipc_frame_id % (2*ModelConstants.MODEL_FREQ) == 0:
# any disengage prob
Expand Down
6 changes: 1 addition & 5 deletions selfdrive/modeld/models/commonmodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,4 @@ ModelFrame::~ModelFrame() {
CL_CHECK(clReleaseMemObject(u_cl));
CL_CHECK(clReleaseMemObject(y_cl));
CL_CHECK(clReleaseCommandQueue(q));
}

float sigmoid(float input) {
return 1 / (1 + expf(-input));
}
}
2 changes: 0 additions & 2 deletions selfdrive/modeld/models/commonmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include "selfdrive/modeld/transforms/loadyuv.h"
#include "selfdrive/modeld/transforms/transform.h"

float sigmoid(float input);

class ModelFrame {
public:
ModelFrame(cl_device_id device_id, cl_context context);
Expand Down
2 changes: 0 additions & 2 deletions selfdrive/modeld/models/commonmodel.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ cdef extern from "common/clutil.h":
cl_context cl_create_context(cl_device_id)

cdef extern from "selfdrive/modeld/models/commonmodel.h":
float sigmoid(float)

cppclass ModelFrame:
int buf_size
ModelFrame(cl_device_id, cl_context)
Expand Down
4 changes: 1 addition & 3 deletions selfdrive/modeld/models/commonmodel_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ from libc.string cimport memcpy
from msgq.visionipc.visionipc cimport cl_mem
from msgq.visionipc.visionipc_pyx cimport VisionBuf, CLContext as BaseCLContext
from .commonmodel cimport CL_DEVICE_TYPE_DEFAULT, cl_get_device_id, cl_create_context
from .commonmodel cimport mat3, sigmoid as cppSigmoid, ModelFrame as cppModelFrame
from .commonmodel cimport mat3, ModelFrame as cppModelFrame

def sigmoid(x):
return cppSigmoid(x)

cdef class CLContext(BaseCLContext):
def __cinit__(self):
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/modeld/models/supercombo.onnx
Git LFS file not shown
13 changes: 8 additions & 5 deletions selfdrive/modeld/parse_model_outputs.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import numpy as np
from openpilot.selfdrive.modeld.constants import ModelConstants

def safe_exp(x, out=None):
# -11 is around 10**14, more causes float16 overflow
return np.exp(np.clip(x, -np.inf, 11), out=out)

def sigmoid(x):
return 1. / (1. + np.exp(-x))
return 1. / (1. + safe_exp(-x))

def softmax(x, axis=-1):
x -= np.max(x, axis=axis, keepdims=True)
if x.dtype == np.float32 or x.dtype == np.float64:
np.exp(x, out=x)
safe_exp(x, out=x)
else:
x = np.exp(x)
x = safe_exp(x)
x /= np.sum(x, axis=axis, keepdims=True)
return x

Expand Down Expand Up @@ -44,7 +48,7 @@ def parse_mdn(self, name, outs, in_N=0, out_N=1, out_shape=None):

n_values = (raw.shape[2] - out_N)//2
pred_mu = raw[:,:,:n_values]
pred_std = np.exp(raw[:,:,n_values: 2*n_values])
pred_std = safe_exp(raw[:,:,n_values: 2*n_values])

if in_N > 1:
weights = np.zeros((raw.shape[0], in_N, out_N), dtype=raw.dtype)
Expand Down Expand Up @@ -87,7 +91,6 @@ def parse_outputs(self, outs: dict[str, np.ndarray]) -> dict[str, np.ndarray]:
self.parse_mdn('road_edges', outs, in_N=0, out_N=0, out_shape=(ModelConstants.NUM_ROAD_EDGES,ModelConstants.IDX_N,ModelConstants.LANE_LINES_WIDTH))
self.parse_mdn('pose', outs, in_N=0, out_N=0, out_shape=(ModelConstants.POSE_WIDTH,))
self.parse_mdn('road_transform', outs, in_N=0, out_N=0, out_shape=(ModelConstants.POSE_WIDTH,))
self.parse_mdn('sim_pose', outs, in_N=0, out_N=0, out_shape=(ModelConstants.POSE_WIDTH,))
self.parse_mdn('wide_from_device_euler', outs, in_N=0, out_N=0, out_shape=(ModelConstants.WIDE_FROM_DEVICE_WIDTH,))
self.parse_mdn('lead', outs, in_N=ModelConstants.LEAD_MHP_N, out_N=ModelConstants.LEAD_MHP_SELECTION,
out_shape=(ModelConstants.LEAD_TRAJ_LEN,ModelConstants.LEAD_WIDTH))
Expand Down
Loading

0 comments on commit 67ccbbd

Please sign in to comment.