Skip to content

Commit

Permalink
Added function to wait for an robot pose update if ensure_gnss is true
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaTechRC committed Sep 10, 2024
1 parent 7a95ea3 commit 254df8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions field_friend/automations/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ async def prepare(self) -> bool:
if isinstance(self.detector, rosys.vision.DetectorSimulation) and not rosys.is_test:
self.detector.simulated_objects = []
self.log.info('clearing plant provider')

self.log.info('waiting for GNSS pose upsate')
await self.gnss.wait_for_updated_robot_pose()
return True

async def finish(self) -> None:
Expand Down
8 changes: 8 additions & 0 deletions field_friend/localization/gnss.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import contextlib
import logging
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -52,6 +53,7 @@ def __init__(self, odometer: rosys.driving.Odometer, antenna_offset: float) -> N
self.device: str | None = None
self.antenna_offset = antenna_offset
self._is_paused = False
self._pose_update = asyncio.Event()
self.observed_poses: list[rosys.geometry.Pose] = []
self.last_pose_update = rosys.time()
self.needed_poses: int = self.NEEDED_POSES
Expand Down Expand Up @@ -131,12 +133,18 @@ def _on_rtk_fix(self) -> None:
if not self._is_paused:
self._update_robot_pose()

async def wait_for_updated_robot_pose(self) -> None:
if self.ensure_gnss:
await self._pose_update.wait()

def _update_robot_pose(self) -> None:
x = np.mean([pose.point.x for pose in self.observed_poses])
y = np.mean([pose.point.y for pose in self.observed_poses])
yaw = np.mean([pose.yaw for pose in self.observed_poses])
pose = rosys.geometry.Pose(x=float(x), y=float(y), yaw=float(yaw), time=rosys.time())
self.ROBOT_POSE_LOCATED.emit(pose)
self._pose_update.set()
self._pose_update.clear()
self.last_pose_update = rosys.time()
self.observed_poses.clear()

Expand Down

0 comments on commit 254df8e

Please sign in to comment.