diff --git a/src/Smart_car/overload.py b/src/Smart_car/overload.py new file mode 100644 index 0000000000..add2d37219 --- /dev/null +++ b/src/Smart_car/overload.py @@ -0,0 +1,72 @@ +import time +import random + +class UnmannedVehicleOverloadWarningSystem: + """无人车超载预警系统""" + def __init__(self, max_load=1000): + # 初始化系统参数 + self.max_load = max_load # 车辆最大载重(单位:kg,可自定义) + self.current_load = 0 # 当前载重 + self.warning_level = 0 # 预警等级:0-正常,1-轻度过载,2-中度过载,3-严重超载 + + def simulate_weight_collection(self): + """模拟无人车重量采集(模拟传感器数据,可替换为真实硬件接口)""" + # 模拟载重变化:每次在当前基础上小幅波动(模拟乘客/货物上下车) + weight_change = random.randint(-50, 100) + self.current_load = max(0, self.current_load + weight_change) # 载重不能为负数 + return self.current_load + + def judge_overload(self): + """超载判断逻辑,划分预警等级""" + load_ratio = self.current_load / self.max_load # 载重占比 + + if load_ratio <= 0.8: + self.warning_level = 0 # 正常:载重≤80%最大载重 + return "正常", "绿色", "当前载重未超出安全范围,无需处理" + elif 0.8 < load_ratio <= 0.95: + self.warning_level = 1 # 轻度过载:80%<载重≤95% + return "轻度过载预警", "黄色", "当前载重接近上限,建议停止加载" + elif 0.95 < load_ratio <= 1.1: + self.warning_level = 2 # 中度过载:95%<载重≤110% + return "中度过载警告", "橙色", "当前载重已超出安全上限,立即停止运行并卸载部分货物" + else: + self.warning_level = 3 # 严重超载:载重>110% + return "严重超载警报", "红色", "极度危险!立即紧急制动,联系工作人员处理" + + def display_warning(self, status, color, desc): + """可视化输出预警信息(模拟车载终端显示)""" + print("=" * 50) + print(f"【无人车超载预警系统 - 实时监测】") + print(f"当前时间:{time.strftime('%Y-%m-%d %H:%M:%S')}") + print(f"最大载重:{self.max_load} kg") + print(f"当前载重:{self.current_load:.2f} kg") + print(f"载重占比:{self.current_load/self.max_load*100:.2f}%") + print(f"预警状态:【{status}】({color})") + print(f"处理建议:{desc}") + print("=" * 50) + print() + + def run(self, monitor_times=10): + """运行系统,持续监测载重并输出预警""" + print("无人车超载预警系统已启动...") + print(f"开始持续监测(共监测{monitor_times}次,每次间隔2秒)\n") + + for i in range(monitor_times): + # 1. 采集当前载重(模拟) + self.simulate_weight_collection() + # 2. 判断超载等级 + status, color, desc = self.judge_overload() + # 3. 显示预警信息 + self.display_warning(status, color, desc) + # 4. 严重超载时紧急停止 + if self.warning_level == 3: + print("❗❗❗ 检测到严重超载,系统紧急停止运行! ❗❗❗") + break + # 5. 间隔2秒进行下一次监测 + time.sleep(2) + +if __name__ == "__main__": + # 初始化系统:设置无人车最大载重为1000kg(可根据需求修改) + overload_system = UnmannedVehicleOverloadWarningSystem(max_load=1000) + # 运行系统,持续监测10次(可修改监测次数) + overload_system.run(monitor_times=10) \ No newline at end of file diff --git a/src/Smart_car/overweight.py b/src/Smart_car/overweight.py new file mode 100644 index 0000000000..9a2784d2bb --- /dev/null +++ b/src/Smart_car/overweight.py @@ -0,0 +1,99 @@ +import tkinter as tk +from tkinter import ttk +import random +import time + +class UAVTemperatureSystem: + def __init__(self, root): + self.root = root + self.root.title("无人车温度调节系统仿真") + self.root.geometry("500x400") + + # 温度参数初始化 + self.current_temp = 25.0 # 初始温度 + self.target_temp = 25.0 # 目标温度 + self.max_temp = 35.0 # 温度上限 + self.min_temp = 15.0 # 温度下限 + + # 创建UI组件 + self.create_widgets() + + # 启动温度监测循环 + self.update_temp() + + def create_widgets(self): + # 标题标签 + ttk.Label(self.root, text="无人车温度调节系统", font=("Arial", 16, "bold")).pack(pady=10) + + # 当前温度显示 + self.temp_label = ttk.Label(self.root, text=f"当前温度: {self.current_temp:.1f} °C", font=("Arial", 14)) + self.temp_label.pack(pady=5) + + # 目标温度设置 + ttk.Label(self.root, text="设置目标温度:").pack(pady=2) + self.target_entry = ttk.Entry(self.root, width=10) + self.target_entry.insert(0, "25") + self.target_entry.pack(pady=2) + ttk.Button(self.root, text="确认设置", command=self.set_target_temp).pack(pady=5) + + # 系统状态显示 + self.status_label = ttk.Label(self.root, text="系统状态: 待机", font=("Arial", 12), foreground="blue") + self.status_label.pack(pady=10) + + # 温度曲线画布(简易模拟) + self.canvas = tk.Canvas(self.root, width=400, height=150, bg="white") + self.canvas.pack(pady=10) + self.canvas.create_line(10, 75, 390, 75, fill="black") # 基准线 + self.canvas.create_text(200, 10, text="温度变化趋势", font=("Arial", 10)) + + self.x_pos = 10 # 曲线绘制横坐标 + + def set_target_temp(self): + try: + self.target_temp = float(self.target_entry.get()) + self.status_label.config(text=f"目标温度已设为: {self.target_temp:.1f} °C", foreground="green") + except ValueError: + self.status_label.config(text="输入无效!请输入数字", foreground="red") + + def update_temp(self): + # 模拟温度波动(无人车运行时的温度变化) + self.current_temp += random.uniform(-0.5, 0.8) + self.current_temp = round(self.current_temp, 1) + + # 更新温度显示 + self.temp_label.config(text=f"当前温度: {self.current_temp:.1f} °C") + + # 判断温度状态并执行调节逻辑 + if self.current_temp > self.max_temp: + self.status_label.config(text="状态: 温度过高 → 启动制冷系统", foreground="red") + self.current_temp -= 1.2 # 制冷降温 + elif self.current_temp < self.min_temp: + self.status_label.config(text="状态: 温度过低 → 启动加热系统", foreground="orange") + self.current_temp += 1.2 # 加热升温 + elif abs(self.current_temp - self.target_temp) > 1.0: + if self.current_temp > self.target_temp: + self.status_label.config(text="状态: 高于目标 → 轻度制冷", foreground="blue") + self.current_temp -= 0.5 + else: + self.status_label.config(text="状态: 低于目标 → 轻度加热", foreground="blue") + else: + self.status_label.config(text="状态: 温度正常 → 系统待机", foreground="green") + + # 绘制温度变化曲线 + y_pos = 75 - (self.current_temp - 25) * 5 # 映射温度到画布坐标 + if self.x_pos < 390: + self.canvas.create_line(self.x_pos, 75, self.x_pos + 1, y_pos, fill="red", width=2) + self.x_pos += 1 + else: + # 曲线满屏后重置 + self.canvas.delete("all") + self.canvas.create_line(10, 75, 390, 75, fill="black") + self.x_pos = 10 + + # 每隔1秒更新一次 + self.root.after(1000, self.update_temp) + +if __name__ == "__main__": + root = tk.Tk() + app = UAVTemperatureSystem(root) + root.mainloop() \ No newline at end of file