Skip to content
Snippets Groups Projects
Commit 4b8a6e1e authored by jlKronos01's avatar jlKronos01
Browse files

Merge branch 'UWB' of https://git.soton.ac.uk/plw1g21/robobin into UWB

parents f9de1905 6237c709
No related branches found
No related tags found
No related merge requests found
...@@ -8,42 +8,56 @@ class AnchorTagGUI: ...@@ -8,42 +8,56 @@ class AnchorTagGUI:
def __init__(self, root): def __init__(self, root):
self.root = root self.root = root
self.root.title("Anchor and Tag Visualization") self.root.title("Anchor and Tag Visualization")
self.root.geometry("600x900") # Fixed size: 600px width, 800px height self.root.resizable(False, False)
self.root.resizable(False, False) # Disable resizing
# Canvas for visualization self.root.configure(bg='navy blue')
self.canvas = tk.Canvas(root, width=600, height=600, bg="white") self.left_frame = tk.Frame(root)
self.canvas.pack() self.left_frame.pack(side=tk.LEFT, fill=tk.Y, padx=10, pady=10)
# Button to generate anchor coordinates self.right_frame = tk.Frame(root)
self.generate_anchors_button = ttk.Button(root, text="Generate Anchor Coordinates", command=self.determine_anchor_coords) self.right_frame.pack(side=tk.RIGHT, fill=tk.Y, padx=10, pady=10)
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 self.tag_distances = {} # Distances from the tag to specific anchors
for anchor in ["A1", "A2", "A3", "A4"]: 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() 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(self.right_frame, text="Calculate Tag Position", command=self.calculate_tag_position)
self.calc_button = ttk.Button(root, text="Calculate Tag Position", command=self.calculate_tag_position)
self.calc_button.pack() 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() self.output_label.pack()
# Anchor positions (to be generated dynamically)
self.anchors = {} 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): def determine_anchor_coords(self):
try: try:
measured_distances = self.measured_distances
# Measured distances arrive in order: A, E, D, B, F, C # 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 # Introduce ±10 cm of noise
noise_level = 10.0 noise_level = 10.0
measured_distances_noisy = measured_distances + np.random.uniform(-noise_level, noise_level, size=len(measured_distances)) measured_distances_noisy = measured_distances + np.random.uniform(-noise_level, noise_level, size=len(measured_distances))
...@@ -108,9 +122,10 @@ class AnchorTagGUI: ...@@ -108,9 +122,10 @@ class AnchorTagGUI:
# Display anchors on canvas # Display anchors on canvas
self.draw_canvas() self.draw_canvas()
self.output_label.config( # self.output_label.config(
text=f"Anchors Generated Successfully! Coordinates: {self.anchors}" # 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: except Exception as e:
self.output_label.config(text=f"Error: {str(e)}") self.output_label.config(text=f"Error: {str(e)}")
...@@ -144,6 +159,7 @@ class AnchorTagGUI: ...@@ -144,6 +159,7 @@ class AnchorTagGUI:
# Display result # Display result
self.output_label.config(text=f"Tag Position: ({x_tag:.2f}, {y_tag:.2f})") 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: except Exception as e:
self.output_label.config(text=f"Error: {str(e)}") self.output_label.config(text=f"Error: {str(e)}")
...@@ -189,8 +205,9 @@ class AnchorTagGUI: ...@@ -189,8 +205,9 @@ class AnchorTagGUI:
self.canvas.create_oval( self.canvas.create_oval(
x_tag_scaled - 5, y_tag_scaled - 5, x_tag_scaled + 5, y_tag_scaled + 5, fill="red" 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( 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"
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment