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
| class EmergencyStopFunction: """ ESF 紧急停车功能 Euro NCAP 2026 合规实现 """ def __init__(self, config: Dict): self.phase1_duration = config.get('phase1_duration', 3.0) self.phase2_duration = config.get('phase2_duration', 5.0) self.deceleration = config.get('deceleration', 3.0) self.state = 'normal' self.state_start_time = None self.adas_interface = ADASInterface() def update(self, is_unresponsive: bool, driver_input: bool, current_time: float) -> Dict: """ 更新状态机 Args: is_unresponsive: 是否检测到无响应 driver_input: 是否有驾驶员输入 current_time: 当前时间 Returns: action: 系统动作 """ if self.state == 'normal': if is_unresponsive: self.state = 'phase1_warning' self.state_start_time = current_time return {'action': 'phase1_warning', 'sound': True, 'visual': True} return {'action': 'none'} elif self.state == 'phase1_warning': elapsed = current_time - self.state_start_time if driver_input: self.state = 'normal' return {'action': 'cancel', 'reason': 'driver_responded'} if elapsed > self.phase1_duration: self.state = 'phase2_warning' self.state_start_time = current_time return {'action': 'phase2_warning', 'sound': True, 'visual': True, 'vibration': True} return {'action': 'continue_phase1'} elif self.state == 'phase2_warning': elapsed = current_time - self.state_start_time if driver_input: self.state = 'normal' return {'action': 'cancel', 'reason': 'driver_responded'} if elapsed > self.phase2_duration: self.state = 'emergency_stop' self.state_start_time = current_time return self._initiate_stop(current_time) return {'action': 'continue_phase2'} elif self.state == 'emergency_stop': return self._execute_stop(current_time) return {'action': 'none'} def _initiate_stop(self, current_time: float) -> Dict: """启动紧急停车""" self.adas_interface.set_hazard_lights(True) self.adas_interface.apply_brakes(self.deceleration) return { 'action': 'emergency_stop_initiated', 'hazard_lights': True, 'braking': True, 'deceleration': self.deceleration } def _execute_stop(self, current_time: float) -> Dict: """执行紧急停车""" vehicle_speed = self.adas_interface.get_speed() if vehicle_speed < 0.5: self.adas_interface.unlock_doors() self.adas_interface.call_emergency_services() return { 'action': 'vehicle_stopped', 'doors_unlocked': True, 'emergency_call': True } return { 'action': 'braking', 'current_speed': vehicle_speed }
class ADASInterface: """ADAS 接口(模拟)""" def __init__(self): self.speed = 30.0 self.braking = False def set_hazard_lights(self, on: bool): """设置危险警报灯""" pass def apply_brakes(self, deceleration: float): """施加制动""" self.braking = True def get_speed(self) -> float: """获取车速""" if self.braking: self.speed = max(0, self.speed - 0.1) return self.speed def unlock_doors(self): """解锁车门""" pass def call_emergency_services(self): """呼叫紧急服务""" pass
|