1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| """ BMW Symbiotic Drive 驾驶员意图推断模型
核心思路: 1. 融合方向盘、眼神、转向灯、身体姿态 2. 判断当前操作是"刻意"还是"无意识" 3. 刻意 → 抑制系统干预 4. 无意识 → 触发警告/干预 """
import numpy as np from dataclasses import dataclass from typing import Optional, List from enum import Enum
class DriverIntent(Enum): DELIBERATE_LANE_CHANGE = "deliberate_lane_change" UNCONSCIOUS_DEVIATION = "unconscious_deviation" EMERGENCY_AVOIDANCE = "emergency_avoidance" NORMAL_DRIVING = "normal_driving" PARKING = "parking"
@dataclass class IntentSignals: """多模态意图信号""" steering_angle: float steering_velocity: float steering_jerk: float gaze_zone: str gaze_on_mirror: bool gaze_on_blind_spot: bool turn_signal_active: bool turn_signal_direction: str shoulder_check: bool body_rotation: float lane_departure: bool vehicle_speed: float time_to_lane_crossing: float
class DriverIntentInference: """ 驾驶员意图推断引擎 BMW Symbiotic Drive 核心逻辑: - 转向灯 + 肩部检查 + 眼神看盲区 → 刻意变道,抑制警告 - 无转向灯 + 无肩部检查 + 无眼神移动 → 无意识偏离,触发警告 - 急打方向 + 前方有障碍 → 紧急避险,增强辅助 """ def __init__(self): self.deliberate_threshold = 0.7 self.emergency_steering_vel = 300 self.lane_crossing_time_threshold = 2.0 def infer(self, signals: IntentSignals) -> dict: """推断驾驶员意图""" intent_scores = { DriverIntent.DELIBERATE_LANE_CHANGE: 0.0, DriverIntent.UNCONSCIOUS_DEVIATION: 0.0, DriverIntent.EMERGENCY_AVOIDANCE: 0.0, DriverIntent.NORMAL_DRIVING: 0.0, DriverIntent.PARKING: 0.0, } score = 0.0 if signals.turn_signal_active: score += 0.35 if signals.shoulder_check: score += 0.25 if signals.gaze_on_blind_spot: score += 0.25 if signals.gaze_on_mirror: score += 0.15 if abs(signals.steering_velocity) > 10 and abs(signals.steering_jerk) < 50: score += 0.15 intent_scores[DriverIntent.DELIBERATE_LANE_CHANGE] = min(1.0, score) score = 0.0 if signals.lane_departure: score += 0.3 if not signals.turn_signal_active: score += 0.25 if not signals.shoulder_check: score += 0.2 if signals.gaze_zone == 'phone' or signals.gaze_zone == 'infotainment': score += 0.25 if signals.time_to_lane_crossing < self.lane_crossing_time_threshold: score += 0.2 intent_scores[DriverIntent.UNCONSCIOUS_DEVIATION] = min(1.0, score) score = 0.0 if abs(signals.steering_velocity) > self.emergency_steering_vel: score += 0.5 if abs(signals.steering_jerk) > 100: score += 0.3 if signals.vehicle_speed > 60: score += 0.2 intent_scores[DriverIntent.EMERGENCY_AVOIDANCE] = min(1.0, score) score = 0.3 if not signals.lane_departure: score += 0.3 if signals.gaze_zone == 'road': score += 0.2 if abs(signals.steering_velocity) < 15: score += 0.2 intent_scores[DriverIntent.NORMAL_DRIVING] = min(1.0, score) if signals.vehicle_speed < 10: intent_scores[DriverIntent.PARKING] = 0.8 for k in intent_scores: intent_scores[k] *= 0.5 total = sum(intent_scores.values()) if total > 0: for k in intent_scores: intent_scores[k] /= total best_intent = max(intent_scores, key=intent_scores.get) confidence = intent_scores[best_intent] if best_intent == DriverIntent.DELIBERATE_LANE_CHANGE and confidence > self.deliberate_threshold: action = "SUPPRESS_WARNING" elif best_intent == DriverIntent.UNCONSCIOUS_DEVIATION: action = "TRIGGER_WARNING" elif best_intent == DriverIntent.EMERGENCY_AVOIDANCE: action = "ASSIST_EMERGENCY" else: action = "MONITOR" return { 'intent': best_intent.value, 'confidence': confidence, 'all_scores': {k.value: v for k, v in intent_scores.items()}, 'action': action, }
if __name__ == "__main__": engine = DriverIntentInference() s1 = IntentSignals( steering_angle=15, steering_velocity=20, steering_jerk=30, gaze_zone='blind_spot', gaze_on_mirror=False, gaze_on_blind_spot=True, turn_signal_active=True, turn_signal_direction='left', shoulder_check=True, body_rotation=25, lane_departure=False, vehicle_speed=80, time_to_lane_crossing=5 ) r1 = engine.infer(s1) print(f"刻意变道: {r1['intent']}, conf={r1['confidence']:.2%}, action={r1['action']}") s2 = IntentSignals( steering_angle=5, steering_velocity=8, steering_jerk=15, gaze_zone='phone', gaze_on_mirror=False, gaze_on_blind_spot=False, turn_signal_active=False, turn_signal_direction='none', shoulder_check=False, body_rotation=0, lane_departure=True, vehicle_speed=70, time_to_lane_crossing=1.5 ) r2 = engine.infer(s2) print(f"无意识偏离: {r2['intent']}, conf={r2['confidence']:.2%}, action={r2['action']}") s3 = IntentSignals( steering_angle=45, steering_velocity=350, steering_jerk=200, gaze_zone='road', gaze_on_mirror=False, gaze_on_blind_spot=False, turn_signal_active=False, turn_signal_direction='none', shoulder_check=False, body_rotation=0, lane_departure=False, vehicle_speed=90, time_to_lane_crossing=10 ) r3 = engine.infer(s3) print(f"紧急避险: {r3['intent']}, conf={r3['confidence']:.2%}, action={r3['action']}")
|