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
4b8a6e1e
Commit
4b8a6e1e
authored
6 months ago
by
jlKronos01
Browse files
Options
Downloads
Plain Diff
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
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Wireless_Communication/UWB/Beacons_tag_position/realtime_location_POF_gui.py
+41
-24
41 additions, 24 deletions
...ion/UWB/Beacons_tag_position/realtime_location_POF_gui.py
with
41 additions
and
24 deletions
Wireless_Communication/UWB/Beacons_tag_position/realtime_location_POF_gui.py
+
41
−
24
View file @
4b8a6e1e
...
@@ -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
:
.
2
f
}
,
{
y_tag
:
.
2
f
}
)
"
)
self
.
output_label
.
config
(
text
=
f
"
Tag Position: (
{
x_tag
:
.
2
f
}
,
{
y_tag
:
.
2
f
}
)
"
)
#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
"
)
)
...
...
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