Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Robobin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
Robobin
Commits
c297d17d
Commit
c297d17d
authored
5 months ago
by
Ziyuan Chang
Browse files
Options
Downloads
Patches
Plain Diff
Delete main__1_.py
parent
7410471b
Branches
UWB_b&t_position
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main__1_.py
+0
-93
0 additions, 93 deletions
main__1_.py
with
0 additions
and
93 deletions
main__1_.py
deleted
100644 → 0
+
0
−
93
View file @
7410471b
from
scipy.optimize
import
least_squares
import
numpy
as
np
# Measured distances with ±10 cm errors (a, b, c, d, e, f)
measured_distances
=
[
3905.12
,
2236.07
,
5000
,
8000
,
8994.27
,
5590.17
]
# Updated initial guess for (x_B, y_B, x_C, y_C, y_D)
# Use values that are reasonably close to the expected beacon positions.
initial_guess
=
[
2500
,
3000
,
4500
,
5500
,
8000
]
# Updated bounds for the variables
# Allowing for a wide range, given the distances are in the thousands
bounds
=
([
0
,
0
,
0
,
0
,
0
],
[
10000
,
10000
,
10000
,
10000
,
10000
])
# Error function for least squares
def
error_function
(
variables
,
measured_distances
):
x_B
,
y_B
,
x_C
,
y_C
,
y_D
=
variables
a_measured
,
b_measured
,
c_measured
,
d_measured
,
e_measured
,
f_measured
=
measured_distances
# Calculating residuals
residuals
=
[]
r_a
=
np
.
sqrt
(
x_B
**
2
+
y_B
**
2
)
-
a_measured
r_b
=
np
.
sqrt
((
x_C
-
x_B
)
**
2
+
(
y_C
-
y_B
)
**
2
)
-
b_measured
r_c
=
np
.
sqrt
(
x_C
**
2
+
(
y_C
-
y_D
)
**
2
)
-
c_measured
r_d
=
y_D
-
d_measured
r_e
=
np
.
sqrt
(
x_C
**
2
+
y_C
**
2
)
-
e_measured
r_f
=
np
.
sqrt
(
x_B
**
2
+
(
y_B
-
y_D
)
**
2
)
-
f_measured
residuals
.
extend
([
r_a
,
r_b
,
r_c
,
r_d
,
r_e
,
r_f
])
return
residuals
# Run least squares optimization
result
=
least_squares
(
error_function
,
initial_guess
,
args
=
(
measured_distances
,
),
bounds
=
bounds
,
loss
=
'
soft_l1
'
# Using a robust loss function to deal with noise
)
# Extract optimized coordinates
optimized_coords
=
result
.
x
x_B
,
y_B
,
x_C
,
y_C
,
y_D
=
optimized_coords
# Print the optimized coordinates
print
(
"
Optimized coordinates:
"
,
optimized_coords
)
# Manually calculate distances based on optimized coordinates
a_calculated
=
np
.
sqrt
(
x_B
**
2
+
y_B
**
2
)
# Distance from A to B
b_calculated
=
np
.
sqrt
((
x_C
-
x_B
)
**
2
+
(
y_C
-
y_B
)
**
2
)
c_calculated
=
np
.
sqrt
(
x_C
**
2
+
(
y_C
-
y_D
)
**
2
)
d_calculated
=
y_D
# Distance from A to D (since A is at (0,0) and D is at (0, y_D))
e_calculated
=
np
.
sqrt
(
x_C
**
2
+
y_C
**
2
)
f_calculated
=
np
.
sqrt
(
x_B
**
2
+
(
y_B
-
y_D
)
**
2
)
# Verification with a tolerance to handle the measurement error (±10 cm)
a_measured
=
3905.12
# Example measured distance (in cm)
b_measured
=
2236.07
c_measured
=
5000
d_measured
=
8000
# Example measured distance (in cm)
e_measured
=
8994.27
f_measured
=
5590.17
# # Check if calculated distances match measured distances within ±10 cm
# assert np.isclose(
# a_calculated, a_measured, atol=10
# ), f"a_calculated {a_calculated} differs from a_measured {a_measured}"
# assert np.isclose(
# b_calculated, b_measured, atol=10
# ), f"b_calculated {b_calculated} differs from b_measured {b_measured}"
# assert np.isclose(
# c_calculated, c_measured, atol=10
# ), f"c_calculated {c_calculated} differs from c_measured {c_measured}"
# assert np.isclose(
# d_calculated, d_measured, atol=10
# ), f"d_calculated {d_calculated} differs from d_measured {d_measured}"
# assert np.isclose(
# e_calculated, e_measured, atol=10
# ), f"e_calculated {e_calculated} differs from e_measured {e_measured}"
# assert np.isclose(
# f_calculated, f_measured, atol=10
# ), f"f_calculated {f_calculated} differs from f_measured {f_measured}"
# print(
# "All calculated distances are within the acceptable tolerance of the measured distances."
# )
# Calculate and print the residuals after optimization
residuals_after_optimization
=
error_function
(
optimized_coords
,
measured_distances
)
print
(
"
Residuals after optimization:
"
,
residuals_after_optimization
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment