forked from commaai/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controlsd: pull out LDW (commaai#33479)
* controlsd: pull out LDW * cleanup * good ol mypy
- Loading branch information
1 parent
77f4f57
commit 73d31d5
Showing
2 changed files
with
57 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from cereal import log | ||
from openpilot.common.realtime import DT_CTRL | ||
from openpilot.common.conversions import Conversions as CV | ||
|
||
|
||
CAMERA_OFFSET = 0.04 | ||
LDW_MIN_SPEED = 31 * CV.MPH_TO_MS | ||
LANE_DEPARTURE_THRESHOLD = 0.1 | ||
|
||
class LaneDepartureWarning: | ||
def __init__(self): | ||
self.left = False | ||
self.right = False | ||
self.last_blinker_frame = 0 | ||
|
||
def update(self, frame, modelV2, CS, CC): | ||
if CS.leftBlinker or CS.rightBlinker: | ||
self.last_blinker_frame = frame | ||
|
||
recent_blinker = (frame - self.last_blinker_frame) * DT_CTRL < 5.0 # 5s blinker cooldown | ||
ldw_allowed = CS.vEgo > LDW_MIN_SPEED and not recent_blinker and not CC.latActive | ||
|
||
desire_prediction = modelV2.meta.desirePrediction | ||
if len(desire_prediction) and ldw_allowed: | ||
right_lane_visible = modelV2.laneLineProbs[2] > 0.5 | ||
left_lane_visible = modelV2.laneLineProbs[1] > 0.5 | ||
l_lane_change_prob = desire_prediction[log.Desire.laneChangeLeft] | ||
r_lane_change_prob = desire_prediction[log.Desire.laneChangeRight] | ||
|
||
lane_lines = modelV2.laneLines | ||
l_lane_close = left_lane_visible and (lane_lines[1].y[0] > -(1.08 + CAMERA_OFFSET)) | ||
r_lane_close = right_lane_visible and (lane_lines[2].y[0] < (1.08 - CAMERA_OFFSET)) | ||
|
||
self.left = bool(l_lane_change_prob > LANE_DEPARTURE_THRESHOLD and l_lane_close) | ||
self.right = bool(r_lane_change_prob > LANE_DEPARTURE_THRESHOLD and r_lane_close) | ||
else: | ||
self.left, self.right = False, False | ||
|
||
@property | ||
def warning(self) -> bool: | ||
return bool(self.left or self.right) |