Skip to content

Commit d11dbbd

Browse files
viambotgithub-actions[bot]
authored andcommitted
[WORKFLOW] AI update based on proto changes from commit bd635a9
1 parent 6104a57 commit d11dbbd

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

src/viam/components/gantry/client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from typing import Any, Dict, List, Mapping, Optional
1+
from typing import Any, Dict, List, Mapping, Optional, Tuple
22

33
from grpclib.client import Channel
44

5-
from viam.proto.common import DoCommandRequest, DoCommandResponse, Geometry
5+
from viam.proto.common import DoCommandRequest, DoCommandResponse, Geometry, GetKinematicsRequest, GetKinematicsResponse
66
from viam.proto.component.gantry import (
77
GantryServiceStub,
88
GetLengthsRequest,
@@ -20,6 +20,7 @@
2020
from viam.utils import ValueTypes, dict_to_struct, get_geometries, struct_to_dict
2121

2222
from .gantry import Gantry
23+
from .arm import KinematicsFileFormat
2324

2425

2526
class GantryClient(Gantry, ReconfigurableResourceRPCClientBase):
@@ -110,6 +111,14 @@ async def do_command(
110111
response: DoCommandResponse = await self.client.DoCommand(request, timeout=timeout, metadata=md)
111112
return struct_to_dict(response.result)
112113

114+
async def get_kinematics(
115+
self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
116+
) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
117+
md = kwargs.get("metadata", self.Metadata()).proto
118+
request = GetKinematicsRequest(name=self.name, extra=dict_to_struct(extra))
119+
response: GetKinematicsResponse = await self.client.GetKinematics(request, timeout=timeout, metadata=md)
120+
return response.format, response.kinematics_data
121+
113122
async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
114123
md = kwargs.get("metadata", self.Metadata())
115124
return await get_geometries(self.client, self.name, extra, timeout, md)

src/viam/components/gantry/gantry.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import abc
2-
from typing import Any, Dict, Final, List, Optional
2+
from typing import Any, Dict, Final, List, Optional, Tuple
33

4+
from viam.components.arm import KinematicsFileFormat
45
from viam.resource.types import API, RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT
56

67
from ..component_base import ComponentBase
@@ -154,3 +155,24 @@ async def is_moving(self) -> bool:
154155
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#ismoving>`_.
155156
"""
156157
...
158+
159+
@abc.abstractmethod
160+
async def get_kinematics(
161+
self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
162+
) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
163+
"""
164+
Get the kinematics of the component.
165+
166+
::
167+
168+
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
169+
170+
# Get the kinematics of the gantry.
171+
(kinematics_format, kinematics_data) = await my_gantry.get_kinematics()
172+
173+
Returns:
174+
Tuple[KinematicsFileFormat.ValueType, bytes]: The format of the kinematics data and the kinematics data itself.
175+
176+
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/>`_.
177+
"""
178+
...

src/viam/components/gantry/service.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from grpclib.server import Stream
22

3-
from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse
3+
from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse, GetKinematicsRequest, GetKinematicsResponse
44
from viam.proto.component.gantry import (
55
GantryServiceBase,
66
GetLengthsRequest,
@@ -103,6 +103,18 @@ async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -
103103
response = DoCommandResponse(result=dict_to_struct(result))
104104
await stream.send_message(response)
105105

106+
async def GetKinematics(self, stream: Stream[GetKinematicsRequest, GetKinematicsResponse]) -> None:
107+
request = await stream.recv_message()
108+
assert request is not None
109+
name = request.name
110+
gantry = self.get_resource(name)
111+
timeout = stream.deadline.time_remaining() if stream.deadline else None
112+
kinematics_format, kinematics_data = await gantry.get_kinematics(
113+
extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata
114+
)
115+
response = GetKinematicsResponse(format=kinematics_format, kinematics_data=kinematics_data)
116+
await stream.send_message(response)
117+
106118
async def GetGeometries(self, stream: Stream[GetGeometriesRequest, GetGeometriesResponse]) -> None:
107119
request = await stream.recv_message()
108120
assert request is not None

tests/mocks/components.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ def __init__(self, name: str, position: List[float], lengths: List[float]):
556556
self.position = position
557557
self.lengths = lengths
558558
self.is_stopped = True
559+
self.kinematics = (KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA, b"\x00\x01\x02")
559560
self.extra = None
560561
self.homed = True
561562
self.speeds = Optional[List[float]]
@@ -602,6 +603,13 @@ async def stop(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optiona
602603
async def is_moving(self) -> bool:
603604
return not self.is_stopped
604605

606+
async def get_kinematics(
607+
self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
608+
) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
609+
self.extra = extra
610+
self.timeout = timeout
611+
return self.kinematics
612+
605613
async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) -> List[Geometry]:
606614
self.extra = extra
607615
self.timeout = timeout

tests/test_gantry.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from grpclib.testing import ChannelFor
22

3+
from viam.components.arm import KinematicsFileFormat
34
from viam.components.gantry import GantryClient
45
from viam.components.gantry.service import GantryRPCService
5-
from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse
6+
from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse, GetKinematicsRequest, GetKinematicsResponse
67
from viam.proto.component.gantry import (
78
GantryServiceStub,
89
GetLengthsRequest,
@@ -58,6 +59,11 @@ async def test_is_moving(self):
5859
await self.gantry.stop()
5960
assert not await self.gantry.is_moving()
6061

62+
async def test_get_kinematics(self):
63+
kinematics_format, kinematics_data = await self.gantry.get_kinematics()
64+
assert kinematics_format == KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA
65+
assert kinematics_data == b"\x00\x01\x02"
66+
6167
async def test_extra(self):
6268
assert self.gantry.extra is None or len(self.gantry.extra) == 0
6369
extra = {"foo": "bar", "baz": [1, 2, 3]}
@@ -79,6 +85,9 @@ async def test_timeout(self):
7985
await self.gantry.stop(timeout=4.4)
8086
assert self.gantry.timeout == loose_approx(4.4)
8187

88+
await self.gantry.get_kinematics(timeout=9.9)
89+
assert self.gantry.timeout == loose_approx(9.9)
90+
8291
async def test_get_geometries(self):
8392
geometries = await self.gantry.get_geometries()
8493
assert geometries == GEOMETRIES
@@ -142,6 +151,15 @@ async def test_is_moving(self):
142151
response: IsMovingResponse = await client.IsMoving(request)
143152
assert response.is_moving is True
144153

154+
async def test_get_kinematics(self):
155+
async with ChannelFor([self.service]) as channel:
156+
client = GantryServiceStub(channel)
157+
request = GetKinematicsRequest(name=self.gantry.name)
158+
response: GetKinematicsResponse = await client.GetKinematics(request, timeout=1.1)
159+
assert response.format == KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA
160+
assert response.kinematics_data == b"\x00\x01\x02"
161+
assert self.gantry.timeout == loose_approx(1.1)
162+
145163
async def test_extra(self):
146164
async with ChannelFor([self.service]) as channel:
147165
assert self.gantry.extra is None or len(self.gantry.extra) == 0
@@ -151,6 +169,11 @@ async def test_extra(self):
151169
await client.Stop(request)
152170
assert self.gantry.extra == extra
153171

172+
extra = {"foo": "bar", "baz": [1, 2, 3]}
173+
request = GetKinematicsRequest(name=self.gantry.name, extra=dict_to_struct(extra))
174+
await client.GetKinematics(request)
175+
assert self.gantry.extra == extra
176+
154177
async def test_do(self):
155178
async with ChannelFor([self.service]) as channel:
156179
client = GantryServiceStub(channel)
@@ -226,6 +249,14 @@ async def test_is_moving(self):
226249
client = GantryClient(self.gantry.name, channel)
227250
assert await client.is_moving() is True
228251

252+
async def test_get_kinematics(self):
253+
async with ChannelFor([self.service]) as channel:
254+
client = GantryClient(self.gantry.name, channel)
255+
kinematics_format, kinematics_data = await client.get_kinematics(timeout=2.2)
256+
assert kinematics_format == KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA
257+
assert kinematics_data == b"\x00\x01\x02"
258+
assert self.gantry.timeout == loose_approx(2.2)
259+
229260
async def test_extra(self):
230261
async with ChannelFor([self.service]) as channel:
231262
assert self.gantry.extra is None or len(self.gantry.extra) == 0
@@ -234,6 +265,10 @@ async def test_extra(self):
234265
await client.move_to_position([1, 2, 3], [4, 5, 6], extra=extra)
235266
assert self.gantry.extra == extra
236267

268+
extra = {"foo": "bar", "baz": [1, 2, 3]}
269+
await client.get_kinematics(extra=extra)
270+
assert self.gantry.extra == extra
271+
237272
async def test_get_geometries(self):
238273
async with ChannelFor([self.service]) as channel:
239274
client = GantryClient(self.gantry.name, channel)

0 commit comments

Comments
 (0)