11from grpclib .testing import ChannelFor
22
3+ from viam .components .arm import KinematicsFileFormat
34from viam .components .gantry import GantryClient
45from 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
67from 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