Skip to content

locationd: PoseSmoother#37699

Open
fredyshox wants to merge 2 commits intomasterfrom
pose-smoother
Open

locationd: PoseSmoother#37699
fredyshox wants to merge 2 commits intomasterfrom
pose-smoother

Conversation

@fredyshox
Copy link
Copy Markdown
Contributor

No description provided.

@fredyshox fredyshox changed the title PoseSmoother locationd: PoseSmoother Mar 20, 2026
@fredyshox fredyshox requested a review from Copilot March 20, 2026 23:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors locationd smoothing utilities by centralizing the masked symmetric moving-average helper in helpers.py and introducing a reusable PoseSmoother for symmetric Gaussian smoothing of Pose measurements.

Changes:

  • Moved masked_symmetric_moving_average from lagd.py into selfdrive/locationd/helpers.py and updated lagd.py to import it.
  • Added PoseSmoother to helpers.py for windowed symmetric smoothing over Pose buffers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
selfdrive/locationd/lagd.py Imports masked_symmetric_moving_average from helpers.py after removing the local definition.
selfdrive/locationd/helpers.py Adds masked_symmetric_moving_average utility and introduces the new PoseSmoother class.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +200 to +205
def __init__(self, k: int, sigma: float):
self.k, self.sigma = k, sigma
self.t_buf = deque(maxlen=k)
self.pose_buf = deque(maxlen=k)
self.w = self._symmetric_average_weights(k, sigma)

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

PoseSmoother computes symmetric Gaussian weights and then chooses the center timestamp at k//2, but there’s no validation that k is positive/odd (and sigma > 0). With an even k the “center” is ambiguous and the smoothing becomes time-biased; with sigma<=0 the weights become invalid. Consider asserting k >= 1 and k % 2 == 1 (and sigma > 0) in __init__ to match the assumptions in the implementation (and the existing masked_symmetric_moving_average).

Copilot uses AI. Check for mistakes.
Comment on lines +219 to +223
def feed_pose(self, t: int, pose: Pose):
self.t_buf.append(t)
self.pose_buf.append(pose)

def build_smoothed_pose(self) -> tuple[int, Pose] | None:
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The time parameter for PoseSmoother.feed_pose/build_smoothed_pose is annotated as int, but locationd/lagd consistently use t: float seconds for log time. Using int here is misleading for callers and type-checkers; consider changing these annotations (and the return type) to float to match the rest of the locationd pipeline.

Suggested change
def feed_pose(self, t: int, pose: Pose):
self.t_buf.append(t)
self.pose_buf.append(pose)
def build_smoothed_pose(self) -> tuple[int, Pose] | None:
def feed_pose(self, t: float, pose: Pose):
self.t_buf.append(t)
self.pose_buf.append(pose)
def build_smoothed_pose(self) -> tuple[float, Pose] | None:

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants