Skip to content

Commit 3c111a1

Browse files
First Stable Release: SentryBOT Robot Platform DeskGUI Module
This commit includes the PyQt5 based desktop control and monitoring interface developed for the SentryBOT robot platform. bugs expected
1 parent 9c03541 commit 3c111a1

38 files changed

+44587
-0
lines changed

debug_imports.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Debug Imports - Utility to check if all required modules are available
4+
"""
5+
6+
import sys
7+
import os
8+
import importlib
9+
import traceback
10+
11+
def check_imports(modules):
12+
"""Check if the given modules can be imported"""
13+
results = {}
14+
for module_name in modules:
15+
try:
16+
module = importlib.import_module(module_name)
17+
version = getattr(module, '__version__', 'Unknown')
18+
results[module_name] = {'status': 'OK', 'version': version}
19+
except ImportError as e:
20+
results[module_name] = {'status': 'FAIL', 'error': str(e)}
21+
except Exception as e:
22+
results[module_name] = {'status': 'ERROR', 'error': str(e)}
23+
return results
24+
25+
def main():
26+
"""Check imports for all required modules"""
27+
print("Debug Imports - Checking for required modules")
28+
print(f"Python version: {sys.version}")
29+
print(f"Python executable: {sys.executable}")
30+
print(f"Working directory: {os.getcwd()}")
31+
print("-" * 60)
32+
33+
required_modules = [
34+
'PyQt5',
35+
'cv2',
36+
'numpy',
37+
'face_recognition',
38+
'json',
39+
'pickle',
40+
'requests',
41+
'threading',
42+
'pubsub',
43+
'time',
44+
'socket'
45+
]
46+
47+
optional_modules = [
48+
'fastapi',
49+
'uvicorn',
50+
'pyttsx3',
51+
'speech_recognition'
52+
]
53+
54+
print("Checking required modules:")
55+
required_results = check_imports(required_modules)
56+
for module, result in required_results.items():
57+
if result['status'] == 'OK':
58+
print(f"✅ {module} - {result['version']}")
59+
else:
60+
print(f"❌ {module} - {result['error']}")
61+
62+
print("\nChecking optional modules:")
63+
optional_results = check_imports(optional_modules)
64+
for module, result in optional_results.items():
65+
if result['status'] == 'OK':
66+
print(f"✅ {module} - {result['version']}")
67+
else:
68+
print(f"⚠️ {module} - {result['error']}")
69+
70+
# Check if we can import our own modules
71+
print("\nChecking local modules:")
72+
try:
73+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
74+
import desk_gui
75+
print("✅ desk_gui module")
76+
except ImportError as e:
77+
print(f"❌ desk_gui module - {e}")
78+
print(f" sys.path: {sys.path}")
79+
except Exception as e:
80+
print(f"❌ desk_gui module - Unexpected error: {e}")
81+
traceback.print_exc()
82+
83+
if __name__ == "__main__":
84+
main()
85+

desk_gui.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python3
2+
"""
3+
SentryBOT Desktop GUI
4+
Kullanım:
5+
python desk_gui.py --robot-ip 192.168.137.52 --debug
6+
"""
7+
8+
import sys
9+
from PyQt5.QtWidgets import QApplication
10+
from modules.gui.desk_gui_app import DeskGUI
11+
import multiprocessing
12+
import traceback
13+
14+
def launch_gui(**kwargs):
15+
"""
16+
SentryBOT GUI uygulamasını başlat
17+
18+
Args:
19+
**kwargs: DeskGUI sınıfına geçirilecek parametreler
20+
robot_ip: Robot IP adresi
21+
video_port: Video portu
22+
command_port: Komut portu
23+
ollama_url: Ollama API URL
24+
ollama_model: Kullanılacak model
25+
encodings_file: Yüz tanıma modeli dosyası
26+
bluetooth_server: Bluetooth ses sunucusu
27+
debug: Debug modu
28+
"""
29+
try:
30+
# On Windows, ensure that the multiprocessing functionality works
31+
if sys.platform.startswith('win'):
32+
multiprocessing.freeze_support()
33+
34+
app = QApplication(sys.argv)
35+
app.setStyle('Fusion')
36+
37+
# Create and show the GUI
38+
window = DeskGUI(**kwargs)
39+
window.show()
40+
41+
# Start the application event loop
42+
sys.exit(app.exec_())
43+
except Exception as e:
44+
print(f"GUI başlatılırken hata oluştu: {e}")
45+
traceback.print_exc()
46+
sys.exit(1)
47+
48+
if __name__ == "__main__":
49+
import argparse
50+
51+
parser = argparse.ArgumentParser(description='SentryBOT Masaüstü GUI')
52+
parser.add_argument('--robot-ip', default='192.168.137.52', help='Robot IP adresi')
53+
parser.add_argument('--video-port', type=int, default=8000, help='Video portu')
54+
parser.add_argument('--command-port', type=int, default=8090, help='Komut portu')
55+
parser.add_argument('--gui-listen-port', type=int, default=8091, help='GUI dinleme portu')
56+
parser.add_argument('--ollama-url', default='http://localhost:11434/api', help='Ollama API URL')
57+
parser.add_argument('--ollama-model', default='gemma2:2b', help='Kullanılacak model')
58+
parser.add_argument('--encodings-file', default='encodings.pickle', help='Yüz tanıma modeli dosyası')
59+
parser.add_argument('--bluetooth-server', default='192.168.1.100', help='Bluetooth ses sunucusu')
60+
parser.add_argument('--debug', action='store_true', help='Debug modunu aktif et')
61+
62+
args = parser.parse_args()
63+
64+
config = vars(args)
65+
launch_gui(**config)

encodings.pickle

3.24 KB
Binary file not shown.

finger/finger.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import cv2
2+
from cvzone.HandTrackingModule import HandDetector
3+
import json # JSON kütüphanesini içe aktar
4+
5+
# JSON haritasını yükle
6+
map_file_path = r'c:\Users\emirh\OneDrive\Masaüstü\hand_combinations_map.json' # Ham dize olarak tanımla
7+
try:
8+
with open(map_file_path, 'r') as f:
9+
hand_map = json.load(f)
10+
except FileNotFoundError:
11+
print(f"Hata: Harita dosyası bulunamadı: {map_file_path}")
12+
exit()
13+
except json.JSONDecodeError:
14+
print(f"Hata: Harita dosyası geçerli bir JSON değil: {map_file_path}")
15+
exit()
16+
17+
cap = cv2.VideoCapture(0)
18+
19+
# İki eli algılamak için maxHands=2 olarak ayarlandı
20+
detector = HandDetector(detectionCon=0.8, maxHands=2)
21+
22+
fingerTip = [4, 8, 12, 16, 20]
23+
last_published_message = None # Son yayınlanan mesajı takip etmek için
24+
25+
# 10 parmak için renkler (El 1: 0-4, El 2: 5-9)
26+
red = (0, 0, 255)
27+
yellow = (0, 255, 255)
28+
blue = (255, 0, 0)
29+
green = (0, 255, 0)
30+
purple = (255, 0, 255)
31+
orange = (0, 165, 255)
32+
pink = (203, 192, 255)
33+
cyan = (255, 255, 0)
34+
white = (255, 255, 255)
35+
lime = (0, 255, 127)
36+
37+
colors = [red, yellow, blue, green, purple, # El 1 renkleri
38+
orange, pink, cyan, white, lime] # El 2 renkleri
39+
40+
while cap.isOpened():
41+
success, img = cap.read()
42+
if not success:
43+
print("Kamera okunamadı.")
44+
break
45+
46+
# Elleri bul (en fazla 2 el)
47+
hands, img = detector.findHands(img)
48+
49+
currentHandsData = [""] * 2 # Bu frame'deki el verilerini tutmak için
50+
currentHandTypes = [""] * 2 # Bu frame'deki el tiplerini tutmak için
51+
num_hands = len(hands)
52+
53+
# Algılanan her el için döngü
54+
for hand_idx, hand in enumerate(hands):
55+
lmList = hand['lmList']
56+
handType = hand['type']
57+
currentHandTypes[hand_idx] = handType # El tipini sakla
58+
59+
# Mevcut el için parmak değerlerini hesapla
60+
current_fingerVal = [0] * 5
61+
62+
# Başparmak (Thumb)
63+
if handType == "Right":
64+
if lmList[fingerTip[0]][0] > lmList[fingerTip[0] - 1][0]:
65+
current_fingerVal[0] = 1
66+
else:
67+
current_fingerVal[0] = 0
68+
else: # Left hand
69+
if lmList[fingerTip[0]][0] < lmList[fingerTip[0] - 1][0]:
70+
current_fingerVal[0] = 1
71+
else:
72+
current_fingerVal[0] = 0
73+
74+
# Diğer 4 parmak
75+
for i in range(1, 5):
76+
if lmList[fingerTip[i]][1] < lmList[fingerTip[i] - 2][1]:
77+
current_fingerVal[i] = 1
78+
else:
79+
current_fingerVal[i] = 0
80+
81+
# İşaretleri çiz (her parmak için ayrı renk)
82+
for i in range(5):
83+
if current_fingerVal[i] == 1:
84+
# El indeksine göre renk seçimi (hand_idx * 5 + i)
85+
color_index = hand_idx * 5 + i
86+
cv2.circle(img, (lmList[fingerTip[i]][0], lmList[fingerTip[i]][1]), 15,
87+
colors[color_index], cv2.FILLED)
88+
89+
# Mevcut elin parmak durumunu string'e çevir
90+
strVal = ''.join(map(str, current_fingerVal))
91+
currentHandsData[hand_idx] = strVal # Mevcut frame verisine ekle
92+
93+
# --- El işleme döngüsü bitti, şimdi haritalama ve yayınlama ---
94+
95+
message_to_publish = None
96+
97+
if num_hands == 1:
98+
hand_type = currentHandTypes[0]
99+
str_val = currentHandsData[0]
100+
message_to_publish = hand_map.get(hand_type, {}).get(str_val)
101+
elif num_hands == 2:
102+
hand0_type = currentHandTypes[0]
103+
hand0_str = currentHandsData[0]
104+
hand1_type = currentHandTypes[1]
105+
hand1_str = currentHandsData[1]
106+
107+
# Sol ve sağ eli belirle
108+
left_str = None
109+
right_str = None
110+
if hand0_type == 'Left' and hand1_type == 'Right':
111+
left_str = hand0_str
112+
right_str = hand1_str
113+
elif hand0_type == 'Right' and hand1_type == 'Left':
114+
left_str = hand1_str
115+
right_str = hand0_str
116+
117+
if left_str is not None and right_str is not None:
118+
if left_str == right_str:
119+
lookup_key = f"{left_str}_{left_str}"
120+
message_to_publish = hand_map.get("Same", {}).get(lookup_key)
121+
else:
122+
lookup_key = f"{left_str}_{right_str}"
123+
message_to_publish = hand_map.get("Combined", {}).get(lookup_key)
124+
125+
# Yayınlama Mantığı
126+
if message_to_publish is not None:
127+
if message_to_publish != last_published_message:
128+
print(f"Durum: {message_to_publish}")
129+
last_published_message = message_to_publish
130+
elif num_hands == 0: # Eller kaybolduysa
131+
if last_published_message is not None:
132+
print("Durum: El algılanmadı")
133+
last_published_message = None # Son mesajı sıfırla
134+
135+
cv2.imshow("Image", img)
136+
key = cv2.waitKey(1)
137+
if key == ord('q'):
138+
break
139+
140+
cap.release()
141+
cv2.destroyAllWindows()

finger/hand_combinations_map.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"Right": {
3+
"00000": "reset",
4+
"01000": "move_up",
5+
"00100": "move_down",
6+
"00010": "move_left",
7+
"00001": "move_right",
8+
"01111": "wave_hand"
9+
},
10+
"Left": {
11+
"00000": "reset",
12+
"01000": "move_right",
13+
"00100": "move_left",
14+
"00010": "move_down",
15+
"00001": "move_up",
16+
"01111": "wave_hand"
17+
},
18+
"Combined": {
19+
"01000_01000": "rainbow",
20+
"00100_00100": "fire",
21+
"01111_01111": "alert_red"
22+
},
23+
"Same": {
24+
"01000_01000": "gradient",
25+
"00100_00100": "wave"
26+
}
27+
}

0 commit comments

Comments
 (0)