From 4d26422ee772dffe65a7e6f7f3558f81c1672edd Mon Sep 17 00:00:00 2001 From: martha-johnston <106617924+martha-johnston@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:56:54 -0400 Subject: [PATCH] RSDK-4579: TypeScript SDK Base Properties (#156) --- src/components/base.ts | 2 +- src/components/base/base.ts | 6 ++++++ src/components/base/client.ts | 15 +++++++++++++++ src/main.ts | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/components/base.ts b/src/components/base.ts index 9c2782142..46f52f828 100644 --- a/src/components/base.ts +++ b/src/components/base.ts @@ -1,2 +1,2 @@ -export type { Base } from './base/base'; +export type { Base, BaseProperties } from './base/base'; export { BaseClient } from './base/client'; diff --git a/src/components/base/base.ts b/src/components/base/base.ts index 36625069c..6ccb1accf 100644 --- a/src/components/base/base.ts +++ b/src/components/base/base.ts @@ -1,4 +1,7 @@ import type { Resource, StructType, Vector3 } from '../../types'; +import pb from '../../gen/component/base/v1/base_pb'; + +export type BaseProperties = pb.GetPropertiesResponse.AsObject; /** Represents a physical base of a robot. */ export interface Base extends Resource { @@ -54,4 +57,7 @@ export interface Base extends Resource { /** Return true if the base is in motion. */ isMoving(extra?: StructType): Promise; + + /** Return the base's properties. */ + getProperties(extra?: StructType): Promise; } diff --git a/src/components/base/client.ts b/src/components/base/client.ts index 66b85ca52..63ea2e29a 100644 --- a/src/components/base/client.ts +++ b/src/components/base/client.ts @@ -123,4 +123,19 @@ export class BaseClient implements Base { const { baseService } = this; return doCommandFromClient(baseService, this.name, command, this.options); } + + async getProperties(extra = {}) { + const { baseService } = this; + const request = new pb.GetPropertiesRequest(); + request.setName(this.name); + request.setExtra(Struct.fromJavaScript(extra)); + + this.options.requestLogger?.(request); + + const response = await promisify< + pb.GetPropertiesRequest, + pb.GetPropertiesResponse + >(baseService.getProperties.bind(baseService), request); + return response.toObject(); + } } diff --git a/src/main.ts b/src/main.ts index c1e40eebc..3ca60eaad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -47,7 +47,7 @@ export { type Arm, ArmClient } from './components/arm'; * @group Raw Protobufs */ export { default as baseApi } from './gen/component/base/v1/base_pb'; -export { type Base, BaseClient } from './components/base'; +export { type Base, type BaseProperties, BaseClient } from './components/base'; /** * Raw Protobuf interfaces for a Board component.