Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/hackathon UI 152 - Add feature to rotate track by 90 #225

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
6 changes: 6 additions & 0 deletions DRG_config.json
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 27 additions & 1 deletion src/graphics/track_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tkinter import *
import src.utils.geometry as geometry
import src.configuration.real_world as config
import math


class TrackGraphics:
Expand All @@ -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")

Expand Down Expand Up @@ -55,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)

Expand All @@ -68,6 +78,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):
Expand All @@ -80,6 +95,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):
Expand Down Expand Up @@ -120,7 +137,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 = []
Expand Down Expand Up @@ -161,3 +177,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
18 changes: 9 additions & 9 deletions src/main/guru.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def __init__(self, root):
self.track_canvas.bind("<ButtonRelease-1>", self.left_button_released_on_track_canvas)
self.track_canvas.bind("<Double-1>", self.left_button_double_clicked_on_track_canvas)


self.control_frame = tk.Frame(root)
self.inner_control_frame = tk.Frame(self.control_frame)

Expand All @@ -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
#
Expand All @@ -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
#
Expand Down Expand Up @@ -198,30 +195,26 @@ 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
#

self.master.title("Deep Racer Guru v" + VERSION)
self.menu_bar = MenuBar(root, self, False, False)


#
# All done, so display main window now
#

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
#
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
app.mainloop()
5 changes: 5 additions & 0 deletions src/main/view_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/ui/menu_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down