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
bbfaceac
Commit
bbfaceac
authored
6 months ago
by
Darren0822
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of
https://git.soton.ac.uk/plw1g21/robobin
parents
841509f2
9b13275c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ros2/src/robobin/robobin/uwb_navigation_node.py
+29
-17
29 additions, 17 deletions
ros2/src/robobin/robobin/uwb_navigation_node.py
with
29 additions
and
17 deletions
ros2/src/robobin/robobin/uwb_navigation_node.py
+
29
−
17
View file @
bbfaceac
...
@@ -122,6 +122,10 @@ class UWBNode(Node):
...
@@ -122,6 +122,10 @@ class UWBNode(Node):
self
.
anchors_coords_known
=
False
self
.
anchors_coords_known
=
False
self
.
previous_tag1_position
=
None
self
.
previous_tag1_position
=
None
self
.
windowSize
=
10
self
.
tag1Window
=
[]
self
.
tag2Window
=
[]
self
.
current_tag1_position
=
None
self
.
current_tag1_position
=
None
self
.
current_tag2_position
=
None
self
.
current_tag2_position
=
None
...
@@ -304,10 +308,10 @@ class UWBNode(Node):
...
@@ -304,10 +308,10 @@ class UWBNode(Node):
bounds
=
([
x_min
,
y_min
,
z_min
],
[
x_max
,
y_max
,
z_max
])
bounds
=
([
x_min
,
y_min
,
z_min
],
[
x_max
,
y_max
,
z_max
])
def
error_function
(
vars
):
def
error_function
(
vars
):
x
,
y
=
vars
x
,
y
,
z
=
vars
residuals
=
[]
residuals
=
[]
for
(
bx
,
by
),
d_measured
in
zip
(
available_beacons
,
available_distances
):
for
(
bx
,
by
,
bz
),
d_measured
in
zip
(
available_beacons
,
available_distances
):
d_computed
=
np
.
sqrt
((
x
-
bx
)
**
2
+
(
y
-
by
)
**
2
)
d_computed
=
np
.
sqrt
((
x
-
bx
)
**
2
+
(
y
-
by
)
**
2
+
(
z
-
bz
)
**
2
)
residuals
.
append
(
d_computed
-
d_measured
)
residuals
.
append
(
d_computed
-
d_measured
)
return
residuals
return
residuals
...
@@ -332,13 +336,16 @@ class UWBNode(Node):
...
@@ -332,13 +336,16 @@ class UWBNode(Node):
tag1_position
=
self
.
calculate_tag_coordinates
(
tag_distances_dict
)
tag1_position
=
self
.
calculate_tag_coordinates
(
tag_distances_dict
)
if
tag1_position
:
if
len
(
self
.
tag1Window
<
self
.
windowSize
):
self
.
tag1Window
.
append
(
tag1_position
)
else
:
self
.
tag1Window
=
self
.
tag1Window
[
1
:]
+
[
tag1_position
]
self
.
current_tag1_position
=
tuple
(
map
(
lambda
li
:
sum
(
li
)
/
len
(
li
),
zip
(
self
.
tag1Window
)))
if
tag1_position
is
not
None
:
self
.
current_tag1_position
=
tag1_position
self
.
get_logger
().
info
(
f
"
Tag 1 position:
{
tag1_position
}
"
)
self
.
get_logger
().
info
(
f
"
Tag 1 position:
{
tag1_position
}
"
)
position_msg
=
Point
(
x
=
tag1_position
[
0
],
y
=
tag1_position
[
1
],
z
=
tag1_position
[
2
])
position_msg
=
Point
(
x
=
self
.
current_
tag1_position
[
0
],
y
=
self
.
current_
tag1_position
[
1
],
z
=
self
.
current_
tag1_position
[
2
])
self
.
publisher
.
publish
(
position_msg
)
self
.
publisher
.
publish
(
position_msg
)
if
self
.
mode
==
"
Follow
"
:
if
self
.
mode
==
"
Follow
"
:
...
@@ -353,22 +360,29 @@ class UWBNode(Node):
...
@@ -353,22 +360,29 @@ class UWBNode(Node):
}
}
tag2_position
=
self
.
calculate_tag_coordinates
(
tag2_distances_dict
)
tag2_position
=
self
.
calculate_tag_coordinates
(
tag2_distances_dict
)
if
tag2_position
:
if
tag2_position
:
self
.
get_logger
().
info
(
f
"
Tag 1 position:
{
tag1_position
}
"
)
if
len
(
self
.
tag2Window
<
self
.
windowSize
):
self
.
get_logger
().
info
(
f
"
Tag 2 position:
{
tag2_position
}
"
)
self
.
tag2Window
.
append
(
tag2_position
)
self
.
current_tag2_position
=
tag2_position
else
:
target_msg
=
Point
(
x
=
tag2_position
[
0
],
y
=
tag2_position
[
1
],
z
=
tag2_position
[
2
])
self
.
tag2Window
=
self
.
tag2Window
[
1
:]
+
[
tag2_position
]
self
.
current_tag2_position
=
tuple
(
map
(
lambda
li
:
sum
(
li
)
/
len
(
li
),
zip
(
self
.
tag2Window
)))
self
.
get_logger
().
info
(
f
"
Tag 1 position:
{
self
.
current_tag1_position
}
"
)
self
.
get_logger
().
info
(
f
"
Tag 2 position:
{
self
.
current_tag2_position
}
"
)
target_msg
=
Point
(
x
=
self
.
current_tag2_position
[
0
],
y
=
self
.
current_tag2_position
[
1
],
z
=
self
.
current_tag2_position
[
2
])
self
.
target_location_pub
.
publish
(
target_msg
)
self
.
target_location_pub
.
publish
(
target_msg
)
# Compute offset if not yet computed
# Compute offset if not yet computed
if
not
self
.
follow_offset_computed
and
self
.
current_yaw
is
not
None
and
self
.
current_tag1_position
is
not
None
:
if
not
self
.
follow_offset_computed
and
self
.
current_yaw
is
not
None
and
self
.
current_tag1_position
is
not
None
:
self
.
uwb_to_imu_offset
=
self
.
compute_heading_offset
(
self
.
current_tag1_position
,
self
.
current_tag2_position
,
self
.
current_yaw
)
self
.
uwb_to_imu_offset
=
self
.
compute_heading_offset
(
self
.
current_tag1_position
,
self
.
current_tag2_position
,
self
.
current_yaw
)
self
.
follow_offset_computed
=
True
self
.
follow_offset_computed
=
True
else
:
self
.
tag2Window
=
[]
else
:
else
:
self
.
get_logger
().
warning
(
"
Tag 2 not known
"
)
self
.
get_logger
().
warning
(
"
Tag 2 not known
"
)
self
.
tag2Window
=
[]
if
self
.
mode
==
"
Call
"
and
self
.
call_mode_active
:
if
self
.
mode
==
"
Call
"
and
self
.
call_mode_active
:
self
.
get_logger
().
info
(
"
Call mode active.
"
)
self
.
get_logger
().
info
(
"
Call mode active.
"
)
if
self
.
current_tag1_position
is
not
None
and
self
.
current_target_index
<
len
(
self
.
path
):
if
self
.
current_tag1_position
is
not
None
and
self
.
current_target_index
<
len
(
self
.
path
):
self
.
get_logger
().
info
(
f
"
Current target index:
{
self
.
current_target_index
}
"
)
self
.
get_logger
().
info
(
f
"
Current target index:
{
self
.
current_target_index
}
"
)
...
@@ -387,7 +401,7 @@ class UWBNode(Node):
...
@@ -387,7 +401,7 @@ class UWBNode(Node):
# Check if close to the node
# Check if close to the node
dist
=
math
.
sqrt
((
self
.
current_tag1_position
[
0
]
-
target_pos
[
0
])
**
2
+
dist
=
math
.
sqrt
((
self
.
current_tag1_position
[
0
]
-
target_pos
[
0
])
**
2
+
(
self
.
current_tag1_position
[
1
]
-
target_pos
[
1
])
**
2
)
(
self
.
current_tag1_position
[
1
]
-
target_pos
[
1
])
**
2
)
if
dist
<
5
:
# Threshold of 5 cm
if
dist
<
10
:
# Threshold of 5 cm
self
.
current_target_index
+=
1
self
.
current_target_index
+=
1
if
self
.
current_target_index
>=
len
(
self
.
path
):
if
self
.
current_target_index
>=
len
(
self
.
path
):
self
.
get_logger
().
info
(
"
Call mode: Reached final destination.
"
)
self
.
get_logger
().
info
(
"
Call mode: Reached final destination.
"
)
...
@@ -395,8 +409,6 @@ class UWBNode(Node):
...
@@ -395,8 +409,6 @@ class UWBNode(Node):
else
:
else
:
self
.
get_logger
().
info
(
f
"
Moving to next node:
{
self
.
path
[
self
.
current_target_index
]
}
"
)
self
.
get_logger
().
info
(
f
"
Moving to next node:
{
self
.
path
[
self
.
current_target_index
]
}
"
)
except
Exception
as
e
:
except
Exception
as
e
:
self
.
get_logger
().
error
(
f
"
Error updating positions:
{
e
}
"
)
self
.
get_logger
().
error
(
f
"
Error updating positions:
{
e
}
"
)
#ros2\src\robobin\robobin\graphs\graph.json
#ros2\src\robobin\robobin\graphs\graph.json
...
...
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