robot looks at you

This commit is contained in:
2024-07-19 14:35:10 -04:00
parent 19bd8a2f6f
commit 482d05f252
12 changed files with 1311 additions and 0 deletions

65
main.py Normal file
View File

@@ -0,0 +1,65 @@
from UnifiWebsockets import Unifi
from URSentry import URSentry
import queue
import time
import threading
import BBoxProcessor
q = queue.Queue()
x = threading.Thread(target=Unifi.run, args=(q,))
x.start()
b = BBoxProcessor.BBoxProcessor()
ur = URSentry("172.22.114.160")
joystick_queue = queue.Queue()
class CameraJoystick(threading.Thread):
def __init__(self, joystick_queue: queue.Queue[list[int]]):
threading.Thread.__init__(self)
self.joystick_queue = joystick_queue
self.keep_running = True
def run(self):
while self.keep_running:
bb = b.get_joystick_position_from_new_set_of_bboxes(q.get())
print(bb)
self.joystick_queue.put(bb)
def stop(self):
self.keep_running = False
current_joystick = [0, 0]
class JoystickScheduler(threading.Thread):
def __init__(self, joystick_queue: queue.Queue[list[int]]):
threading.Thread.__init__(self)
self.joystick_queue = joystick_queue
self.keep_running = True
def run(self):
while self.keep_running:
global current_joystick
current_joystick = self.joystick_queue.get()
def stop(self):
self.keep_running = False
camera_joystick = CameraJoystick(joystick_queue)
camera_joystick.start()
joystick_scheduler = JoystickScheduler(joystick_queue)
joystick_scheduler.start()
ur.await_stop = True
ur.forward_position()
while True:
ur.move_robot_base(-current_joystick[0])
print("Setting robot base velocity to: ", current_joystick[0])
time.sleep(0.2)