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

UI changes #129

Merged
merged 22 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9beec6d
reordered UI frames and added scrollable section to btree
zhengc84 Feb 13, 2025
76a7263
reordered UI and added btree scroll
zhengc84 Feb 13, 2025
ff1f6a9
UI updates and btree scroll added
zhengc84 Feb 13, 2025
598b1e6
changed UI and added btree scroll
zhengc84 Feb 13, 2025
52af6f3
Merge branch 'master' into UI-changes
mantkiew Feb 14, 2025
180e956
use attributes(-zoomed, True) to maximize the window
mantkiew Feb 14, 2025
0a95f42
added UI changes and btree scroll
zhengc84 Feb 14, 2025
bcccc2f
UI changes and added btree scroll
zhengc84 Feb 14, 2025
b30504e
Merge branch 'UI-changes' of https://github.com/rodrigoqueiroz/geosce…
zhengc84 Feb 14, 2025
78087ac
window maximization for mac and linux
zhengc84 Feb 14, 2025
1cd1de5
UI changes and added btree scroll
zhengc84 Feb 14, 2025
423a0d2
added resolution scaling
zhengc84 Feb 18, 2025
72ed87a
UI layout change and added resolution scaling
zhengc84 Feb 18, 2025
9afe0a8
Ui changes and resolution scaling
zhengc84 Feb 18, 2025
c388ec5
UI changes
zhengc84 Feb 18, 2025
56643b0
added ability to set screen position on launch
zhengc84 Feb 19, 2025
95ae14a
added ability to change dash size on launch
zhengc84 Feb 19, 2025
cbfb30c
made UI changes and font changes
zhengc84 Feb 19, 2025
3478ec6
changed default input of --dash-pos to []
zhengc84 Feb 19, 2025
638a135
fixed setting --dash-pos
zhengc84 Feb 19, 2025
74d2262
remove conda-forge tk and use the one from pip to support TrueType fonts
mantkiew Feb 19, 2025
2de6075
tiny cleanup
mantkiew Feb 19, 2025
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
14 changes: 5 additions & 9 deletions SimTraffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def add_static_obect(self, oid, x,y):


def start(self):
self.flag = True
#Optional CARLA co-sim
if CARLA_COSIMULATION:
self.carla_sync = CarlaSync()
Expand All @@ -90,12 +91,12 @@ def start(self):
self.write_traffic_state(0 , 0.0, 0.0)

#If cosimulation, hold start waiting for first client state
if self.cosimulation == True and self.simconfig.wait_for_client:
if self.cosimulation == True and self.sim_config.wait_for_client:
log.warn("GSServer is running in co-simulation. Waiting for client state in SEM:{} KEY:{}...".format(CS_SEM_KEY, CS_SHM_KEY))
while(True):
header, vstates, _, _, _ = self.sim_client_shm.read_client_state(len(self.vehicles), len(self.pedestrians))
if len(vstates)>0:
break;
break
time.sleep(0.5)

#Start SDV Planners
Expand All @@ -109,6 +110,7 @@ def start(self):
pedestrian.start_planner()

def stop_all(self):
self.flag = False
if self.carla_sync:
self.carla_sync.quit()

Expand Down Expand Up @@ -208,7 +210,7 @@ def create_traffic_state_shm(self):
def write_traffic_state(self, tick_count, delta_time, sim_time):
if not self.traffic_state_sharr:
return

nv = len(self.vehicles)
np = len(self.pedestrians)

Expand Down Expand Up @@ -256,8 +258,6 @@ def write_traffic_state(self, tick_count, delta_time, sim_time):
if self.carla_sync:
self.carla_sync.write_server_state(tick_count, delta_time, self.vehicles)



def detect_collisions(self,tick_count, delta_time, sim_time):
for id_va, va in self.vehicles.items():
if va.sim_state is not ActorSimState.ACTIVE:
Expand All @@ -278,8 +278,6 @@ def detect_collisions(self,tick_count, delta_time, sim_time):
return True
return False



def log_sim_state(self, client_vehicle_states, disabled_vehicles):
log.info("Collision between vehicles {}".format(disabled_vehicles))
state_str = "GSS crash report:\n"
Expand All @@ -300,7 +298,6 @@ def log_sim_state(self, client_vehicle_states, disabled_vehicles):
)
log.info(state_str)


def log_trajectories(self,tick_count,delta_time,sim_time):
if WRITE_TRAJECTORIES:
for vid, vehicle in sorted(self.vehicles.items()):
Expand All @@ -327,7 +324,6 @@ def write_log_trajectories(self):
for line in vlog:
csv_writer.writerow(line)


#For independent processes:
def read_traffic_state(self, traffic_state_sharr, actives_only = True):
'''
Expand Down
103 changes: 48 additions & 55 deletions dash/Dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def run_dash_process(self, traffic_state_sharr, debug_shdata):

#clear
self.clear_vehicle_charts()
self.tree_msg.configure(text= "")

#get new data
header, vehicles, pedestrians, traffic_lights, static_objects = self.sim_traffic.read_traffic_state(traffic_state_sharr, False)
Expand All @@ -97,7 +96,6 @@ def run_dash_process(self, traffic_state_sharr, debug_shdata):
#find valid vehicle to focus plots and btree (if available)
vid = None


if (type(self.center_id) == str):
if self.center_id[0] == 'p':
self.center_pedestrian = True
Expand All @@ -119,7 +117,8 @@ def run_dash_process(self, traffic_state_sharr, debug_shdata):
if VEH_TRAJ_CHART: #vehicle traj plot
self.plot_vehicle_sd(traj, cand)
#behavior tree
self.tree_msg.configure(text="==== Behavior Tree. Vehicle {} ====\n\n {} ".format(vid, btree_snapshot))
self.tree_msg.delete("1.0", "end")
self.tree_msg.insert("1.0", btree_snapshot)
else:
#vehicles without planner:
self.plot_cartesian_chart(vid, vehicles, pedestrians)
Expand Down Expand Up @@ -367,8 +366,6 @@ def plot_vehicles(self,vehicles,x_min,x_max,y_min,y_max, show_arrow = False):
vy = -vy
plt.arrow(x, y, vx/2, vy/2, head_width=1, head_length=1, color=colorcode, zorder=10)



def plot_pedestrians(self, pedestrians, x_min, x_max, y_min, y_max, show_arrow=True):
if pedestrians:
for pid, pedestrian in pedestrians.items():
Expand Down Expand Up @@ -398,7 +395,6 @@ def plot_pedestrians(self, pedestrians, x_min, x_max, y_min, y_max, show_arrow=T
plt.plot(x_goal, y_goal, 'r.' ,markersize=2, zorder=10)
plt.gca().text(x_goal+1, y_goal+1, "p{} goal".format(pid), style='italic', zorder=10)


def plot_frenet_chart(self, center_id, traffic_state:TrafficState, debug_ref_path, traj, cand, unf, traj_s_shift):
#Frenet Frame plot
fig = plt.figure(Dashboard.FRE_FIG_ID)
Expand Down Expand Up @@ -440,7 +436,6 @@ def plot_frenet_chart(self, center_id, traffic_state:TrafficState, debug_ref_pat
x, y = lane_config.stopline_pos
plt.axvline(x, color= 'r', linestyle='-', zorder=1)


#road_occupancy
if SHOW_OCCUPANCY and traffic_state.road_occupancy is not None:
road_occupancy:RoadOccupancy = traffic_state.road_occupancy
Expand Down Expand Up @@ -475,7 +470,6 @@ def plot_frenet_chart(self, center_id, traffic_state:TrafficState, debug_ref_pat
gca.text(anchorx, anchory, y_label)
gca.text(anchorx, anchory + cellsize, i_label)


#junction
#size = 3
#intersections = traffic_state.intersections
Expand All @@ -485,7 +479,6 @@ def plot_frenet_chart(self, center_id, traffic_state:TrafficState, debug_ref_pat
# if isinstance(intersection, sv.SDVTrafficState.AllWayStopIntersection):
# intersection.


# Regulatory Elements
if (regulatory_elements is not None):
for re in regulatory_elements:
Expand Down Expand Up @@ -562,9 +555,6 @@ def plot_frenet_chart(self, center_id, traffic_state:TrafficState, debug_ref_pat
# update lane config based on current (possibly outdated) reference frame
#lane_config = self.read_map(vehicle_state, self.reference_path)




def get_color_by_type(self,actor,a_type,sim_state = None, name = ''):
#color
colorcode = 'k' #black
Expand Down Expand Up @@ -613,7 +603,6 @@ def clear_vehicle_charts(self):
fig = plt.figure(Dashboard.TRAJ_FIG_ID)
plt.cla()


@staticmethod
def plot_trajectory(s_coef, d_coef, T, traj_s_shift, tcolor='grey'):
s_eq = to_equation(s_coef)
Expand Down Expand Up @@ -721,47 +710,62 @@ def plot_curve(coef, T, title, ylabel, xlabel, color="black"):
def create_gui(self):
#Window
window = tk.Tk()
window.configure(bg="white")
window.configure("-fullscreen", True)

# Main containers:
# title frame
# stats frame
# global frame [ map | table ]
# vehicle frame [ cart | frenet | btree ]
title_frame = tk.Frame(window, width = 1200, height = 50, bg = "black")
title_frame.grid(row=0, sticky="nsew")
#tk.ttk.Separator(window,orient=tk.HORIZONTAL).grid(row=1, column=0, sticky='ew' )

stats_frame = tk.Frame(window, width = 1200, height = 50, bg = "white")
stats_frame.grid(row=2, sticky="nsew")
tk.ttk.Separator(window,orient=tk.HORIZONTAL).grid(row=3, column=0, sticky='ew' )
#title and stats
title_frame = tk.Frame(window, bg = "black")
title_frame.place(relx=0, rely=0, relwidth=1.0, relheight=0.05)

global_frame = tk.Frame(window, width = 1200, height = 300, bg = "white")
global_frame.grid(row=4, sticky="nsew")
tk.ttk.Separator(window,orient=tk.HORIZONTAL).grid(row=5, column=0, sticky='ew' )
stats_frame = tk.Frame(window, bg = "white")
stats_frame.place(relx=0, rely=0.05, relwidth=1.0, relheight=0.05)

#map and cartesian
if SHOW_MPLOT:
map_frame = tk.Frame(window, bg = "white")
map_frame.place(relx=0, rely=0.1, relwidth=0.35, relheight=0.4)

vehicle_frame = tk.Frame(window, width = 1200, height = 300, bg = "white")
vehicle_frame.grid(row=6, sticky="nsew")
cart_frame = tk.Frame(window, bg = "white")
cart_frame.place(relx=0.35, rely=0.1, relwidth=0.35, relheight=0.4)

#global sub containers
if SHOW_MPLOT:
map_frame = tk.Frame(global_frame, width = 600, height = 300, bg = "red") #create
map_frame.grid(row=0, column=1, sticky="nsew") #set pos
fren_frame = tk.Frame(window, bg="white")
fren_frame.place(relx=0.01, rely=0.51, relwidth=0.69, relheight=0.29)

tab_frame = tk.Frame(global_frame, width = 1000, height = 300, bg = "blue")
tab_frame.grid(row=0, column=2, sticky="nsew")
tab_frame = tk.Frame(window, bg="white")
tab_frame.place(relx=0, rely=0.8, relwidth=0.7, relheight=0.2)

canvas = tk.Canvas(window)
canvas.place(relx=0.7, rely=0.1, relwidth=0.3, relheight=0.9)

# Add a vertical scrollbar
scrollbar = tk.Scrollbar(window, orient="vertical", command=canvas.yview)
scrollbar.place(relx=0.99, rely=0.1, relwidth=0.01, relheight=0.9)

canvas.configure(yscrollcommand=scrollbar.set)

# Create the bt_frame inside the canvas
bt_frame = tk.Frame(canvas, bg="white")

# Add the bt_frame to the canvas
canvas.create_window((0, 0), window=bt_frame, anchor="nw", width=500)

# Update the scrollregion whenever bt_frame is resize

bt_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all") # Adjust scroll region based on content size
)
)

#vehicle sub containers
cart_frame = tk.Frame(vehicle_frame if SHOW_MPLOT else global_frame, width = 300, height = 300, bg = "white")
fren_frame = tk.Frame(vehicle_frame, width = 300, height = 300, bg = "white")
bt_frame = tk.Frame(vehicle_frame, width = 300, height = 300, bg = "white")
traj_frame = tk.Frame(vehicle_frame, width = 300, height = 300, bg = "white")

# Show enabled plots (left justified)
c = 0
for cframe, visible in zip([cart_frame, fren_frame, bt_frame], [SHOW_CPLOT, SHOW_FFPLOT, SHOW_BTREE]):
if visible:
cframe.grid(row=0, column=c, sticky="nsew")
c += 1
traj_frame = tk.Frame(bt_frame, bg = "white")

# Content:
window.title = 'GeoScenario Server'
Expand All @@ -785,12 +789,6 @@ def create_gui(self):
scenario_config_lb.pack(side = 'left')
self.scenario_config_lb = scenario_config_lb

#scenario_stats_lb = tk.Label(stats_frame, bg='white', text='Loading \n scenario...', font=('OpenSans', 12), anchor="e", justify=tk.RIGHT)
#scenario_stats_lb.pack(side = 'right')
#self.scenario_stats_lb = scenario_stats_lb

# global container:

# map
if SHOW_MPLOT:
fig_map = plt.figure(Dashboard.MAP_FIG_ID)
Expand All @@ -816,9 +814,6 @@ def create_gui(self):
tab.pack(fill='both', expand=True) #x and y
self.tab = tab


# vehicle container:

# vehicle cart
fig_cart = plt.figure(Dashboard.CART_FIG_ID)
if not SHOW_MPLOT:
Expand All @@ -840,12 +835,10 @@ def create_gui(self):
self.traj_canvas = FigureCanvasTkAgg(fig_traj, traj_frame)
self.traj_canvas.get_tk_widget().pack()

tree_msg= tk.Message(bt_frame,text='', anchor='s',
width=300,
bg='white',foreground='black')
tree_msg = tk.Text(bt_frame, height=65, spacing2=1, bg="white", fg="black", wrap="word")
self.tree_msg = tree_msg
tree_msg.grid(row=0,column=0, sticky='nsew')

#General plot Layout
matplotlib.rc('font', size=8)
matplotlib.rc('axes', titlesize=8)
Expand All @@ -855,4 +848,4 @@ def create_gui(self):
matplotlib.rc('legend', fontsize=8)
matplotlib.rc('figure', titlesize=8)

return window
return window