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
| """ 铁路DMS vs 汽车DMS架构对比 Elron铁路方案 → IMS启发
关键差异: - 铁路: 固定路线+长直道+低频率操作→疲劳风险更高 - 汽车: 复杂路况+高频操作→分心风险更高 - 铁路: 可自动停车(安全), 汽车AEB(风险) - 铁路: 单人驾驶室, 汽车多乘员 """
from dataclasses import dataclass from typing import Tuple
@dataclass class RailwayDMSConfig: """铁路DMS配置 (基于Elron方案)""" monitoring = { 'camera_type': 'IR+RGB dual', 'fps': 30, 'detection_functions': [ 'eyelid_closure', 'head_nodding', 'gaze_away', 'phone_use', 'absence', ], 'alert_threshold_sec': 2.0, 'auto_brake_threshold_sec': 5.0, 'auto_stop_threshold_sec': 10.0, } intervention_levels = [ {'level': 0, 'action': 'none', 'condition': '正常驾驶'}, {'level': 1, 'action': 'audio_warning', 'condition': '注意力丢失>2s'}, {'level': 2, 'action': 'visual_alert', 'condition': '未响应>4s'}, {'level': 3, 'action': 'auto_deceleration', 'condition': '未响应>5s'}, {'level': 4, 'action': 'auto_stop', 'condition': '未响应>10s'}, {'level': 5, 'action': 'emergency_stop', 'condition': '驾驶员离位'}, ] railway_specific = { 'long_straight_monitoring': '长直道更容易疲劳', 'signal_attention': '信号灯识别注意力', 'platform_stops': '站台停车精度', 'speed_limit_compliance': '限速遵守', 'emergency_response': '紧急情况响应', }
class RailwayDMSController: """ 铁路DMS控制器 状态机: Normal → Warning → Alert → Decelerate → Stop → Emergency """ def __init__(self): self.config = RailwayDMSConfig() self.state = 'normal' self.attention_lost_time = 0 def update(self, dms_output, dt=1.0): """ 更新状态机 Args: dms_output: dict with 'attention', 'eyes_closed', 'head_nod', 'gaze_zone', 'absent' dt: 时间步长 (秒) Returns: action: 当前干预级别 """ attention_lost = ( dms_output.get('eyes_closed', False) or dms_output.get('head_nod', False) or dms_output.get('gaze_zone') == 'away' or dms_output.get('absent', False) ) if attention_lost: self.attention_lost_time += dt else: self.attention_lost_time = 0 self.state = 'normal' return {'level': 0, 'action': 'none'} t = self.attention_lost_time if dms_output.get('absent', False): self.state = 'emergency' return {'level': 5, 'action': 'emergency_stop'} elif t >= 10: self.state = 'auto_stop' return {'level': 4, 'action': 'auto_stop'} elif t >= 5: self.state = 'decelerate' return {'level': 3, 'action': 'auto_deceleration'} elif t >= 4: self.state = 'visual_alert' return {'level': 2, 'action': 'visual_alert'} elif t >= 2: self.state = 'warning' return {'level': 1, 'action': 'audio_warning'} else: return {'level': 0, 'action': 'none'}
if __name__ == "__main__": controller = RailwayDMSController() config = RailwayDMSConfig() print("=" * 60) print("Elron铁路DMS 状态机仿真") print("=" * 60) print(f"\n监测功能:") for f in config.monitoring['detection_functions']: print(f" ✅ {f}") print(f"\n干预级别:") for lv in config.intervention_levels: print(f" L{lv['level']}: {lv['action']} ({lv['condition']})") print(f"\n--- 场景: 驾驶员逐渐打瞌睡 ---") timeline = [ (0, '正常驾驶'), (1, '开始闭眼'), (2, '闭眼持续'), (3, '⚠️ 警告'), (4, '⚠️ 视觉警报'), (5, '🚂 自动减速'), (8, '🚂 减速中'), (10, '🛑 自动停车'), (12, '🛑 已停车'), ] for t, desc in timeline: if t < 1: dms = {'eyes_closed': False, 'gaze_zone': 'forward'} elif t < 10: dms = {'eyes_closed': True, 'gaze_zone': 'away'} else: dms = {'eyes_closed': True, 'gaze_zone': 'away'} result = controller.update(dms, dt=1.0) print(f" t={t:2d}s: {desc:<20} → L{result['level']} {result['action']}") print(f"\n{'='*60}") print(f"铁路 vs 汽车DMS 干预对比:") print(f"{'场景':<20} {'铁路DMS':<25} {'汽车DMS':<25}") print(f"{'-'*70}") print(f"{'注意力丢失2s':<20} {'音频警告':<25} {'一级警告':<25}") print(f"{'未响应5s':<20} {'自动减速':<25} {'二级警告+ADAS':<25}") print(f"{'未响应10s':<20} {'自动停车':<25} {'AEB紧急制动':<25}") print(f"{'驾驶员离位':<20} {'紧急停车':<25} {'无法检测(单人)':<25}")
|