diff --git a/Wireless_Communication/UWB/Beacons_tag_position/realtime_location_POF_gui.py b/Wireless_Communication/UWB/Beacons_tag_position/realtime_location_POF_gui.py index e2f16be94f0c5c6bacffd9873ec11b5d4d78eec5..d3401248ee29cb8db6d6ffac90720045c1f94492 100644 --- a/Wireless_Communication/UWB/Beacons_tag_position/realtime_location_POF_gui.py +++ b/Wireless_Communication/UWB/Beacons_tag_position/realtime_location_POF_gui.py @@ -8,42 +8,56 @@ class AnchorTagGUI: def __init__(self, root): self.root = root self.root.title("Anchor and Tag Visualization") - self.root.geometry("600x900") # Fixed size: 600px width, 800px height - self.root.resizable(False, False) # Disable resizing + self.root.resizable(False, False) + + self.root.configure(bg='navy blue') + self.left_frame = tk.Frame(root) + self.left_frame.pack(side=tk.LEFT, fill=tk.Y, padx=10, pady=10) - # Canvas for visualization - self.canvas = tk.Canvas(root, width=600, height=600, bg="white") - self.canvas.pack() + self.right_frame = tk.Frame(root) + self.right_frame.pack(side=tk.RIGHT, fill=tk.Y, padx=10, pady=10) - # Button to generate anchor coordinates - self.generate_anchors_button = ttk.Button(root, text="Generate Anchor Coordinates", command=self.determine_anchor_coords) - self.generate_anchors_button.pack() + self.canvas = tk.Canvas(root, width=600, height=600, bg="lightgray") + self.canvas.pack(side=tk.LEFT, padx=10, pady=10) - # Distance inputs for tag-to-anchors - ttk.Label(root, text="Enter distances from tag to anchors:").pack() + + ttk.Label(self.right_frame, text="Enter distances from tag to anchors:").pack() self.tag_distances = {} # Distances from the tag to specific anchors for anchor in ["A1", "A2", "A3", "A4"]: - ttk.Label(root, text=f"Distance to {anchor}:").pack() + ttk.Label(self.right_frame, text=f"Distance to {anchor}:").pack() self.tag_distances[anchor] = tk.StringVar() - ttk.Entry(root, textvariable=self.tag_distances[anchor]).pack() + ttk.Entry(self.right_frame, textvariable=self.tag_distances[anchor]).pack() - # Button to calculate tag position - self.calc_button = ttk.Button(root, text="Calculate Tag Position", command=self.calculate_tag_position) + + self.calc_button = ttk.Button(self.right_frame, text="Calculate Tag Position", command=self.calculate_tag_position) self.calc_button.pack() - # Output label - self.output_label = ttk.Label(root, text="") + + self.output_label = ttk.Label(self.right_frame, text="") self.output_label.pack() - # Anchor positions (to be generated dynamically) self.anchors = {} + self.measured_distances = [tk.DoubleVar(value=200.22), tk.DoubleVar(value=200.47), tk.DoubleVar(value=170.00), tk.DoubleVar(value=170.71), tk.DoubleVar(value=150.00), tk.DoubleVar(value=160.08)] # A, E, D, B, F, C + for i, anchor in enumerate(["a", "e", "d", "b", "f", "c"]): + ttk.Label(self.right_frame, text=f"Distance {anchor}:").pack() + ttk.Entry(self.right_frame, textvariable=self.measured_distances[i]).pack() + - + + self.generate_anchors_button = ttk.Button( + self.right_frame, text="Generate Anchor Coordinates", command=self.determine_anchor_coords + ) + self.generate_anchors_button.pack() + def determine_anchor_coords(self): try: + measured_distances = self.measured_distances + # Measured distances arrive in order: A, E, D, B, F, C - measured_distances = [200.22, 200.47, 170.00, 170.71, 150.00, 160.08] - + + measured_distances = [var.get() for var in measured_distances] + + measured_distances = np.array(measured_distances) # Introduce ±10 cm of noise noise_level = 10.0 measured_distances_noisy = measured_distances + np.random.uniform(-noise_level, noise_level, size=len(measured_distances)) @@ -108,9 +122,10 @@ class AnchorTagGUI: # Display anchors on canvas self.draw_canvas() - self.output_label.config( - text=f"Anchors Generated Successfully! Coordinates: {self.anchors}" - ) + # self.output_label.config( + # text=f"Anchors Generated Successfully! Coordinates: { {k: (round(v[0], 2), round(v[1], 2)) for k, v in self.anchors.items()} }" + # ) + except Exception as e: self.output_label.config(text=f"Error: {str(e)}") @@ -144,6 +159,7 @@ class AnchorTagGUI: # Display result self.output_label.config(text=f"Tag Position: ({x_tag:.2f}, {y_tag:.2f})") + #print(f"Tag Position: ({x_tag:.2f}, {y_tag:.2f})") except Exception as e: self.output_label.config(text=f"Error: {str(e)}") @@ -189,8 +205,9 @@ class AnchorTagGUI: self.canvas.create_oval( x_tag_scaled - 5, y_tag_scaled - 5, x_tag_scaled + 5, y_tag_scaled + 5, fill="red" ) + label = f"Tag ({round(x_tag, 2)}, {round(y_tag, 2)})" self.canvas.create_text( - x_tag_scaled + 15, y_tag_scaled, text="Tag", fill="black" + x_tag_scaled + 15, y_tag_scaled+15, text=label, fill="black" )