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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
| import numpy as np from typing import Dict, Tuple from dataclasses import dataclass
@dataclass class OccupantInfo: """乘员信息""" category: str weight_estimate: float confidence: float position: Tuple[float, float]
class OccupantClassifier: """ 多传感器乘员分类器 传感器融合: 1. 压力传感器阵列(座椅底部) 2. 电容传感器(座椅表面) 3. 摄像头(车内OMS) 输出:乘员类型 + 置信度 """ def __init__(self): self.weight_thresholds = { 'empty': 5, 'child_seat': 15, 'child': 50, 'adult_female': 75, 'adult_male': float('inf') } self.nn_classifier = self._build_classifier() def _build_classifier(self): """构建神经网络分类器""" import torch.nn as nn model = nn.Sequential( nn.Linear(128, 64), nn.ReLU(), nn.Dropout(0.3), nn.Linear(64, 32), nn.ReLU(), nn.Linear(32, 5), nn.Softmax(dim=-1) ) return model def classify(self, pressure_data: np.ndarray, capacitive_data: np.ndarray, camera_features: np.ndarray) -> OccupantInfo: """ 多传感器融合分类 Args: pressure_data: (N,) 压力传感器阵列数据 capacitive_data: (M,) 电容传感器数据 camera_features: (K,) 摄像头特征 Returns: OccupantInfo: 乘员信息 """ total_weight = np.sum(pressure_data) * 0.1 pressure_2d = pressure_data.reshape(8, 8) center_x = np.sum(np.arange(8) * np.sum(pressure_2d, axis=0)) / (total_weight + 1e-6) center_y = np.sum(np.arange(8) * np.sum(pressure_2d, axis=1)) / (total_weight + 1e-6) capacitive_score = np.mean(capacitive_data) is_human = capacitive_score > 0.5 has_child_seat = camera_features[0] > 0.8 if len(camera_features) > 0 else False if total_weight < self.weight_thresholds['empty']: category = 'empty' confidence = 0.95 elif has_child_seat: category = 'child_seat' confidence = 0.9 elif not is_human and total_weight > self.weight_thresholds['empty']: category = 'child_seat' confidence = 0.7 elif total_weight < self.weight_thresholds['child_seat']: category = 'child_seat' confidence = 0.8 elif total_weight < self.weight_thresholds['child']: category = 'child' confidence = 0.85 elif total_weight < self.weight_thresholds['adult_female']: category = 'adult_female' confidence = 0.85 else: category = 'adult_male' confidence = 0.85 return OccupantInfo( category=category, weight_estimate=total_weight, confidence=confidence, position=(center_x / 8, center_y / 8) )
class AdaptiveRestraintController: """ 自适应约束控制器 根据乘员分类结果调整: 1. 气囊展开压力 2. 气囊展开时间 3. 安全带预紧力度 """ def __init__(self): self.airbag_configs = { 'empty': { 'deploy': False, 'pressure': 0, 'timing': 0 }, 'child_seat': { 'deploy': False, 'pressure': 0, 'timing': 0 }, 'child': { 'deploy': False, 'pressure': 0, 'timing': 0 }, 'adult_female': { 'deploy': True, 'pressure': 0.7, 'timing': 15 }, 'adult_male': { 'deploy': True, 'pressure': 1.0, 'timing': 0 } } self.seatbelt_configs = { 'empty': {'pretension': 0}, 'child_seat': {'pretension': 0}, 'child': {'pretension': 0.8}, 'adult_female': {'pretension': 0.9}, 'adult_male': {'pretension': 1.0} } def get_restraint_config(self, occupant: OccupantInfo) -> Dict: """ 获取约束配置 Args: occupant: 乘员信息 Returns: config: 约束参数配置 """ airbag_config = self.airbag_configs.get(occupant.category, self.airbag_configs['adult_male']) seatbelt_config = self.seatbelt_configs.get(occupant.category, self.seatbelt_configs['adult_male']) position_adjustment = self._calculate_position_adjustment(occupant.position) return { 'airbag': { **airbag_config, 'pressure': airbag_config['pressure'] * position_adjustment['pressure_factor'] }, 'seatbelt': seatbelt_config, 'occupant': occupant } def _calculate_position_adjustment(self, position: Tuple[float, float]) -> Dict: """ 计算位置调整因子 离位乘员(OOP)需要特殊处理: - 太靠近气囊:降低展开压力 - 姿态异常:延迟展开 """ x, y = position distance_from_center = np.sqrt((x - 0.5)**2 + (y - 0.5)**2) pressure_factor = max(0.5, 1.0 - distance_from_center * 0.5) return { 'pressure_factor': pressure_factor, 'oop_detected': distance_from_center > 0.3 }
class OccupantRestraintSystem: """ 完整乘员约束系统 集成流程: 1. 实时乘员分类 2. 自适应约束配置 3. 碰撞检测触发 """ def __init__(self): self.classifier = OccupantClassifier() self.controller = AdaptiveRestraintController() self.current_occupant = None def update(self, pressure_data, capacitive_data, camera_features): """ 实时更新乘员状态 """ self.current_occupant = self.classifier.classify( pressure_data, capacitive_data, camera_features ) def on_crash_detected(self, crash_severity: float) -> Dict: """ 碰撞检测回调 Args: crash_severity: 碰撞强度 (0-1) Returns: action: 约束动作 """ if self.current_occupant is None: self.current_occupant = OccupantInfo( category='adult_male', weight_estimate=75, confidence=0.5, position=(0.5, 0.5) ) config = self.controller.get_restraint_config(self.current_occupant) action = { 'deploy_airbag': config['airbag']['deploy'] and crash_severity > 0.3, 'airbag_pressure': config['airbag']['pressure'], 'airbag_timing': config['airbag']['timing'], 'seatbelt_pretension': config['seatbelt']['pretension'], 'occupant_category': self.current_occupant.category, 'confidence': self.current_occupant.confidence } return action
class ZFAdaptiveRestraint: """ ZF LIFETEC自适应约束方案 来源:InCabin 2024展示 特点: 1. 摄像头+传感器融合 2. 实时乘员分类 3. 两级气囊展开 """ def __init__(self): self.features = { "乘员检测": "摄像头 + 压力传感器", "分类类别": "成人/儿童/儿童座椅/空座", "气囊策略": "两级展开", "安全带": "自适应预紧", "部署平台": "车载ECU" } def two_stage_airbag(self, occupant_category): """ 两级气囊展开策略 ZF创新:第一阶段推动乘员向内, 第二阶段正常展开 """ if occupant_category in ['child', 'child_seat']: return { "stage1": {"action": "push_inward", "distance": 0}, "stage2": {"action": "none"} } elif occupant_category == 'adult_female': return { "stage1": {"action": "push_inward", "distance": 30}, "stage2": {"action": "inflate", "pressure": 0.7} } else: return { "stage1": {"action": "push_inward", "distance": 60}, "stage2": {"action": "inflate", "pressure": 1.0} }
if __name__ == "__main__": system = OccupantRestraintSystem() test_cases = [ { "name": "成年男性驾驶员", "pressure": np.ones(64) * 100, "capacitive": np.ones(16) * 0.8, "camera": np.array([0.1]) }, { "name": "儿童座椅(副驾)", "pressure": np.ones(64) * 30, "capacitive": np.ones(16) * 0.2, "camera": np.array([0.9]) }, { "name": "空座", "pressure": np.ones(64) * 2, "capacitive": np.ones(16) * 0.1, "camera": np.array([0.0]) } ] print("=" * 60) print("自适应约束系统测试") print("=" * 60) for case in test_cases: system.update(case["pressure"], case["capacitive"], case["camera"]) action = system.on_crash_detected(crash_severity=0.8) print(f"\n场景: {case['name']}") print(f" 乘员类型: {action['occupant_category']}") print(f" 置信度: {action['confidence']:.2f}") print(f" 气囊展开: {'是' if action['deploy_airbag'] else '否'}") print(f" 气囊压力: {action['airbag_pressure']:.1f}") print(f" 安全带预紧: {action['seatbelt_pretension']:.1f}")
|