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
| import numpy as np
class HapticPattern: """触觉模式定义""" LEVEL_SOFT = "soft" LEVEL_ALERT = "alert" LEVEL_URGENT = "urgent" @staticmethod def short_pulse(): """短脉冲 - 轻微提醒""" return { 'duration_ms': 100, 'intensity': 0.3, 'pattern': [1] } @staticmethod def double_pulse(): """双脉冲 - 注意提醒""" return { 'duration_ms': 300, 'intensity': 0.5, 'pattern': [1, 0, 1], 'on_ms': 100, 'off_ms': 100 } @staticmethod def continuous_pulse(): """连续脉冲 - 强烈警告""" return { 'duration_ms': 600, 'intensity': 0.7, 'pattern': [1, 0, 1, 0, 1], 'on_ms': 100, 'off_ms': 50 } @staticmethod def ramp_up(): """渐强 - 疲劳唤醒""" return { 'duration_ms': 800, 'intensity_curve': np.linspace(0.2, 1.0, 50).tolist(), 'pattern': 'ramp' } @staticmethod def rapid_burst(): """急促爆发 - 紧急唤醒(微睡眠)""" return { 'duration_ms': 500, 'intensity': 1.0, 'pattern': [1]*10, 'on_ms': 50, 'off_ms': 0 } @staticmethod def rhythmic_calm(): """节律舒缓 - 情绪安抚""" return { 'duration_ms': 2000, 'intensity': 0.3, 'pattern': [1, 0, 0, 0, 1, 0, 0, 0, 1], 'on_ms': 300, 'off_ms': 700 }
DMS_HAPTIC_MAP = { ('distraction', 1): HapticPattern.short_pulse(), ('distraction', 2): HapticPattern.double_pulse(), ('fatigue', 1): HapticPattern.ramp_up(), ('fatigue', 2): HapticPattern.rapid_burst(), ('microsleep', 3): HapticPattern.rapid_burst(), ('emotion_angry', 1): HapticPattern.rhythmic_calm(), }
print("DMS→触觉模式映射:") for (state, level), pattern in DMS_HAPTIC_MAP.items(): print(f" {state} L{level}: duration={pattern['duration_ms']}ms, " f"intensity={pattern.get('intensity', 'variable')}")
|