Skip to content
Snippets Groups Projects
Commit b7185762 authored by Darren0822's avatar Darren0822
Browse files

Update realtime_location_with_serial_gui.py

parent a45d2263
Branches
No related tags found
No related merge requests found
...@@ -186,9 +186,6 @@ class AnchorTagGUI: ...@@ -186,9 +186,6 @@ class AnchorTagGUI:
try: try:
measured_distances = [var.get() for var in self.measured_distances] measured_distances = [var.get() for var in self.measured_distances]
measured_distances = np.array(measured_distances) measured_distances = np.array(measured_distances)
noise_level = 0.0
measured_distances_noisy = measured_distances + np.random.uniform(-noise_level, noise_level, size=len(measured_distances))
print(f"Measured distances: {measured_distances_noisy}")
# Automatically generate a reasonable initial guess # Automatically generate a reasonable initial guess
def generate_initial_guess(measured_distances): def generate_initial_guess(measured_distances):
y_A = measured_distances[2] # Distance from A to D y_A = measured_distances[2] # Distance from A to D
...@@ -226,8 +223,8 @@ class AnchorTagGUI: ...@@ -226,8 +223,8 @@ class AnchorTagGUI:
return lower_bound, upper_bound return lower_bound, upper_bound
# Generate the initial guess and bounds # Generate the initial guess and bounds
initial_guess = generate_initial_guess(measured_distances_noisy) initial_guess = generate_initial_guess(measured_distances)
lower_bounds, upper_bounds = generate_bounds(measured_distances_noisy) lower_bounds, upper_bounds = generate_bounds(measured_distances)
def error_function(variables, measured): def error_function(variables, measured):
x_B, y_B, x_C, y_C, y_A = variables x_B, y_B, x_C, y_C, y_A = variables
...@@ -267,7 +264,7 @@ class AnchorTagGUI: ...@@ -267,7 +264,7 @@ class AnchorTagGUI:
result_noisy = least_squares( result_noisy = least_squares(
error_function, error_function,
initial_guess, initial_guess,
args=(measured_distances_noisy,), args=(measured_distances,),
bounds=(lower_bounds, upper_bounds), bounds=(lower_bounds, upper_bounds),
loss='soft_l1' loss='soft_l1'
) )
...@@ -436,7 +433,7 @@ class AnchorTagGUI: ...@@ -436,7 +433,7 @@ 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="orange", tags="tag1" x_tag_scaled - 5, y_tag_scaled - 5, x_tag_scaled + 5, y_tag_scaled + 5, fill="orange", tags="tag1"
) )
label = f"Tag 1({round(tag1_x, 2)}, {round(tag1_y, 2)} {tag1_z:.2f})" label = f"Tag 1({round(tag1_x, 2)}, {round(tag1_y, 2)}, {round(tag1_z, 2)})"
self.canvas.create_text( self.canvas.create_text(
x_tag_scaled + 15, y_tag_scaled + 15, text=label, fill="black" x_tag_scaled + 15, y_tag_scaled + 15, text=label, fill="black"
) )
...@@ -449,7 +446,7 @@ class AnchorTagGUI: ...@@ -449,7 +446,7 @@ class AnchorTagGUI:
self.canvas.create_oval( self.canvas.create_oval(
x_tag2_scaled - 5, y_tag2_scaled - 5, x_tag2_scaled + 5, y_tag2_scaled + 5, fill="green", tags="tag2" x_tag2_scaled - 5, y_tag2_scaled - 5, x_tag2_scaled + 5, y_tag2_scaled + 5, fill="green", tags="tag2"
) )
label = f"Tag 2({round(tag2_x, 2)}, {round(tag2_y, 2)} {tag2_z:.2f})" label = f"Tag 2({round(tag2_x, 2)}, {round(tag2_y, 2)}, {round(tag2_z, 2)})"
self.canvas.create_text( self.canvas.create_text(
x_tag2_scaled + 15, y_tag2_scaled + 15, text=label, fill="black" x_tag2_scaled + 15, y_tag2_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