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
| import numpy as np from dataclasses import dataclass, field from typing import List, Optional, Tuple import time
""" IMS 座舱空气质量监测系统 整合 CO2/VOC/NOx/PM2.5 多传感器
参考: - Metis Engineering Air Wise (CAN, CO2/VOC/NOx, 2026-06) - Senseair K96 (3-channel NDIR, 2026) - ARAI VOC 排放研究 (GC-MS, 2026-07) """
@dataclass class AirQualityReading: """空气质量读数""" co2_ppm: float voc_ppb: float nox_ppb: float pm25_ugm3: float pm10_ugm3: float temp_c: float humidity_pct: float pressure_hpa: float timestamp: float @property def aqi_score(self) -> float: """综合空气质量评分 (0-100, 越高越好)""" score = 100 if self.co2_ppm > 1000: score -= min(30, (self.co2_ppm - 1000) / 50) if self.voc_ppb > 300: score -= min(25, (self.voc_ppb - 300) / 50) if self.nox_ppb > 50: score -= min(20, (self.nox_ppb - 50) / 15) if self.pm25_ugm3 > 15: score -= min(25, (self.pm25_ugm3 - 15) / 1) return max(0, round(score, 1))
@dataclass class VentilationAction: """通风动作""" action: str fan_speed: int ac_on: bool reason: str urgency: str
class CabinAirQualityMonitor: """座舱空气质量监控器""" THRESHOLDS = { 'co2_good': 800, 'co2_warning': 1200, 'co2_critical': 2000, 'voc_good': 300, 'voc_warning': 800, 'voc_critical': 1500, 'nox_good': 50, 'nox_warning': 150, 'nox_critical': 300, 'pm25_good': 15, 'pm25_warning': 35, 'pm25_critical': 75, } SENSORS = { 'metis_air_wise': { 'name': 'Metis Air Wise', 'interface': 'CAN', 'measures': ['CO2', 'VOC', 'NOx', 'pressure', 'temp', 'humidity', 'shock'], 'update_hz': 1, 'power_mw': 150 }, 'senseair_k96': { 'name': 'Senseair K96', 'interface': 'I2C/UART', 'measures': ['CO2', 'CO', 'HC'], 'tech': '3-channel NDIR', 'update_hz': 0.5, 'power_mw': 80 }, 'sensirion_sgp40': { 'name': 'Sensirion SGP40', 'interface': 'I2C', 'measures': ['VOC'], 'tech': 'MOS', 'update_hz': 1, 'power_mw': 40 }, 'pmsa003i': { 'name': 'Plantower PMSA003I', 'interface': 'I2C', 'measures': ['PM2.5', 'PM10'], 'tech': 'laser scattering', 'update_hz': 1, 'power_mw': 100 } } def __init__(self): self.history: List[AirQualityReading] = [] self.ventilation_actions: List[VentilationAction] = [] def process_reading(self, reading: AirQualityReading) -> VentilationAction: """处理读数并决定通风策略""" if reading.co2_ppm > self.THRESHOLDS['co2_critical']: action = 'fresh_air' fan_speed = 7 ac_on = True reason = f"CO2 {reading.co2_ppm:.0f}ppm 严重超标" urgency = 'critical' elif reading.co2_ppm > self.THRESHOLDS['co2_warning']: action = 'fresh_air' fan_speed = 4 ac_on = False reason = f"CO2 {reading.co2_ppm:.0f}ppm 超标" urgency = 'warning' elif reading.co2_ppm > self.THRESHOLDS['co2_good']: action = 'fresh_air' fan_speed = 2 ac_on = False reason = f"CO2 {reading.co2_ppm:.0f}ppm 偏高" urgency = 'info' else: action = 'recirculate' fan_speed = 1 ac_on = True reason = "空气质量良好" urgency = 'info' if reading.voc_ppb > self.THRESHOLDS['voc_critical']: action = 'purge' fan_speed = 7 ac_on = True reason = f"VOC {reading.voc_ppb:.0f}ppb 严重超标" urgency = 'critical' elif reading.voc_ppb > self.THRESHOLDS['voc_warning'] and urgency == 'info': action = 'fresh_air' fan_speed = max(fan_speed, 3) reason = f"VOC {reading.voc_ppb:.0f}ppb 超标" urgency = 'warning' if reading.pm25_ugm3 > self.THRESHOLDS['pm25_critical']: action = 'recirculate' fan_speed = max(fan_speed, 5) ac_on = True reason = f"PM2.5 {reading.pm25_ugm3:.0f}ug/m3 严重超标" urgency = 'critical' elif reading.pm25_ugm3 > self.THRESHOLDS['pm25_warning'] and urgency == 'info': action = 'recirculate' fan_speed = max(fan_speed, 3) reason = f"PM2.5 {reading.pm25_ugm3:.0f}ug/m3 超标" urgency = 'warning' if reading.nox_ppb > self.THRESHOLDS['nox_warning']: action = 'recirculate' reason = f"NOx {reading.nox_ppb:.0f}ppb 超标(外部?)" if urgency == 'info': urgency = 'warning' result = VentilationAction( action=action, fan_speed=fan_speed, ac_on=ac_on, reason=reason, urgency=urgency ) self.history.append(reading) self.ventilation_actions.append(result) return result
if __name__ == "__main__": np.random.seed(42) monitor = CabinAirQualityMonitor() print("=" * 75) print("IMS 座舱空气质量监测系统测试") print("=" * 75) scenarios = [ ('刚上车(停车场)', 450, 120, 15, 8, 35, 60, 1010), ('城市驾驶(隧道)', 850, 200, 180, 25, 40, 32, 1010), ('高速驾驶(1h后)', 1400, 350, 40, 12, 28, 50, 1005), ('长时间关窗', 2100, 900, 30, 18, 30, 55, 1005), ('新车VOC释放', 600, 1600, 20, 10, 45, 70, 1010), ('雾霾天外部', 500, 100, 80, 85, 50, 25, 1010), ] print(f"\n{'场景':<20} {'CO2':>6} {'VOC':>6} {'NOx':>6} {'PM2.5':>7} " f"{'AQI':>6} {'动作':>12} {'档位':>4} {'AC':>4} {'紧急':>8}") print("-" * 90) for name, co2, voc, nox, pm25, temp, hum, pres in scenarios: reading = AirQualityReading( co2_ppm=co2, voc_ppb=voc, nox_ppb=nox, pm25_ugm3=pm25, pm10_ugm3=pm25*1.5, temp_c=temp, humidity_pct=hum, pressure_hpa=pres, timestamp=time.time() ) action = monitor.process_reading(reading) print(f"{name:<20} {co2:>6.0f} {voc:>6.0f} {nox:>6.0f} {pm25:>7.0f} " f"{reading.aqi_score:>6.1f} {action.action:>12} " f"{action.fan_speed:>4} {'❄️' if action.ac_on else '—':>4} " f"{action.urgency:>8}") print(f" 原因: {action.reason}") print(f"\n{'='*75}") print("传感器配置:") print(f"{'传感器':<20} {'接口':>10} {'测量':>30} {'功耗':>8}") print("-" * 70) for sid, s in CabinAirQualityMonitor.SENSORS.items(): measures = ','.join(s['measures']) print(f"{s['name']:<20} {s['interface']:>10} {measures:>30} " f"{s['power_mw']:>7}mW") print(f"\n{'='*75}") print("健康阈值:") print(f" {'指标':<10} {'良好':>10} {'警告':>10} {'严重':>10} {'单位':>8}") print(f" {'CO2':<10} {'<800':>10} {'>1200':>10} {'>2000':>10} {'ppm':>8}") print(f" {'VOC':<10} {'<300':>10} {'>800':>10} {'>1500':>10} {'ppb':>8}") print(f" {'NOx':<10} {'<50':>10} {'>150':>10} {'>300':>10} {'ppb':>8}") print(f" {'PM2.5':<10} {'<15':>10} {'>35':>10} {'>75':>10} {'ug/m3':>8}")
|