Skip to content

Commit

Permalink
Code van vanochtend
Browse files Browse the repository at this point in the history
  • Loading branch information
BobElsendoorn committed Mar 4, 2024
1 parent 781d66c commit 48891b4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
19 changes: 19 additions & 0 deletions gui_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import tkinter as tk
from src.client.video import VideoWindow

def main():
#create a window
window = tk.Tk()
#set the window title
window.title("Battlebot GUI")
#load the videostream from raspberry pi (this is defined in the video.py file as an separate window)
video=VideoWindow()
#set the window size
window.geometry("1200x800")
#run the window
window.mainloop()


if __name__ == "__main__":
main()

9 changes: 4 additions & 5 deletions src/client/communications.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self, url, gui):
self.connected = False
self.send_lock = asyncio.Lock()
self.gui = gui
self.command_queue = asyncio.Queue() # Queue for sending commands to the server

async def connect(self):
async with websockets.connect(self.url) as ws:
Expand All @@ -54,13 +53,13 @@ async def setup_data_channel(self):
self.data_channel = self.pc.createDataChannel("dataChannel")
self.data_channel.on("open", self.data_channel_open)
self.data_channel.on("message", self.on_data_channel_message)

asyncio.create_task(self.send_command_queue())

self.command_queue = asyncio.Queue() # Queue for sending commands to the server

async def data_channel_open(self):
print("Data Channel is open")
self.connected = True

asyncio.create_task(self.send_command_queue()) # create the task here

async def on_data_channel_message(self, message):
message = json.loads(message)

Expand Down
6 changes: 3 additions & 3 deletions src/client/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ def get_joystick_position_and_speed(self):
y_axis = 0
else:
y_axis = round(y_axis / abs(y_axis)) # This will result in -1 or 1
if x_axis == 1:

if x_axis == 1 and y_axis == 0:
x_axis = -1
elif x_axis == -1:
elif x_axis == -1 and y_axis == 0:
x_axis = 1

# Get the value of the right trigger (RT on Xbox controller)
Expand Down
12 changes: 7 additions & 5 deletions src/client/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ def __init__(self, window_name="Video"):

def display_frame(self, frame):
# Convert the av.VideoFrame to a numpy array in RGB format
img_rgb = frame.to_ndarray(format="rgb24")
img_bgr = frame.to_ndarray(format="rgb24")

# Correctly convert RGB image to BGR for display with OpenCV
img_bgr = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
# Correctly convert RGB image to BGR for display with OpenCV and invert the colors
#img_bgr = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR) # Convert the image to BGR

img_bgr_flipped = cv2.flip(img_bgr, 0)

img_bgr_flipped = cv2.flip(img_bgr, -1)


scale_percent = 50 # percent of original size
width = int(img_bgr.shape[1] * scale_percent / 100)
height = int(img_bgr.shape[0] * scale_percent / 100)
dim = (width, height)
# resize image
img_bgr = cv2.resize(img_bgr_flipped, dim, interpolation = cv2.INTER_AREA)
img_bgr = cv2.resize(img_bgr_flipped, dim, interpolation = cv2.INTER_AREA)

cv2.imshow(self.window_name, img_bgr)

Expand Down

0 comments on commit 48891b4

Please sign in to comment.