Skip to content

Commit 7b450ac

Browse files
authored
adding pose tracker to sdk (#615)
1 parent fe9315a commit 7b450ac

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { type JsonValue, Struct } from '@bufbuild/protobuf';
2+
import type { CallOptions, PromiseClient } from '@connectrpc/connect';
3+
import { PoseTrackerService } from '../../gen/component/posetracker/v1/pose_tracker_connect';
4+
import type { RobotClient } from '../../robot';
5+
import type { Options } from '../../types';
6+
import { doCommandFromClient } from '../../utils';
7+
import type { PoseTracker } from './pose-tracker';
8+
import { GetGeometriesRequest } from '../../gen/common/v1/common_pb';
9+
10+
/**
11+
* A gRPC-web client for the Generic component.
12+
*
13+
* @group Clients
14+
*/
15+
export class PoseTrackerClient implements PoseTracker {
16+
private client: PromiseClient<typeof PoseTrackerService>;
17+
public readonly name: string;
18+
private readonly options: Options;
19+
public callOptions: CallOptions = { headers: {} as Record<string, string> };
20+
21+
constructor(client: RobotClient, name: string, options: Options = {}) {
22+
this.client = client.createServiceClient(PoseTrackerService);
23+
this.name = name;
24+
this.options = options;
25+
}
26+
27+
async getGeometries(extra = {}, callOptions = this.callOptions) {
28+
const request = new GetGeometriesRequest({
29+
name: this.name,
30+
extra: Struct.fromJson(extra),
31+
});
32+
33+
const response = await this.client.getGeometries(request, callOptions);
34+
return response.geometries;
35+
}
36+
37+
async doCommand(
38+
command: Struct,
39+
callOptions = this.callOptions
40+
): Promise<JsonValue> {
41+
return doCommandFromClient(
42+
this.client.doCommand,
43+
this.name,
44+
command,
45+
this.options,
46+
callOptions
47+
);
48+
}
49+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Geometry } from '../../gen/common/v1/common_pb';
2+
import type { Struct, Resource } from '../../types';
3+
4+
/** Represents a generic component. */
5+
export interface PoseTracker extends Resource {
6+
/**
7+
* Get the geometries of the component in their current configuration.
8+
*
9+
* @example
10+
*
11+
* ```ts
12+
* const generic = new VIAM.GenericComponentClient(
13+
* machine,
14+
* 'my_generic_component'
15+
* );
16+
*
17+
* // Get the geometries of this component
18+
* const geometries = await generic.getGeometries();
19+
* console.log('Geometries:', geometries);
20+
* ```
21+
*
22+
* For more information, see [Generic
23+
* API](https://docs.viam.com/dev/reference/apis/components/generic/#getgeometries).
24+
*/
25+
getGeometries: (extra?: Struct) => Promise<Geometry[]>;
26+
}

src/components/posetracker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { PoseTrackerClient } from './pose-tracker/client';
2+
export type { PoseTracker } from './pose-tracker/pose-tracker';

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ export {
282282
GenericClient as GenericComponentClient,
283283
type Generic as GenericComponent,
284284
} from './components/generic';
285+
286+
export { PoseTrackerClient, type PoseTracker } from './components/posetracker';
287+
285288
/**
286289
* Raw Protobuf interfaces for a Generic component.
287290
*

0 commit comments

Comments
 (0)