From 145b8ab73790ef995ce909503592800578a8fbad Mon Sep 17 00:00:00 2001 From: Aamir Siddiqui Date: Wed, 1 May 2024 11:57:48 +0100 Subject: [PATCH 1/3] add gitignore --- .gitignore | 1 + DRG_config.json | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 .gitignore create mode 100644 DRG_config.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/DRG_config.json b/DRG_config.json new file mode 100644 index 0000000..4dbbb08 --- /dev/null +++ b/DRG_config.json @@ -0,0 +1,6 @@ +{ + "log_directory": "/Users/aamir/Documents/projects/ai/deepracer-sample-logs", + "last_open_track": "2022_reinvent_champ_ccw", + "calculate_alternate_discount_factors": false, + "calculate_new_reward": false +} \ No newline at end of file From fcaca17cdd13b9e9200a98d30c571a4ed103a03f Mon Sep 17 00:00:00 2001 From: Aamir Siddiqui Date: Wed, 1 May 2024 11:58:58 +0100 Subject: [PATCH 2/3] add ability to rotate by 90 --- src/graphics/track_graphics.py | 27 ++++++++++++++++++++++++++- src/main/guru.py | 18 +++++++++--------- src/main/view_manager.py | 5 +++++ src/ui/menu_bar.py | 9 +++++++++ 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/graphics/track_graphics.py b/src/graphics/track_graphics.py index 3535597..26c3ea4 100644 --- a/src/graphics/track_graphics.py +++ b/src/graphics/track_graphics.py @@ -9,6 +9,7 @@ from tkinter import * import src.utils.geometry as geometry import src.configuration.real_world as config +import math class TrackGraphics: @@ -17,12 +18,20 @@ def __init__(self, canvas:Canvas): self.scale = 100.0 self.min_x = 0 self.max_y = 0 + self.rotation = math.pi * 90 / 180 self.ring_highlight_widgets = [] self.angle_line_highlight_widgets = [] self.car_widgets = [] self.old_car_widgets = [] + def set_rotation(self, angle): + self.rotation = math.pi * angle / 180 + + + def get_origin(self): + return (self.canvas.winfo_width() / 2, self.canvas.winfo_height() / 2) + def reset_to_blank(self): self.canvas.delete("all") @@ -68,6 +77,11 @@ def plot_line(self, point1, point2, width, fill_colour, dash_pattern=None): x2 = (x2 - self.min_x) * self.scale y2 = (self.max_y - y2) * self.scale + x, y = self.rotate_point((x, y), self.rotation) + x2, y2 = self.rotate_point( + (x2, y2), self.rotation + ) + return self.canvas.create_line(x, y, x2, y2, fill=fill_colour, width=width, dash=dash_pattern) def plot_angle_line(self, start_point, bearing, distance, width, fill_colour, dash_pattern=None): @@ -80,6 +94,8 @@ def plot_text(self, point, text_string, font_size, colour: str, offset_x: float x = (x - self.min_x) * self.scale y = (self.max_y - y) * self.scale + x, y = self.rotate_point((x, y), self.rotation) + return self.canvas.create_text(x + offset_x, y + offset_y, text=text_string, fill=colour, font=("", font_size)) def plot_box(self, x, y, x2, y2, colour): @@ -120,7 +136,6 @@ def plot_angled_box_left_and_right_sides_only(self, x: float, y: float, box_widt self.plot_line(front_left, rear_left, line_width, colour) self.plot_line(front_right, rear_right, line_width, colour) - def plot_polygon(self, points, colour): points_as_array = [] @@ -161,3 +176,13 @@ def remove_cars(self): for w in self.old_car_widgets: self.canvas.delete(w) self.old_car_widgets = [] + + def rotate_point(self, point, angle, origin=None): + x, y = point + new_origin = origin if origin else self.get_origin() + ox, oy = new_origin + + qx = ox + math.cos(angle) * (x - ox) - math.sin(angle) * (y - oy) + qy = oy + math.sin(angle) * (x - ox) + math.cos(angle) * (y - oy) + + return qx, qy diff --git a/src/main/guru.py b/src/main/guru.py index 9ed4180..1df6bfb 100644 --- a/src/main/guru.py +++ b/src/main/guru.py @@ -104,7 +104,6 @@ def __init__(self, root): self.track_canvas.bind("", self.left_button_released_on_track_canvas) self.track_canvas.bind("", self.left_button_double_clicked_on_track_canvas) - self.control_frame = tk.Frame(root) self.inner_control_frame = tk.Frame(self.control_frame) @@ -125,7 +124,6 @@ def __init__(self, root): self.graph_canvas = matplotlib_canvas.get_tk_widget() self.graph_canvas.config(width=DEFAULT_CANVAS_WIDTH, height=DEFAULT_CANVAS_HEIGHT) - # # Initialize the "please wait" widget in the middle of each canvas # @@ -134,7 +132,6 @@ def __init__(self, root): self.please_wait_graph = PleaseWait(root, self.graph_canvas) self.please_wait = self.please_wait_track - # # Create the various "analyzers" and let them take control of the contents of the high level UI components # @@ -198,14 +195,12 @@ def __init__(self, root): else: self.secret_analyzers = None - # # Define the layout of the high level UI components # self.layout_ui_for_track_analyzer() - # # Configure the rest of the application window and then make it appear # @@ -213,7 +208,6 @@ def __init__(self, root): self.master.title("Deep Racer Guru v" + VERSION) self.menu_bar = MenuBar(root, self, False, False) - # # All done, so display main window now # @@ -221,7 +215,6 @@ def __init__(self, root): self.already_drawing = False self.update() - # # And now lock-in the sizes of the control and status frames so switches between views will be smooth # @@ -636,6 +629,14 @@ def menu_callback_waypoints_large(self): self.view_manager.set_waypoint_sizes_large() self.redraw() + def menu_callback_rotate_track_90(self): + self.view_manager.rotate_track(90) + self.redraw() + + def menu_callback_rotate_track_0(self): + self.view_manager.rotate_track(0) + self.redraw() + def menu_callback_waypoints_small(self): self.view_manager.set_waypoint_sizes_small() self.redraw() @@ -712,7 +713,6 @@ def expect_objects(self): return self.log is not None and self.log.get_log_meta().race_type == "OBJECT_AVOIDANCE" - root = tk.Tk() app = MainApp(root) -app.mainloop() \ No newline at end of file +app.mainloop() diff --git a/src/main/view_manager.py b/src/main/view_manager.py index 453b6cc..7b2874c 100644 --- a/src/main/view_manager.py +++ b/src/main/view_manager.py @@ -21,6 +21,7 @@ def __init__(self): self.waypoint_major_size = 0 self.waypoint_minor_size = 0 + self.rotation_angle = 0 self.waypoints_on = True self.waypoint_labels_on = False @@ -61,6 +62,9 @@ def set_waypoint_sizes_micro(self): self.waypoint_major_size = 0 self.waypoints_on = True + def rotate_track(self, angle=0): + self.rotation_angle = angle + def set_waypoints_off(self): self.waypoints_on = False @@ -124,6 +128,7 @@ def redraw(self, current_track :Track, track_graphics, analyzer, background_anal background_analyser.recalculate() track_graphics.reset_to_blank() + track_graphics.set_rotation(self.rotation_angle) if self.zoom_in and self.zoom_x: track_graphics.set_track_area(self.zoom_x, self.zoom_y, self.zoom_x2, self.zoom_y2) diff --git a/src/ui/menu_bar.py b/src/ui/menu_bar.py index 5ea601c..c68085d 100644 --- a/src/ui/menu_bar.py +++ b/src/ui/menu_bar.py @@ -113,6 +113,15 @@ def add_view_menu(self): menu.add_command(label="Track - Grey", command=self.main_app.menu_callback_track_grey) menu.add_command(label="Track - Blue", command=self.main_app.menu_callback_track_blue) menu.add_separator() + menu.add_command( + label="Track - Rotate 90", + command=self.main_app.menu_callback_rotate_track_90, + ) + menu.add_command( + label="Track - Rotate 0", + command=self.main_app.menu_callback_rotate_track_0, + ) + menu.add_separator() menu.add_command(label="Sectors - On", command=self.main_app.menu_callback_sectors_on) menu.add_command(label="Sectors - Off", command=self.main_app.menu_callback_sectors_off) menu.add_separator() From dd8e56751acfa46d945d6cf852d5f2904d245022 Mon Sep 17 00:00:00 2001 From: Aamir Siddiqui Date: Thu, 2 May 2024 11:43:52 +0100 Subject: [PATCH 3/3] Fix rotation bug in TrackGraphics class --- src/graphics/track_graphics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphics/track_graphics.py b/src/graphics/track_graphics.py index 26c3ea4..fbd0737 100644 --- a/src/graphics/track_graphics.py +++ b/src/graphics/track_graphics.py @@ -64,6 +64,7 @@ def plot_dot(self, point, r, fill_colour): x = (x - self.min_x) * self.scale y = (self.max_y - y) * self.scale + x, y = self.rotate_point((x, y), self.rotation) self.canvas.create_oval(x - r, y - r, x + r, y + r, fill=fill_colour, width=0)