Skip to content

RSDK-4578: Python SDK Base Properties #387

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

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion examples/server/v1/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(self, name: str):
self.angular_pwr = Vector3(x=0, y=0, z=0)
self.linear_vel = Vector3(x=0, y=0, z=0)
self.angular_vel = Vector3(x=0, y=0, z=0)
self.props = Base.Properties(1.0, 1.0)
self.props = Base.Properties(1.0, 1.0, 1.0)
super().__init__(name)

async def move_straight(self, distance: int, velocity: float, extra: Optional[Dict[str, Any]] = None, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions src/viam/components/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Base(ComponentBase):
class Properties:
width_meters: float
turning_radius_meters: float
wheel_circumference_meters: float

@abc.abstractmethod
async def move_straight(
Expand Down
6 changes: 5 additions & 1 deletion src/viam/components/base/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ async def get_properties(self, *, extra: Optional[Dict[str, Any]] = None, timeou
extra = {}
request = GetPropertiesRequest(name=self.name, extra=dict_to_struct(extra))
response: GetPropertiesResponse = await self.client.GetProperties(request, timeout=timeout)
return Base.Properties(width_meters=response.width_meters, turning_radius_meters=response.turning_radius_meters)
return Base.Properties(
width_meters=response.width_meters,
turning_radius_meters=response.turning_radius_meters,
wheel_circumference_meters=response.wheel_circumference_meters,
)

async def do_command(
self,
Expand Down
6 changes: 5 additions & 1 deletion src/viam/components/base/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ async def GetProperties(self, stream: Stream[GetPropertiesRequest, GetProperties
base = self.get_resource(name)
timeout = stream.deadline.time_remaining() if stream.deadline else None
properties = await base.get_properties(timeout=timeout, metadata=stream.metadata)
response = GetPropertiesResponse(width_meters=properties.width_meters, turning_radius_meters=properties.turning_radius_meters)
response = GetPropertiesResponse(
width_meters=properties.width_meters,
turning_radius_meters=properties.turning_radius_meters,
wheel_circumference_meters=properties.wheel_circumference_meters,
)
await stream.send_message(response)

async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __init__(self, name: str):
self.geometries = GEOMETRIES
self.extra: Optional[Dict[str, Any]] = None
self.timeout: Optional[float] = None
self.props = Base.Properties(1.0, 1.0)
self.props = Base.Properties(1.0, 2.0, 3.0)
super().__init__(name)

async def move_straight(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ async def test_is_moving(self, base: MockBase):
assert base.stopped is True
assert not await base.is_moving()

@pytest.mark.asyncio
async def test_get_properties(self, base: MockBase):
properties = await base.get_properties()
assert properties.width_meters == 1.0
assert properties.turning_radius_meters == 2.0
assert properties.wheel_circumference_meters == 3.0

@pytest.mark.asyncio
async def test_do(self, base: MockBase):
command = {"command": "args"}
Expand Down