Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
controller_docker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruno Galdos Huaranca
controller_docker
Commits
e26cbfca
Commit
e26cbfca
authored
5 months ago
by
Bruno Galdos
Browse files
Options
Downloads
Patches
Plain Diff
new plot
parent
8df7bc26
No related branches found
No related tags found
No related merge requests found
Pipeline
#506581
canceled
5 months ago
Stage: build
Stage: registry_push
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
colcon_ws/src/my_controller/my_controller/latency_plotter.py
+14
-3
14 additions, 3 deletions
colcon_ws/src/my_controller/my_controller/latency_plotter.py
with
14 additions
and
3 deletions
colcon_ws/src/my_controller/my_controller/latency_plotter.py
+
14
−
3
View file @
e26cbfca
...
@@ -14,12 +14,13 @@ class LatencyPlotter(Node):
...
@@ -14,12 +14,13 @@ class LatencyPlotter(Node):
super
().
__init__
(
'
latency_plotter
'
)
super
().
__init__
(
'
latency_plotter
'
)
# Subscriptions
# Subscriptions
self
.
create_subscription
(
self
.
subscription
=
self
.
create_subscription
(
FrameOfMocapData
,
FrameOfMocapData
,
'
/optitrack_wrapper_node/frame_data
'
,
'
/optitrack_wrapper_node/frame_data
'
,
self
.
latency_callback
,
self
.
latency_callback
,
10
10
)
)
self
.
get_logger
().
info
(
"
Subscribed to /optitrack_wrapper_node/frame_data
"
)
# Data storage
# Data storage
self
.
timestamps
=
deque
(
maxlen
=
1000
)
# Stores timestamps
self
.
timestamps
=
deque
(
maxlen
=
1000
)
# Stores timestamps
...
@@ -33,6 +34,9 @@ class LatencyPlotter(Node):
...
@@ -33,6 +34,9 @@ class LatencyPlotter(Node):
timestamp
=
msg
.
time_publishing
.
sec
+
msg
.
time_publishing
.
nanosec
*
1e-9
timestamp
=
msg
.
time_publishing
.
sec
+
msg
.
time_publishing
.
nanosec
*
1e-9
latency
=
msg
.
system_latency_ms
latency
=
msg
.
system_latency_ms
# Log for debugging
self
.
get_logger
().
info
(
f
"
Received data: Timestamp=
{
timestamp
}
, Latency=
{
latency
}
"
)
# Append data to deques
# Append data to deques
with
self
.
data_lock
:
with
self
.
data_lock
:
self
.
timestamps
.
append
(
timestamp
)
self
.
timestamps
.
append
(
timestamp
)
...
@@ -42,6 +46,7 @@ class LatencyPlotter(Node):
...
@@ -42,6 +46,7 @@ class LatencyPlotter(Node):
with
self
.
data_lock
:
with
self
.
data_lock
:
return
list
(
self
.
timestamps
),
list
(
self
.
latencies
)
return
list
(
self
.
timestamps
),
list
(
self
.
latencies
)
def
plot_animation
(
node
):
def
plot_animation
(
node
):
# Initialize the plot
# Initialize the plot
fig
,
ax
=
plt
.
subplots
()
fig
,
ax
=
plt
.
subplots
()
...
@@ -61,8 +66,9 @@ def plot_animation(node):
...
@@ -61,8 +66,9 @@ def plot_animation(node):
ax
.
autoscale_view
()
ax
.
autoscale_view
()
return
line
,
return
line
,
ani
=
FuncAnimation
(
fig
,
update
,
interval
=
100
,
blit
=
True
)
ani
=
FuncAnimation
(
fig
,
update
,
interval
=
100
,
blit
=
False
)
plt
.
show
()
plt
.
show
(
block
=
False
)
# Non-blocking to allow ROS to keep running
def
main
(
args
=
None
):
def
main
(
args
=
None
):
rclpy
.
init
(
args
=
args
)
rclpy
.
init
(
args
=
args
)
...
@@ -75,11 +81,16 @@ def main(args=None):
...
@@ -75,11 +81,16 @@ def main(args=None):
try
:
try
:
# Start the plot animation
# Start the plot animation
plot_animation
(
latency_plotter
)
plot_animation
(
latency_plotter
)
# Keep the script alive for ROS and plotting
while
plt
.
fignum_exists
(
1
):
plt
.
pause
(
0.1
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
pass
pass
finally
:
finally
:
latency_plotter
.
destroy_node
()
latency_plotter
.
destroy_node
()
rclpy
.
shutdown
()
rclpy
.
shutdown
()
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
main
()
main
()
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