@@ -18,9 +18,10 @@ import {
18
18
ListPlanStatusesRequest ,
19
19
MoveOnGlobeRequest ,
20
20
MoveOnGlobeResponse ,
21
+ MoveRequest ,
21
22
StopPlanRequest ,
22
23
} from '../../gen/service/motion/v1/motion_pb' ;
23
- import { GeoGeometry , GeoPoint , ResourceName } from '../../types' ;
24
+ import { GeoGeometry , GeoPoint , Pose , PoseInFrame , ResourceName } from '../../types' ;
24
25
import { MotionClient } from './client' ;
25
26
import {
26
27
GetPlanResponse ,
@@ -29,6 +30,7 @@ import {
29
30
ObstacleDetector ,
30
31
PlanState ,
31
32
} from './types' ;
33
+ import { Constraints , PseudolinearConstraint } from './types' ;
32
34
33
35
const motionClientName = 'test-motion' ;
34
36
const date = new Date ( 1970 , 1 , 1 , 1 , 1 , 1 ) ;
@@ -263,6 +265,66 @@ describe('moveOnGlobe', () => {
263
265
} ) ;
264
266
} ) ;
265
267
268
+ describe ( 'move' , ( ) => {
269
+ it ( 'sends a move request with pseudolinear constraints' , async ( ) => {
270
+ const expectedComponentName = new ResourceName ( {
271
+ namespace : 'viam' ,
272
+ type : 'component' ,
273
+ subtype : 'base' ,
274
+ name : 'myBase' ,
275
+ } ) ;
276
+ const expectedDestination : PoseInFrame = {
277
+ referenceFrame : 'world' ,
278
+ pose : {
279
+ x : 1 ,
280
+ y : 2 ,
281
+ z : 3 ,
282
+ oX : 0 ,
283
+ oY : 0 ,
284
+ oZ : 1 ,
285
+ theta : 90 ,
286
+ } ,
287
+ } ;
288
+ const expectedPseudolinearConstraint = new PseudolinearConstraint ( {
289
+ lineToleranceFactor : 0.5 ,
290
+ orientationToleranceFactor : 0.1 ,
291
+ } ) ;
292
+ const expectedConstraints : Constraints = {
293
+ pseudolinearConstraint : [ expectedPseudolinearConstraint ] ,
294
+ } ;
295
+ const expectedExtra = { some : 'extra' } ;
296
+ let capturedReq : MoveRequest | undefined ;
297
+ const mockTransport = createRouterTransport ( ( { service } ) => {
298
+ service ( MotionService , {
299
+ move : ( req ) => {
300
+ capturedReq = req ;
301
+ return { success : true } ;
302
+ } ,
303
+ } ) ;
304
+ } ) ;
305
+ RobotClient . prototype . createServiceClient = vi
306
+ . fn ( )
307
+ . mockImplementation ( ( ) =>
308
+ createPromiseClient ( MotionService , mockTransport )
309
+ ) ;
310
+ motion = new MotionClient ( new RobotClient ( 'host' ) , motionClientName ) ;
311
+ await expect (
312
+ motion . move (
313
+ expectedDestination ,
314
+ expectedComponentName ,
315
+ undefined , // worldState
316
+ expectedConstraints ,
317
+ expectedExtra
318
+ )
319
+ ) . resolves . toStrictEqual ( true ) ;
320
+ expect ( capturedReq ?. name ) . toStrictEqual ( motionClientName ) ;
321
+ expect ( capturedReq ?. destination ) . toStrictEqual ( expectedDestination ) ;
322
+ expect ( capturedReq ?. componentName ) . toStrictEqual ( expectedComponentName ) ;
323
+ expect ( capturedReq ?. constraints ) . toStrictEqual ( expectedConstraints ) ;
324
+ expect ( capturedReq ?. extra ) . toStrictEqual ( Struct . fromJson ( expectedExtra ) ) ;
325
+ } ) ;
326
+ } ) ;
327
+
266
328
describe ( 'stopPlan' , ( ) => {
267
329
it ( 'return null' , async ( ) => {
268
330
const expectedComponentName = new ResourceName ( {
@@ -525,4 +587,4 @@ describe('listPlanStatuses', () => {
525
587
expect ( capturedReq ?. onlyActivePlans ) . toStrictEqual ( expectedOnlyActivePlans ) ;
526
588
expect ( capturedReq ?. extra ) . toStrictEqual ( Struct . fromJson ( expectedExtra ) ) ;
527
589
} ) ;
528
- } ) ;
590
+ } ) ;
0 commit comments