Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vision latency #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions components/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ def _get_pose_delta(self, t):

def ping(self):
"""Send a ping to the RasPi to determine the connection latency."""
self.ping_time = time.monotonic()
t = time.monotonic()
if t - self.ping_time > 0.5:
# Only ping every 500ms - don't keep smashing NetworkTables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we're still constantly flushing NetworkTables here, the impact this will have on traffic is negligible.

The performance impact should also be close-to-negligible iff we have the latest wpilib.

self.ping_time = time.monotonic()

def pong(self):
"""Receive a pong from the RasPi to determine the connection latency."""
if abs(self.rio_pong_time - self.last_pong) > 1e-4: # Floating point comparison
alpha = 0.0 # Exponential averaging
self.latency = alpha * self.latency + (1 - alpha) * (
self.latency = (1 - alpha) * self.latency + alpha * (
self.rio_pong_time - self.raspi_pong_time
)
self.last_pong = self.rio_pong_time