From ab3c3fd28357bee5a27130ee6a3a5ebf9589828a Mon Sep 17 00:00:00 2001 From: shengzhanpeng <3299915477@qq.com> Date: Wed, 17 Dec 2025 01:08:30 +0800 Subject: [PATCH 1/4] 554455 --- src/Driving_Car/README.md | 40 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Driving_Car/README.md b/src/Driving_Car/README.md index 8c27ba2124..aea3eb6553 100644 --- a/src/Driving_Car/README.md +++ b/src/Driving_Car/README.md @@ -1 +1,39 @@ -无人车 \ No newline at end of file + +--- + +# 无人驾驶汽车项目 + +## 项目简介 + +本项目是一个基于Python和PyCharm Community Edition开发的无人驾驶汽车仿真系统。通过计算机视觉、机器学习和传感器数据融合技术,实现车辆在模拟环境中的自主导航和避障功能。 + +## 核心功能 + +**路径规划**: 基于A*算法和RRT算法的智能路径规划 + +**障碍物检测**: 使用YOLO和OpenCV进行实时目标检测与识别 + +**车辆控制**: PID控制器实现精确的转向和速度控制 + +**传感器模拟**: 模拟激光雷达、摄像头和超声波传感器数据 + +**3D可视化**: 基于PyGame的实时场景渲染 + +## 技术栈 +**开发环境**: PyCharm Community Edition 2024+ + +**核心语言**: Python 3.8+ + +**计算机视觉**: OpenCV, PIL, NumPy + +**机器学习**: TensorFlow, scikit-learn + +**3D图形**: PyGame, Pyglet. + +**数据处理**: Pandas, Matplotlib + +## 快速开始 + +1. 克隆项目到PyCharm +2. 安装依赖: `pip install -r requirements.txt` +3. 运行主程序: `python main.py` From a90b5d9855f2d86dcd55d5a1c77c6b968b9b00c9 Mon Sep 17 00:00:00 2001 From: shengzhanpeng <3299915477@qq.com> Date: Thu, 18 Dec 2025 01:02:08 +0800 Subject: [PATCH 2/4] 554455 --- .../Unmanned_vehicle_directional_movemen.py | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/Driving_Car/Unmanned_vehicle_directional_movemen.py diff --git a/src/Driving_Car/Unmanned_vehicle_directional_movemen.py b/src/Driving_Car/Unmanned_vehicle_directional_movemen.py new file mode 100644 index 0000000000..de1c836fd2 --- /dev/null +++ b/src/Driving_Car/Unmanned_vehicle_directional_movemen.py @@ -0,0 +1,71 @@ +import tkinter as tk + +class UnmannedCarSimulator: + def __init__(self, root): + # 初始化主窗口 + self.root = root + self.root.title("无人车平地移动模拟") + self.root.resizable(False, False) + + # 无人车参数 + self.car_x = 250 # 初始x坐标 + self.car_y = 250 # 初始y坐标 + self.car_size = 30 # 车的大小(正方形边长) + self.move_step = 10 # 每次移动的步长 + + # 创建画布(模拟平地) + self.canvas = tk.Canvas(root, width=500, height=500, bg="white") + self.canvas.pack() + + # 绘制初始无人车(矩形) + self.car = self.canvas.create_rectangle( + self.car_x - self.car_size/2, self.car_y - self.car_size/2, + self.car_x + self.car_size/2, self.car_y + self.car_size/2, + fill="blue" + ) + + # 绑定方向键事件 + self.root.bind("", self.move_up) + self.root.bind("", self.move_down) + self.root.bind("", self.move_left) + self.root.bind("", self.move_right) + + # 聚焦窗口以接收键盘事件 + self.canvas.focus_set() + + def move_up(self, event): + """向上移动(y坐标减小)""" + new_y = self.car_y - self.move_step + # 边界检测:不超出画布上沿 + if new_y - self.car_size/2 >= 0: + self.car_y = new_y + self.canvas.move(self.car, 0, -self.move_step) + + def move_down(self, event): + """向下移动(y坐标增大)""" + new_y = self.car_y + self.move_step + # 边界检测:不超出画布下沿 + if new_y + self.car_size/2 <= 500: + self.car_y = new_y + self.canvas.move(self.car, 0, self.move_step) + + def move_left(self, event): + """向左移动(x坐标减小)""" + new_x = self.car_x - self.move_step + # 边界检测:不超出画布左沿 + if new_x - self.car_size/2 >= 0: + self.car_x = new_x + self.canvas.move(self.car, -self.move_step, 0) + + def move_right(self, event): + """向右移动(x坐标增大)""" + new_x = self.car_x + self.move_step + # 边界检测:不超出画布右沿 + if new_x + self.car_size/2 <= 500: + self.car_x = new_x + self.canvas.move(self.car, self.move_step, 0) + +if __name__ == "__main__": + root = tk.Tk() + simulator = UnmannedCarSimulator(root) + root.mainloop() \ No newline at end of file From 9bc9c1f007399436d65788bcd49640a56ca003d4 Mon Sep 17 00:00:00 2001 From: shengzhanpeng <3299915477@qq.com> Date: Thu, 18 Dec 2025 12:35:38 +0800 Subject: [PATCH 3/4] 554455 --- .../Autonomous_vehicle_battery_gauge.py | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/Driving_Car/Autonomous_vehicle_battery_gauge.py diff --git a/src/Driving_Car/Autonomous_vehicle_battery_gauge.py b/src/Driving_Car/Autonomous_vehicle_battery_gauge.py new file mode 100644 index 0000000000..aeee430c47 --- /dev/null +++ b/src/Driving_Car/Autonomous_vehicle_battery_gauge.py @@ -0,0 +1,100 @@ +# 注释掉carla导入 +# import carla +import tkinter as tk +from tkinter import ttk +import random +import threading +import time + +class CarlaBatteryMeter: + def __init__(self, root): + self.root = root + self.root.title("Autonomous Vehicle Battery Gauge") + self.root.geometry("400x300") + self.root.resizable(False, False) + + self.battery_capacity = 100 + self.current_battery = 85 + self.lock = threading.Lock() + + # 注释掉Carla初始化 + # self.carla_client = None + # self.carla_vehicle = None + # self.init_carla() + + self.create_battery_ui() + + self.running = True + self.battery_thread = threading.Thread(target=self.update_battery_from_carla, daemon=True) + self.battery_thread.start() + + self.update_battery_display() + + # 注释掉Carla初始化函数 + # def init_carla(self): + # ... + + def create_battery_ui(self): + title_label = ttk.Label(self.root, text="Autonomous Vehicle Battery Gauge", font=("Microsoft YaHei", 16)) + title_label.pack(pady=20) + + self.battery_label = tk.Label( + self.root, + text=str(self.current_battery), + font=("Microsoft YaHei", 48, "bold"), + bg="white" + ) + self.battery_label.pack(pady=30, fill=tk.BOTH, expand=True) + + desc_label = ttk.Label( + self.root, + text="Battery Range: 70~100(Green) | 20~69(Yellow) | 3~19(Red) | 0~2(Low Power)", + font=("Microsoft YaHei", 10) + ) + desc_label.pack(pady=10) + + def update_battery_from_carla(self): + while self.running: + with self.lock: + # 直接使用模拟数据,注释掉Carla相关逻辑 + # if self.carla_vehicle: + # ... + # else: + if random.random() > 0.4: + self.current_battery = max(0, self.current_battery - 1) + else: + self.current_battery = min(self.battery_capacity, self.current_battery + 1) + time.sleep(1) + + def update_battery_display(self): + with self.lock: + current = self.current_battery + + if 70 <= current <= 100: + text = str(current) + color = "#00cc00" + elif 20 <= current < 70: + text = str(current) + color = "#ffcc00" + elif 3 <= current < 20: + text = str(current) + color = "#ff3300" + else: + text = "Low Power" + color = "#ff0000" + + self.battery_label.config(text=text, fg=color) + self.root.after(200, self.update_battery_display) + + def stop(self): + self.running = False + # 注释掉Carla车辆销毁逻辑 + # if self.carla_vehicle: + # self.carla_vehicle.destroy() + self.root.quit() + +if __name__ == "__main__": + root = tk.Tk() + app = CarlaBatteryMeter(root) + root.protocol("WM_DELETE_WINDOW", app.stop) + root.mainloop() \ No newline at end of file From e41af6cd6943c72aec9da88d6b6165b7fbe93fac Mon Sep 17 00:00:00 2001 From: shengzhanpeng <3299915477@qq.com> Date: Thu, 18 Dec 2025 13:08:01 +0800 Subject: [PATCH 4/4] 554455 --- .../Autonomous_vehicle_fuel_gauge.py | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/Driving_Car/Autonomous_vehicle_fuel_gauge.py diff --git a/src/Driving_Car/Autonomous_vehicle_fuel_gauge.py b/src/Driving_Car/Autonomous_vehicle_fuel_gauge.py new file mode 100644 index 0000000000..453e0ec569 --- /dev/null +++ b/src/Driving_Car/Autonomous_vehicle_fuel_gauge.py @@ -0,0 +1,73 @@ +import random +import time +import sys + + +def get_fuel_color_code(fuel): + """返回ANSI颜色码,终端支持时生效""" + # ANSI颜色码:绿色、黄色、红色、默认 + if fuel >= 70: + return "\033[32m" # 绿色 + elif fuel >= 20: + return "\033[33m" # 黄色 + elif fuel >= 3: + return "\033[31m" # 红色 + else: + return "\033[31m" # 红色 + + +RESET_COLOR = "\033[0m" # 重置颜色 + + +def display_fuel_gauge(fuel): + """在控制台显示油表信息""" + # 清屏(跨平台) + import os + os.system('cls' if os.name == 'nt' else 'clear') + + # 输出油表标题 + print("=" * 40) + print(" Carla Autonomous Vehicle Fuel Gauge") + print("=" * 40) + + # 处理油量显示逻辑 + if fuel >= 3: + fuel_text = f"{fuel}" + color_code = get_fuel_color_code(fuel) + print(f"\n Current Fuel Level: {color_code}{fuel_text}{RESET_COLOR}") + else: + print(f"\n {get_fuel_color_code(fuel)}油量不足{RESET_COLOR}") + + # 绘制简易进度条 + print("\n [", end="") + progress = min(int(fuel), 100) + for i in range(100): + if i < progress: + print(get_fuel_color_code(fuel) + "■" + RESET_COLOR, end="") + else: + print(" ", end="") + print("]") + print("\n (Press Ctrl+C to exit)") + + +def get_carla_fuel_data(): + """模拟从Carla获取油量数据""" + global current_fuel + # 模拟油量缓动变化 + current_fuel += random.randint(-2, 2) + current_fuel = max(0, min(100, current_fuel)) + return current_fuel + + +# 初始化油量 +current_fuel = 80 + +if __name__ == "__main__": + try: + while True: + fuel_level = get_carla_fuel_data() + display_fuel_gauge(fuel_level) + time.sleep(0.5) # 控制刷新频率 + except KeyboardInterrupt: + print("\n\n Exiting Fuel Gauge...") + sys.exit(0) \ No newline at end of file