Skip to content

Commit

Permalink
Merge branch 'main' into RSDK-3634/data.proto
Browse files Browse the repository at this point in the history
  • Loading branch information
8ashar committed Jun 27, 2023
2 parents 3d9ce9d + 6fe4858 commit 68a964d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "viam-sdk"
version = "0.4.1"
version = "0.4.2"
description = "Viam Robotics Python SDK"
authors = [ "Naveed <[email protected]>" ]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/viam/app/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/viam/components/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
...

Expand All @@ -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.
"""
Expand Down
21 changes: 12 additions & 9 deletions src/viam/sessions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 68a964d

Please sign in to comment.