Skip to content

Commit 23b8349

Browse files
committed
Fix AI
1 parent 46b75ea commit 23b8349

File tree

5 files changed

+46
-40
lines changed

5 files changed

+46
-40
lines changed

src/viam/components/arm/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async def GetKinematics(self, stream: Stream[GetKinematicsRequest, GetKinematics
109109
assert request is not None
110110
arm = self.get_resource(request.name)
111111
timeout = stream.deadline.time_remaining() if stream.deadline else None
112-
format, kinematics_data = await arm.get_kinematics(extra=struct_to_dict(request.extra), timeout=timeout)
112+
format, kinematics_data = await arm.get_kinematics(extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata)
113113
response = GetKinematicsResponse(format=format, kinematics_data=kinematics_data)
114114
await stream.send_message(response)
115115

src/viam/components/gantry/client.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
from grpclib.client import Channel
44

5-
from viam.proto.common import DoCommandRequest, DoCommandResponse, Geometry, GetKinematicsRequest, GetKinematicsResponse, KinematicsFileFormat
5+
from viam.proto.common import (
6+
DoCommandRequest,
7+
DoCommandResponse,
8+
Geometry,
9+
GetKinematicsRequest,
10+
GetKinematicsResponse,
11+
KinematicsFileFormat,
12+
)
613
from viam.proto.component.gantry import (
714
GantryServiceStub,
815
GetLengthsRequest,
@@ -111,16 +118,12 @@ async def do_command(
111118
return struct_to_dict(response.result)
112119

113120
async def get_kinematics(
114-
self,
115-
*,
116-
extra: Optional[Dict[str, Any]] = None,
117-
timeout: Optional[float] = None,
118-
**kwargs,
121+
self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
119122
) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
120123
md = kwargs.get("metadata", self.Metadata()).proto
121124
request = GetKinematicsRequest(name=self.name, extra=dict_to_struct(extra))
122125
response: GetKinematicsResponse = await self.client.GetKinematics(request, timeout=timeout, metadata=md)
123-
return response.format, response.kinematics_data
126+
return (response.format, response.kinematics_data)
124127

125128
async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
126129
md = kwargs.get("metadata", self.Metadata())

src/viam/components/gantry/gantry.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -161,37 +161,27 @@ async def get_kinematics(
161161
self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
162162
) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
163163
"""
164-
Get the kinematics of the gantry.
164+
Get the kinematics information associated with the gantry.
165165
166166
::
167167
168168
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
169169
170-
# Get the kinematics of the gantry.
171-
format, data = await my_gantry.get_kinematics()
170+
# Get the kinematics information associated with the gantry.
171+
kinematics = await my_gantry.get_kinematics()
172172
173-
Returns:
174-
Tuple[KinematicsFileFormat.ValueType, bytes]: The kinematics file format and the data.
175-
176-
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#getkinematics>`_.
177-
"""
178-
...
179-
180-
@abc.abstractmethod
181-
async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
182-
"""
183-
Get geometries of the gantry.
184-
185-
::
173+
# Get the format of the kinematics file.
174+
k_file = kinematics[0]
186175
187-
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
188-
189-
# Get the geometries of the gantry.
190-
geometries = await my_gantry.get_geometries()
176+
# Get the byte contents of the file.
177+
k_bytes = kinematics[1]
191178
192179
Returns:
193-
List[Geometry]: A list of geometries of the gantry.
180+
Tuple[KinematicsFileFormat.ValueType, bytes]: A tuple containing two values; the first [0] value represents the format of the
181+
file, either in URDF format (``KinematicsFileFormat.KINEMATICS_FILE_FORMAT_URDF``) or
182+
Viam's kinematic parameter format (spatial vector algebra) (``KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA``),
183+
and the second [1] value represents the byte contents of the file.
194184
195-
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#getgeometries>`_.
185+
For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#getkinematics>`_.
196186
"""
197-
...
187+
...

src/viam/components/gantry/service.py

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

3-
from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse, GetKinematicsRequest, GetKinematicsResponse
3+
from viam.proto.common import (
4+
DoCommandRequest,
5+
DoCommandResponse,
6+
GetGeometriesRequest,
7+
GetGeometriesResponse,
8+
GetKinematicsRequest,
9+
GetKinematicsResponse,
10+
)
411
from viam.proto.component.gantry import (
5-
GantryServiceBase,
612
GetLengthsRequest,
713
GetLengthsResponse,
814
GetPositionRequest,
@@ -15,14 +21,15 @@
1521
MoveToPositionResponse,
1622
StopRequest,
1723
StopResponse,
24+
UnimplementedGantryServiceBase,
1825
)
1926
from viam.resource.rpc_service_base import ResourceRPCServiceBase
2027
from viam.utils import dict_to_struct, struct_to_dict
2128

2229
from .gantry import Gantry
2330

2431

25-
class GantryRPCService(GantryServiceBase, ResourceRPCServiceBase[Gantry]):
32+
class GantryRPCService(UnimplementedGantryServiceBase, ResourceRPCServiceBase[Gantry]):
2633
"""
2734
gRPC Service for a Gantry
2835
"""
@@ -106,8 +113,7 @@ async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -
106113
async def GetKinematics(self, stream: Stream[GetKinematicsRequest, GetKinematicsResponse]) -> None:
107114
request = await stream.recv_message()
108115
assert request is not None
109-
name = request.name
110-
gantry = self.get_resource(name)
116+
gantry = self.get_resource(request.name)
111117
timeout = stream.deadline.time_remaining() if stream.deadline else None
112118
format, data = await gantry.get_kinematics(extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata)
113119
response = GetKinematicsResponse(format=format, kinematics_data=data)
@@ -116,8 +122,8 @@ async def GetKinematics(self, stream: Stream[GetKinematicsRequest, GetKinematics
116122
async def GetGeometries(self, stream: Stream[GetGeometriesRequest, GetGeometriesResponse]) -> None:
117123
request = await stream.recv_message()
118124
assert request is not None
119-
arm = self.get_resource(request.name)
125+
gantry = self.get_resource(request.name)
120126
timeout = stream.deadline.time_remaining() if stream.deadline else None
121-
geometries = await arm.get_geometries(extra=struct_to_dict(request.extra), timeout=timeout)
127+
geometries = await gantry.get_geometries(extra=struct_to_dict(request.extra), timeout=timeout)
122128
response = GetGeometriesResponse(geometries=geometries)
123129
await stream.send_message(response)

tests/test_gantry.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
from viam.components.gantry import GantryClient
44
from viam.components.gantry.service import GantryRPCService
5-
from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse, GetKinematicsRequest, GetKinematicsResponse, KinematicsFileFormat
5+
from viam.proto.common import (
6+
DoCommandRequest,
7+
DoCommandResponse,
8+
GetGeometriesRequest,
9+
GetGeometriesResponse,
10+
GetKinematicsRequest,
11+
GetKinematicsResponse,
12+
)
613
from viam.proto.component.gantry import (
714
GantryServiceStub,
815
GetLengthsRequest,
@@ -260,4 +267,4 @@ async def test_get_geometries(self):
260267
async with ChannelFor([self.service]) as channel:
261268
client = GantryClient(self.gantry.name, channel)
262269
geometries = await client.get_geometries()
263-
assert geometries == GEOMETRIES
270+
assert geometries == GEOMETRIES

0 commit comments

Comments
 (0)