diff --git a/pyproject.toml b/pyproject.toml index ee1dc2ae9..c2421803e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "viam-sdk" -version = "0.4.1" +version = "0.4.2" description = "Viam Robotics Python SDK" authors = [ "Naveed " ] license = "Apache-2.0" diff --git a/src/viam/app/client.py b/src/viam/app/client.py index 4899ce952..5b55cb139 100644 --- a/src/viam/app/client.py +++ b/src/viam/app/client.py @@ -51,4 +51,4 @@ def close(self): LOGGER.debug("Closing gRPC channel to app") LOGGER.debug("Closing grpc-lib Channel instance") self._channel.close() - self._closed = True + self._closed = True \ No newline at end of file diff --git a/src/viam/components/base/base.py b/src/viam/components/base/base.py index 164a94622..2189c653f 100644 --- a/src/viam/components/base/base.py +++ b/src/viam/components/base/base.py @@ -66,9 +66,9 @@ async def spin( Args: angle (float): The angle (in degrees) to spin. - Negative implies backwards. - velocity (float): The angular velocity (in degrees per second). - to spin. Negative implies backwards. + velocity (float): The angular velocity (in degrees per second) + to spin. + Given a positive angle and a positive velocity, the base will turn to the left. """ ... @@ -91,7 +91,7 @@ async def set_power( Args: linear (Vector3): The linear component. Only the Y component is used - for wheeled base. Negative implies backwards. + for wheeled base. Positive implies forwards. angular (Vector3): The angular component. Only the Z component is used for wheeled base. Positive turns left; negative turns right. """ diff --git a/src/viam/sessions_client.py b/src/viam/sessions_client.py index 7ceef8740..0bc9b9877 100644 --- a/src/viam/sessions_client.py +++ b/src/viam/sessions_client.py @@ -36,11 +36,6 @@ def loop_kwargs(): return {} -async def delay(coro, seconds): - await asyncio.sleep(seconds, **loop_kwargs()) - await coro - - class SessionsClient: """ A Session allows a client to express that it is actively connected and @@ -116,10 +111,22 @@ async def metadata(self) -> _MetadataLike: self._heartbeat_interval = response.heartbeat_window.ToTimedelta() self._current_id = response.id + # tick once to ensure heartbeats are supported await self._heartbeat_tick() + if self._supported: + # We send heartbeats slightly faster than the interval window to + # ensure that we don't fall outside of it and expire the session. + wait = self._heartbeat_interval.total_seconds() / 5 + asyncio.create_task(self._heartbeat_task(wait), name=f"{_TASK_PREFIX}-heartbeat") + return self._metadata + async def _heartbeat_task(self, wait: float): + while self._supported: + await asyncio.sleep(wait) + await self._heartbeat_tick() + async def _heartbeat_tick(self): if not self._supported: return @@ -139,10 +146,6 @@ async def _heartbeat_tick(self): self.reset() else: LOGGER.debug("Sent heartbeat successfully") - # We send heartbeats slightly faster than the interval window to - # ensure that we don't fall outside of it and expire the session. - wait = self._heartbeat_interval.total_seconds() / 5 - asyncio.create_task(delay(self._heartbeat_tick(), wait), name=f"{_TASK_PREFIX}-heartbeat") @property def _metadata(self) -> _MetadataLike: