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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
Robobin
Commits
5bf2422a
Commit
5bf2422a
authored
6 months ago
by
Darren0822
Browse files
Options
Downloads
Plain Diff
Update beacons_D_origin.py
parents
3e664451
06a45f31
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Wireless_Communication/UWB/Beacons_tag_position/beacons_D_origin.py
+24
-1
24 additions, 1 deletion
...ommunication/UWB/Beacons_tag_position/beacons_D_origin.py
with
24 additions
and
1 deletion
Wireless_Communication/UWB/Beacons_tag_position/beacons_D_origin.py
+
24
−
1
View file @
5bf2422a
...
@@ -2,10 +2,17 @@ from scipy.optimize import least_squares
...
@@ -2,10 +2,17 @@ from scipy.optimize import least_squares
import
numpy
as
np
import
numpy
as
np
# Measured distances arrive in order: A, E, D, B, F, C
# Measured distances arrive in order: A, E, D, B, F, C
<<<<<<<
HEAD
measured_distances
=
[
1496.692877
,
1477.462413
,
677.287532
,
947.921123
,
1358.796385
,
922.593196
]
measured_distances
=
[
1496.692877
,
1477.462413
,
677.287532
,
947.921123
,
1358.796385
,
922.593196
]
# Introduce ±10 cm of noise into the measurements
# Introduce ±10 cm of noise into the measurements
noise_level
=
0
# Set to zero for no noise
noise_level
=
0
# Set to zero for no noise
=======
measured_distances
=
[
1496.223841
,
1503.259376
,
677.756567
,
945.575945
,
1419.301988
,
923.531267
]
# Introduce ±10 cm of noise
noise_level
=
0
>>>>>>>
06
a45f31e79242c1c4b0f08ce03d5ddf58789e64
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
))
# Automatically generate a robust initial guess
# Automatically generate a robust initial guess
...
@@ -22,6 +29,7 @@ def generate_initial_guess(measured_distances):
...
@@ -22,6 +29,7 @@ def generate_initial_guess(measured_distances):
return
[
x_B
,
y_B
,
x_C
,
y_C
,
y_A
]
return
[
x_B
,
y_B
,
x_C
,
y_C
,
y_A
]
<<<<<<<
HEAD
# Generate bounds based on measured distances
# Generate bounds based on measured distances
def
generate_bounds
(
measured_distances
):
def
generate_bounds
(
measured_distances
):
min_dist
=
min
(
measured_distances
)
min_dist
=
min
(
measured_distances
)
...
@@ -43,6 +51,16 @@ def generate_bounds(measured_distances):
...
@@ -43,6 +51,16 @@ def generate_bounds(measured_distances):
max_dist
*
1.5
# y_A upper bound
max_dist
*
1.5
# y_A upper bound
]
]
return
lower_bound
,
upper_bound
return
lower_bound
,
upper_bound
=======
# Generate the initial guess
initial_guess
=
generate_initial_guess
(
measured_distances_noisy
)
# Simplified uniform bounds for all variables
bounds
=
([
-
2000
,
-
2000
,
-
2000
,
-
2000
,
-
2000
],
[
2000
,
2000
,
2000
,
0
,
2000
])
# Ensure the initial guess is within bounds
initial_guess
=
np
.
clip
(
initial_guess
,
bounds
[
0
],
bounds
[
1
])
>>>>>>>
06
a45f31e79242c1c4b0f08ce03d5ddf58789e64
# Define the error function
# Define the error function
def
error_function
(
variables
,
measured
):
def
error_function
(
variables
,
measured
):
...
@@ -85,7 +103,7 @@ result_noisy = least_squares(
...
@@ -85,7 +103,7 @@ result_noisy = least_squares(
error_function
,
error_function
,
initial_guess
,
initial_guess
,
args
=
(
measured_distances_noisy
,),
args
=
(
measured_distances_noisy
,),
bounds
=
(
lower_bounds
,
upper_bounds
)
,
bounds
=
bounds
,
loss
=
'
soft_l1
'
loss
=
'
soft_l1
'
)
)
...
@@ -94,6 +112,11 @@ optimized_coords_noisy = result_noisy.x
...
@@ -94,6 +112,11 @@ optimized_coords_noisy = result_noisy.x
x_B
,
y_B
,
x_C
,
y_C
,
y_A
=
optimized_coords_noisy
x_B
,
y_B
,
x_C
,
y_C
,
y_A
=
optimized_coords_noisy
print
(
"
Optimized coordinates with noise:
"
,
optimized_coords_noisy
)
print
(
"
Optimized coordinates with noise:
"
,
optimized_coords_noisy
)
<<<<<<<
HEAD
# Calculate and print residuals
# Calculate and print residuals
residuals_noisy
=
error_function
(
optimized_coords_noisy
,
measured_distances_noisy
)[:
-
1
]
# Ignore penalty
residuals_noisy
=
error_function
(
optimized_coords_noisy
,
measured_distances_noisy
)[:
-
1
]
# Ignore penalty
print
(
"
\n
Residuals with noisy measurements:
"
,
residuals_noisy
)
print
(
"
\n
Residuals with noisy measurements:
"
,
residuals_noisy
)
=======
residuals_noisy
=
error_function
(
optimized_coords_noisy
,
measured_distances_noisy
)[:
-
1
]
# Ignore penalty in residuals
print
(
"
Residuals with noisy measurements:
"
,
residuals_noisy
)
>>>>>>>
06
a45f31e79242c1c4b0f08ce03d5ddf58789e64
This diff is collapsed.
Click to expand it.
ycjl1e18
@ycjl1e18
mentioned in commit
3c6933cf
·
6 months ago
mentioned in commit
3c6933cf
mentioned in commit 3c6933cfbf2a4b01a996f7403b8564338983d8d2
Toggle commit list
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