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
| import numpy as np from dataclasses import dataclass
@dataclass class HydrogelProperties: """PVA/SA双网络水凝胶参数""" stretchability: float = 580 tensile_strength: float = 1.2 fracture_energy: float = 820 seebeck_coef: float = 3.53 ionic_conductivity: float = 2.1 gauge_factor: float = 8.5 response_time: float = 120 recovery_time: float = 180 array_size: tuple = (4, 4) patch_size: tuple = (10, 10) spacing: float = 5.0
class ThermogalvanicSensor: """ 热 galvanic水凝胶传感器 输出:温度(热 galvanic电压)+压力(电阻变化) """ def __init__(self, props: HydrogelProperties): self.props = props self.base_resistance = 500 def measure_thermal(self, temp_hot: float, temp_cold: float) -> float: """ 热 galvanic输出电压 V = S × ΔT """ delta_t = temp_hot - temp_cold return self.props.seebeck_coef * delta_t def measure_pressure(self, pressure_kPa: float) -> float: """ 压阻效应:压力→电阻变化 ΔR/R = GF × ε 其中应变ε与压力相关 """ strain = pressure_kPa / 1000 delta_r_ratio = self.props.gauge_factor * strain return self.base_resistance * (1 + delta_r_ratio) def dual_measure(self, temp_hot: float, temp_cold: float, pressure_kPa: float) -> dict: """同时测量温度和压力""" return { 'voltage_mv': self.measure_thermal(temp_hot, temp_cold), 'resistance_ohm': self.measure_pressure(pressure_kPa), 'temperature': temp_hot, 'pressure': pressure_kPa, }
class PostureArray: """ 4×4阵列坐姿监测 结合深度学习进行姿态分类 """ def __init__(self): self.props = HydrogelProperties() self.sensors = [[ThermogalvanicSensor(self.props) for _ in range(4)] for _ in range(4)] def scan(self, temp: float = 37, room_temp: float = 25) -> dict: """扫描阵列""" voltage_map = np.zeros((4, 4)) resistance_map = np.zeros((4, 4)) cx, cy = 1.5, 1.5 for i in range(4): for j in range(4): dist = np.sqrt((i-cx)**2 + (j-cy)**2) pressure = max(0, 35 - dist * 12) s = self.sensors[i][j] m = s.dual_measure(temp, room_temp, pressure) voltage_map[i, j] = m['voltage_mv'] resistance_map[i, j] = m['resistance_ohm'] return { 'voltage': voltage_map, 'resistance': resistance_map, } def classify(self, resistance_map: np.ndarray) -> dict: """深度学习姿态分类(简化版)""" total = resistance_map.sum() row_means = resistance_map.mean(axis=1) col_means = resistance_map.mean(axis=0) rows = np.arange(4) cols = np.arange(4) cy = (row_means * rows).sum() / (row_means.sum() + 1e-8) cx = (col_means * cols).sum() / (col_means.sum() + 1e-8) if total > 1500: posture = 'Heavy Load' elif abs(cy - 1.5) < 0.5 and abs(cx - 1.5) < 0.5: posture = 'Normal' elif cy > 2.0: posture = 'Leaning Back' elif cy < 1.0: posture = 'Leaning Forward' elif cx > 2.0: posture = 'Leaning Right' elif cx < 1.0: posture = 'Leaning Left' else: posture = 'Asymmetric' return { 'posture': posture, 'center': (cx, cy), 'total': total, }
if __name__ == "__main__": props = HydrogelProperties() print("=== PVA/SA双网络水凝胶参数 ===") print(f"拉伸率: {props.stretchability}%") print(f"Seebeck系数: {props.seebeck_coef} mV/K") print(f"灵敏度系数: {props.gauge_factor}") print(f"阵列: {props.array_size}") sensor = ThermogalvanicSensor(props) v = sensor.measure_thermal(37, 25) print(f"\n体温37°C vs 室温25°C:") print(f" 热 galvanic电压: {v:.1f} mV") for p in [0, 10, 25, 50]: r = sensor.measure_pressure(p) print(f" {p:3.0f}kPa → R={r:.0f}Ω") array = PostureArray() result = array.scan() posture = array.classify(result['resistance']) print(f"\n4×4阵列坐姿:") print(f" 姿态: {posture['posture']}") print(f" 重心: ({posture['center'][0]:.2f}, {posture['center'][1]:.2f})") print(f" 总阻抗: {posture['total']:.0f}Ω")
|