Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/Driving_Car/Autonomous_vehicle_airbag_trigger_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import tkinter as tk
import random
import time

# -------------------------- 配置参数 --------------------------
# 压力阈值(单位:牛)
LOW_PRESSURE_THRESHOLD = 40000 # 4万牛
MAX_PRESSURE = 2000000 # 200万牛
UPDATE_INTERVAL = 300 # 界面更新间隔(毫秒),约30FPS

# -------------------------- 主窗口初始化 --------------------------
root = tk.Tk()
root.title("Autonomous Vehicle Airbag Trigger System")
root.geometry("800x600") # 窗口大小

# 用于显示文字的标签(居中、大字体)
text_label = tk.Label(
root,
font=("SimHei", 36), # 黑体,36号字(支持中文)
bg="black" # 黑色背景
)
text_label.pack(expand=True, fill="both") # 标签占满整个窗口

# 存储当前压力值
current_pressure = 0.0

# -------------------------- 核心函数 --------------------------
def generate_pressure():
"""生成0~200万牛的模拟压力数据"""
global current_pressure
# 5%概率触发高压力(碰撞),否则低压力
if random.random() < 0.05:
# 4万~200万牛:随机值
current_pressure = random.uniform(LOW_PRESSURE_THRESHOLD, MAX_PRESSURE)
else:
# 0~4万牛:随机值
current_pressure = random.uniform(0, LOW_PRESSURE_THRESHOLD)
return current_pressure

def update_ui():
"""更新界面文字和颜色"""
# 生成新的压力数据
pressure = generate_pressure()
# 判断压力区间,设置文字和颜色
if 0 <= pressure <= LOW_PRESSURE_THRESHOLD:
# 黄色:车辆碰撞
text_label.config(text="车辆碰撞", fg="#FFFF00")
elif LOW_PRESSURE_THRESHOLD < pressure < MAX_PRESSURE:
# 红色:危险,安全气囊已打开
text_label.config(text="危险,安全气囊已打开", fg="#FF0000")
else:
# 灰色:无碰撞(超出范围的情况)
text_label.config(text="无碰撞", fg="#808080")
# 打印压力值到控制台(调试用)
print(f"当前压力:{pressure:.2f} N")
# 定时更新(递归调用,实现循环)
root.after(UPDATE_INTERVAL, update_ui)

# -------------------------- 启动程序 --------------------------
if __name__ == "__main__":
# 首次调用更新函数
update_ui()
# 启动主循环
root.mainloop()
100 changes: 100 additions & 0 deletions src/Driving_Car/Autonomous_vehicle_battery_gauge.py
Original file line number Diff line number Diff line change
@@ -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()
73 changes: 73 additions & 0 deletions src/Driving_Car/Autonomous_vehicle_fuel_gauge.py
Original file line number Diff line number Diff line change
@@ -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)
47 changes: 47 additions & 0 deletions src/Driving_Car/Autonomous_vehicle_temperature_control_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import random
import time
import sys

# 模拟温度传感器:生成-50~50℃的随机温度
def get_temperature():
"""生成-50~50℃的随机温度,也可手动设置固定值测试"""
return random.uniform(-50.0, 50.0)
# 测试固定温度:return 26.0 # 温度适宜
# return -10.0 # 温度过低
# return 35.0 # 温度过高

# 温度判断与显示(控制台彩色输出+弹窗可选)
def display_temperature_info(temp):
"""根据温度显示对应信息,支持控制台彩色输出"""
# 控制台彩色字体(Windows/Linux通用的ANSI转义码)
class Color:
BLUE = '\033[94m' # 蓝色
GREEN = '\033[92m' # 绿色
RED = '\033[91m' # 红色
RESET = '\033[0m' # 重置颜色

if -50.0 <= temp <= 25.0:
# 温度过低:蓝色文本
text = "温度过低,是否需要打开空调?"
print(f"{Color.BLUE}{text}{Color.RESET}")
elif temp == 26.0:
# 温度适宜:绿色文本
text = "温度适宜"
print(f"{Color.GREEN}{text}{Color.RESET}")
elif 27.0 <= temp <= 50.0:
# 温度过高:红色文本
text = "温度过高,是否需要打开空调?"
print(f"{Color.RED}{text}{Color.RESET}")
else:
text = "温度超出测量范围"
print(text)

# 主循环
try:
while True:
current_temp = get_temperature()
print(f"\n当前温度: {current_temp:.1f}℃", end=" ")
display_temperature_info(current_temp)
time.sleep(0.5) # 控制帧率
except KeyboardInterrupt:
print("\n程序手动终止")
40 changes: 39 additions & 1 deletion src/Driving_Car/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
无人车

---

# 无人驾驶汽车项目

## 项目简介

本项目是一个基于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`
Loading
Loading