Skip to content
Snippets Groups Projects
Commit e26cbfca authored by Bruno Galdos's avatar Bruno Galdos
Browse files

new plot

parent 8df7bc26
No related branches found
No related tags found
No related merge requests found
Pipeline #506581 canceled
...@@ -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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment