Skip to content

Commit a97c3ff

Browse files
viambotnjooma
andauthored
Automated Protos Update (viamrobotics#1041)
Co-authored-by: Naveed Jooma <[email protected]>
1 parent 6104a57 commit a97c3ff

File tree

11 files changed

+219
-105
lines changed

11 files changed

+219
-105
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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
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 (
6+
DoCommandRequest,
7+
DoCommandResponse,
8+
Geometry,
9+
GetKinematicsRequest,
10+
GetKinematicsResponse,
11+
KinematicsFileFormat,
12+
)
613
from viam.proto.component.gantry import (
714
GantryServiceStub,
815
GetLengthsRequest,
@@ -110,6 +117,14 @@ async def do_command(
110117
response: DoCommandResponse = await self.client.DoCommand(request, timeout=timeout, metadata=md)
111118
return struct_to_dict(response.result)
112119

120+
async def get_kinematics(
121+
self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
122+
) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
123+
md = kwargs.get("metadata", self.Metadata()).proto
124+
request = GetKinematicsRequest(name=self.name, extra=dict_to_struct(extra))
125+
response: GetKinematicsResponse = await self.client.GetKinematics(request, timeout=timeout, metadata=md)
126+
return (response.format, response.kinematics_data)
127+
113128
async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
114129
md = kwargs.get("metadata", self.Metadata())
115130
return await get_geometries(self.client, self.name, extra, timeout, md)

src/viam/components/gantry/gantry.py

Lines changed: 32 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,33 @@ 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 information associated with the gantry.
165+
166+
::
167+
168+
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
169+
170+
# Get the kinematics information associated with the gantry.
171+
kinematics = await my_gantry.get_kinematics()
172+
173+
# Get the format of the kinematics file.
174+
k_file = kinematics[0]
175+
176+
# Get the byte contents of the file.
177+
k_bytes = kinematics[1]
178+
179+
Returns:
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.
184+
185+
For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#getkinematics>`_.
186+
"""
187+
...

src/viam/components/gantry/service.py

Lines changed: 21 additions & 5 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
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
"""
@@ -103,11 +110,20 @@ async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -
103110
response = DoCommandResponse(result=dict_to_struct(result))
104111
await stream.send_message(response)
105112

113+
async def GetKinematics(self, stream: Stream[GetKinematicsRequest, GetKinematicsResponse]) -> None:
114+
request = await stream.recv_message()
115+
assert request is not None
116+
gantry = self.get_resource(request.name)
117+
timeout = stream.deadline.time_remaining() if stream.deadline else None
118+
format, data = await gantry.get_kinematics(extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata)
119+
response = GetKinematicsResponse(format=format, kinematics_data=data)
120+
await stream.send_message(response)
121+
106122
async def GetGeometries(self, stream: Stream[GetGeometriesRequest, GetGeometriesResponse]) -> None:
107123
request = await stream.recv_message()
108124
assert request is not None
109-
arm = self.get_resource(request.name)
125+
gantry = self.get_resource(request.name)
110126
timeout = stream.deadline.time_remaining() if stream.deadline else None
111-
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)
112128
response = GetGeometriesResponse(geometries=geometries)
113129
await stream.send_message(response)

src/viam/gen/app/v1/robot_pb2.py

Lines changed: 88 additions & 88 deletions
Large diffs are not rendered by default.

src/viam/gen/app/v1/robot_pb2.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class JobConfig(google.protobuf.message.Message):
179179
RESOURCE_FIELD_NUMBER: builtins.int
180180
METHOD_FIELD_NUMBER: builtins.int
181181
COMMAND_FIELD_NUMBER: builtins.int
182+
LOG_CONFIGURATION_FIELD_NUMBER: builtins.int
182183
name: builtins.str
183184
'unique name of the job.'
184185
schedule: builtins.str
@@ -194,13 +195,17 @@ class JobConfig(google.protobuf.message.Message):
194195
command argument of the gRPC request.
195196
"""
196197

197-
def __init__(self, *, name: builtins.str=..., schedule: builtins.str=..., resource: builtins.str=..., method: builtins.str=..., command: google.protobuf.struct_pb2.Struct | None=...) -> None:
198+
@property
199+
def log_configuration(self) -> global___LogConfiguration:
200+
"""configuration for this job's logger."""
201+
202+
def __init__(self, *, name: builtins.str=..., schedule: builtins.str=..., resource: builtins.str=..., method: builtins.str=..., command: google.protobuf.struct_pb2.Struct | None=..., log_configuration: global___LogConfiguration | None=...) -> None:
198203
...
199204

200-
def HasField(self, field_name: typing.Literal['command', b'command']) -> builtins.bool:
205+
def HasField(self, field_name: typing.Literal['command', b'command', 'log_configuration', b'log_configuration']) -> builtins.bool:
201206
...
202207

203-
def ClearField(self, field_name: typing.Literal['command', b'command', 'method', b'method', 'name', b'name', 'resource', b'resource', 'schedule', b'schedule']) -> None:
208+
def ClearField(self, field_name: typing.Literal['command', b'command', 'log_configuration', b'log_configuration', 'method', b'method', 'name', b'name', 'resource', b'resource', 'schedule', b'schedule']) -> None:
204209
...
205210
global___JobConfig = JobConfig
206211

src/viam/gen/component/gantry/v1/gantry_grpc.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ async def IsMoving(self, stream: 'grpclib.server.Stream[component.gantry.v1.gant
4040
async def DoCommand(self, stream: 'grpclib.server.Stream[common.v1.common_pb2.DoCommandRequest, common.v1.common_pb2.DoCommandResponse]') -> None:
4141
pass
4242

43+
@abc.abstractmethod
44+
async def GetKinematics(self, stream: 'grpclib.server.Stream[common.v1.common_pb2.GetKinematicsRequest, common.v1.common_pb2.GetKinematicsResponse]') -> None:
45+
pass
46+
4347
@abc.abstractmethod
4448
async def GetGeometries(self, stream: 'grpclib.server.Stream[common.v1.common_pb2.GetGeometriesRequest, common.v1.common_pb2.GetGeometriesResponse]') -> None:
4549
pass
4650

4751
def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]:
48-
return {'/viam.component.gantry.v1.GantryService/GetPosition': grpclib.const.Handler(self.GetPosition, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.GetPositionRequest, component.gantry.v1.gantry_pb2.GetPositionResponse), '/viam.component.gantry.v1.GantryService/MoveToPosition': grpclib.const.Handler(self.MoveToPosition, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.MoveToPositionRequest, component.gantry.v1.gantry_pb2.MoveToPositionResponse), '/viam.component.gantry.v1.GantryService/Home': grpclib.const.Handler(self.Home, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.HomeRequest, component.gantry.v1.gantry_pb2.HomeResponse), '/viam.component.gantry.v1.GantryService/GetLengths': grpclib.const.Handler(self.GetLengths, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.GetLengthsRequest, component.gantry.v1.gantry_pb2.GetLengthsResponse), '/viam.component.gantry.v1.GantryService/Stop': grpclib.const.Handler(self.Stop, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.StopRequest, component.gantry.v1.gantry_pb2.StopResponse), '/viam.component.gantry.v1.GantryService/IsMoving': grpclib.const.Handler(self.IsMoving, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.IsMovingRequest, component.gantry.v1.gantry_pb2.IsMovingResponse), '/viam.component.gantry.v1.GantryService/DoCommand': grpclib.const.Handler(self.DoCommand, grpclib.const.Cardinality.UNARY_UNARY, common.v1.common_pb2.DoCommandRequest, common.v1.common_pb2.DoCommandResponse), '/viam.component.gantry.v1.GantryService/GetGeometries': grpclib.const.Handler(self.GetGeometries, grpclib.const.Cardinality.UNARY_UNARY, common.v1.common_pb2.GetGeometriesRequest, common.v1.common_pb2.GetGeometriesResponse)}
52+
return {'/viam.component.gantry.v1.GantryService/GetPosition': grpclib.const.Handler(self.GetPosition, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.GetPositionRequest, component.gantry.v1.gantry_pb2.GetPositionResponse), '/viam.component.gantry.v1.GantryService/MoveToPosition': grpclib.const.Handler(self.MoveToPosition, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.MoveToPositionRequest, component.gantry.v1.gantry_pb2.MoveToPositionResponse), '/viam.component.gantry.v1.GantryService/Home': grpclib.const.Handler(self.Home, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.HomeRequest, component.gantry.v1.gantry_pb2.HomeResponse), '/viam.component.gantry.v1.GantryService/GetLengths': grpclib.const.Handler(self.GetLengths, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.GetLengthsRequest, component.gantry.v1.gantry_pb2.GetLengthsResponse), '/viam.component.gantry.v1.GantryService/Stop': grpclib.const.Handler(self.Stop, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.StopRequest, component.gantry.v1.gantry_pb2.StopResponse), '/viam.component.gantry.v1.GantryService/IsMoving': grpclib.const.Handler(self.IsMoving, grpclib.const.Cardinality.UNARY_UNARY, component.gantry.v1.gantry_pb2.IsMovingRequest, component.gantry.v1.gantry_pb2.IsMovingResponse), '/viam.component.gantry.v1.GantryService/DoCommand': grpclib.const.Handler(self.DoCommand, grpclib.const.Cardinality.UNARY_UNARY, common.v1.common_pb2.DoCommandRequest, common.v1.common_pb2.DoCommandResponse), '/viam.component.gantry.v1.GantryService/GetKinematics': grpclib.const.Handler(self.GetKinematics, grpclib.const.Cardinality.UNARY_UNARY, common.v1.common_pb2.GetKinematicsRequest, common.v1.common_pb2.GetKinematicsResponse), '/viam.component.gantry.v1.GantryService/GetGeometries': grpclib.const.Handler(self.GetGeometries, grpclib.const.Cardinality.UNARY_UNARY, common.v1.common_pb2.GetGeometriesRequest, common.v1.common_pb2.GetGeometriesResponse)}
4953

5054
class UnimplementedGantryServiceBase(GantryServiceBase):
5155

@@ -70,6 +74,9 @@ async def IsMoving(self, stream: 'grpclib.server.Stream[component.gantry.v1.gant
7074
async def DoCommand(self, stream: 'grpclib.server.Stream[common.v1.common_pb2.DoCommandRequest, common.v1.common_pb2.DoCommandResponse]') -> None:
7175
raise grpclib.exceptions.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
7276

77+
async def GetKinematics(self, stream: 'grpclib.server.Stream[common.v1.common_pb2.GetKinematicsRequest, common.v1.common_pb2.GetKinematicsResponse]') -> None:
78+
raise grpclib.exceptions.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
79+
7380
async def GetGeometries(self, stream: 'grpclib.server.Stream[common.v1.common_pb2.GetGeometriesRequest, common.v1.common_pb2.GetGeometriesResponse]') -> None:
7481
raise grpclib.exceptions.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
7582

@@ -83,4 +90,5 @@ def __init__(self, channel: grpclib.client.Channel) -> None:
8390
self.Stop = grpclib.client.UnaryUnaryMethod(channel, '/viam.component.gantry.v1.GantryService/Stop', component.gantry.v1.gantry_pb2.StopRequest, component.gantry.v1.gantry_pb2.StopResponse)
8491
self.IsMoving = grpclib.client.UnaryUnaryMethod(channel, '/viam.component.gantry.v1.GantryService/IsMoving', component.gantry.v1.gantry_pb2.IsMovingRequest, component.gantry.v1.gantry_pb2.IsMovingResponse)
8592
self.DoCommand = grpclib.client.UnaryUnaryMethod(channel, '/viam.component.gantry.v1.GantryService/DoCommand', common.v1.common_pb2.DoCommandRequest, common.v1.common_pb2.DoCommandResponse)
93+
self.GetKinematics = grpclib.client.UnaryUnaryMethod(channel, '/viam.component.gantry.v1.GantryService/GetKinematics', common.v1.common_pb2.GetKinematicsRequest, common.v1.common_pb2.GetKinematicsResponse)
8694
self.GetGeometries = grpclib.client.UnaryUnaryMethod(channel, '/viam.component.gantry.v1.GantryService/GetGeometries', common.v1.common_pb2.GetGeometriesRequest, common.v1.common_pb2.GetGeometriesResponse)

0 commit comments

Comments
 (0)