Skip to content

Commit 1f8e7f4

Browse files
RSDK-6171-add-client-api-for-debugging-grpc-calls (#384)
1 parent ded23f6 commit 1f8e7f4

File tree

23 files changed

+551
-262
lines changed

23 files changed

+551
-262
lines changed

src/components/arm/client.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Struct, type JsonValue } from '@bufbuild/protobuf';
2-
import type { PromiseClient } from '@connectrpc/connect';
2+
import type { CallOptions, PromiseClient } from '@connectrpc/connect';
33
import { ArmService } from '../../gen/component/arm/v1/arm_connect';
44
import {
55
GetEndPositionRequest,
@@ -24,30 +24,31 @@ export class ArmClient implements Arm {
2424
private client: PromiseClient<typeof ArmService>;
2525
private readonly name: string;
2626
private readonly options: Options;
27+
public callOptions: CallOptions = { headers: {} as Record<string, string> };
2728

2829
constructor(client: RobotClient, name: string, options: Options = {}) {
2930
this.client = client.createServiceClient(ArmService);
3031
this.name = name;
3132
this.options = options;
3233
}
3334

34-
async getEndPosition(extra = {}) {
35+
async getEndPosition(extra = {}, callOptions = this.callOptions) {
3536
const request = new GetEndPositionRequest({
3637
name: this.name,
3738
extra: Struct.fromJson(extra),
3839
});
3940

4041
this.options.requestLogger?.(request);
4142

42-
const response = await this.client.getEndPosition(request);
43+
const response = await this.client.getEndPosition(request, callOptions);
4344
const result = response.pose;
4445
if (!result) {
4546
throw new Error('no pose');
4647
}
4748
return result;
4849
}
4950

50-
async moveToPosition(pose: Pose, extra = {}) {
51+
async moveToPosition(pose: Pose, extra = {}, callOptions = this.callOptions) {
5152
const request = new MoveToPositionRequest({
5253
name: this.name,
5354
to: pose,
@@ -56,10 +57,14 @@ export class ArmClient implements Arm {
5657

5758
this.options.requestLogger?.(request);
5859

59-
await this.client.moveToPosition(request);
60+
await this.client.moveToPosition(request, callOptions);
6061
}
6162

62-
async moveToJointPositions(jointPositionsList: number[], extra = {}) {
63+
async moveToJointPositions(
64+
jointPositionsList: number[],
65+
extra = {},
66+
callOptions = this.callOptions
67+
) {
6368
const newJointPositions = new JointPositions({
6469
values: jointPositionsList,
6570
});
@@ -72,18 +77,18 @@ export class ArmClient implements Arm {
7277

7378
this.options.requestLogger?.(request);
7479

75-
await this.client.moveToJointPositions(request);
80+
await this.client.moveToJointPositions(request, callOptions);
7681
}
7782

78-
async getJointPositions(extra = {}) {
83+
async getJointPositions(extra = {}, callOptions = this.callOptions) {
7984
const request = new GetJointPositionsRequest({
8085
name: this.name,
8186
extra: Struct.fromJson(extra),
8287
});
8388

8489
this.options.requestLogger?.(request);
8590

86-
const response = await this.client.getJointPositions(request);
91+
const response = await this.client.getJointPositions(request, callOptions);
8792

8893
const result = response.positions;
8994
if (!result) {
@@ -92,34 +97,38 @@ export class ArmClient implements Arm {
9297
return result;
9398
}
9499

95-
async stop(extra = {}) {
100+
async stop(extra = {}, callOptions = this.callOptions) {
96101
const request = new StopRequest({
97102
name: this.name,
98103
extra: Struct.fromJson(extra),
99104
});
100105

101106
this.options.requestLogger?.(request);
102107

103-
await this.client.stop(request);
108+
await this.client.stop(request, callOptions);
104109
}
105110

106-
async isMoving() {
111+
async isMoving(callOptions = this.callOptions) {
107112
const request = new IsMovingRequest({
108113
name: this.name,
109114
});
110115

111116
this.options.requestLogger?.(request);
112117

113-
const resp = await this.client.isMoving(request);
118+
const resp = await this.client.isMoving(request, callOptions);
114119
return resp.isMoving;
115120
}
116121

117-
async doCommand(command: Struct): Promise<JsonValue> {
122+
async doCommand(
123+
command: Struct,
124+
callOptions = this.callOptions
125+
): Promise<JsonValue> {
118126
return doCommandFromClient(
119127
this.client.doCommand,
120128
this.name,
121129
command,
122-
this.options
130+
this.options,
131+
callOptions
123132
);
124133
}
125134
}

src/components/base/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface Base extends Resource {
5151
stop(extra?: Struct): Promise<void>;
5252

5353
/** Return true if the base is in motion. */
54-
isMoving(extra?: Struct): Promise<boolean>;
54+
isMoving(): Promise<boolean>;
5555

5656
/** Return the base's properties. */
5757
getProperties(extra?: Struct): Promise<BaseProperties>;

src/components/base/client.ts

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Struct, type JsonValue } from '@bufbuild/protobuf';
2-
import type { PromiseClient } from '@connectrpc/connect';
2+
import type { CallOptions, PromiseClient } from '@connectrpc/connect';
33
import { BaseService } from '../../gen/component/base/v1/base_connect';
44
import {
55
GetPropertiesRequest,
@@ -24,14 +24,20 @@ export class BaseClient implements Base {
2424
private client: PromiseClient<typeof BaseService>;
2525
private readonly name: string;
2626
private readonly options: Options;
27+
public callOptions: CallOptions = { headers: {} as Record<string, string> };
2728

2829
constructor(client: RobotClient, name: string, options: Options = {}) {
2930
this.client = client.createServiceClient(BaseService);
3031
this.name = name;
3132
this.options = options;
3233
}
3334

34-
async moveStraight(distanceMm: number, mmPerSec: number, extra = {}) {
35+
async moveStraight(
36+
distanceMm: number,
37+
mmPerSec: number,
38+
extra = {},
39+
callOptions = this.callOptions
40+
) {
3541
const request = new MoveStraightRequest({
3642
name: this.name,
3743
mmPerSec,
@@ -41,10 +47,15 @@ export class BaseClient implements Base {
4147

4248
this.options.requestLogger?.(request);
4349

44-
await this.client.moveStraight(request);
50+
await this.client.moveStraight(request, callOptions);
4551
}
4652

47-
async spin(angleDeg: number, degsPerSec: number, extra = {}) {
53+
async spin(
54+
angleDeg: number,
55+
degsPerSec: number,
56+
extra = {},
57+
callOptions = this.callOptions
58+
) {
4859
const request = new SpinRequest({
4960
name: this.name,
5061
angleDeg,
@@ -54,10 +65,15 @@ export class BaseClient implements Base {
5465

5566
this.options.requestLogger?.(request);
5667

57-
await this.client.spin(request);
68+
await this.client.spin(request, callOptions);
5869
}
5970

60-
async setPower(linear: Vector3, angular: Vector3, extra = {}) {
71+
async setPower(
72+
linear: Vector3,
73+
angular: Vector3,
74+
extra = {},
75+
callOptions = this.callOptions
76+
) {
6177
const request = new SetPowerRequest({
6278
name: this.name,
6379
linear,
@@ -67,10 +83,15 @@ export class BaseClient implements Base {
6783

6884
this.options.requestLogger?.(request);
6985

70-
await this.client.setPower(request);
86+
await this.client.setPower(request, callOptions);
7187
}
7288

73-
async setVelocity(linear: Vector3, angular: Vector3, extra = {}) {
89+
async setVelocity(
90+
linear: Vector3,
91+
angular: Vector3,
92+
extra = {},
93+
callOptions = this.callOptions
94+
) {
7495
const request = new SetVelocityRequest({
7596
name: this.name,
7697
linear,
@@ -80,48 +101,52 @@ export class BaseClient implements Base {
80101

81102
this.options.requestLogger?.(request);
82103

83-
await this.client.setVelocity(request);
104+
await this.client.setVelocity(request, callOptions);
84105
}
85106

86-
async stop(extra = {}) {
107+
async stop(extra = {}, callOptions = this.callOptions) {
87108
const request = new StopRequest({
88109
name: this.name,
89110
extra: Struct.fromJson(extra),
90111
});
91112

92113
this.options.requestLogger?.(request);
93114

94-
await this.client.stop(request);
115+
await this.client.stop(request, callOptions);
95116
}
96117

97-
async isMoving() {
118+
async isMoving(callOptions = this.callOptions) {
98119
const request = new IsMovingRequest({
99120
name: this.name,
100121
});
101122

102123
this.options.requestLogger?.(request);
103124

104-
const resp = await this.client.isMoving(request);
125+
const resp = await this.client.isMoving(request, callOptions);
105126
return resp.isMoving;
106127
}
107128

108-
async doCommand(command: Struct): Promise<JsonValue> {
129+
async doCommand(
130+
command: Struct,
131+
callOptions = this.callOptions
132+
): Promise<JsonValue> {
109133
return doCommandFromClient(
110134
this.client.doCommand,
111135
this.name,
112136
command,
113-
this.options
137+
this.options,
138+
callOptions
114139
);
115140
}
116141

117-
async getProperties(extra = {}) {
142+
async getProperties(extra = {}, callOptions = this.callOptions) {
118143
const request = new GetPropertiesRequest({
119144
name: this.name,
120145
extra: Struct.fromJson(extra),
121146
});
122147

123148
this.options.requestLogger?.(request);
124149

125-
return this.client.getProperties(request);
150+
return this.client.getProperties(request, callOptions);
126151
}
127152
}

0 commit comments

Comments
 (0)