Skip to content

Commit 13194c4

Browse files
authored
[RSDK-6871] add edited map to slam client (#261)
1 parent e8017fe commit 13194c4

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/services/slam/client.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ vi.mock('../../robot');
99
import { EventDispatcher } from '../../events';
1010
import {
1111
GetInternalStateResponse,
12+
GetPointCloudMapRequest,
1213
GetPointCloudMapResponse,
1314
} from '../../gen/service/slam/v1/slam_pb';
1415
import { SlamClient } from './client';
@@ -39,21 +40,34 @@ export class TestResponseStream<T> extends EventDispatcher {
3940

4041
let pcdStream: ResponseStream<GetPointCloudMapResponse>;
4142
let testPcdStream: TestResponseStream<GetPointCloudMapResponse> | undefined;
43+
let testPcdStreamEdited:
44+
| TestResponseStream<GetPointCloudMapResponse>
45+
| undefined;
4246
let internalStream: ResponseStream<GetInternalStateResponse>;
4347
let testInternalStream:
4448
| TestResponseStream<GetInternalStateResponse>
4549
| undefined;
4650

51+
const pointCloudMapMockfn = (
52+
requestMessage: GetPointCloudMapRequest
53+
): TestResponseStream<GetPointCloudMapResponse> | undefined => {
54+
if (requestMessage.getReturnEditedMap()) {
55+
return testPcdStreamEdited;
56+
}
57+
return testPcdStream;
58+
};
59+
4760
beforeEach(() => {
4861
testPcdStream = new TestResponseStream(pcdStream);
62+
testPcdStreamEdited = new TestResponseStream(pcdStream);
4963
testInternalStream = new TestResponseStream(internalStream);
5064
RobotClient.prototype.createServiceClient = vi
5165
.fn()
5266
.mockImplementation(() => new SLAMServiceClient('myslam'));
5367

5468
SLAMServiceClient.prototype.getPointCloudMap = vi
5569
.fn()
56-
.mockImplementation(() => testPcdStream);
70+
.mockImplementation(pointCloudMapMockfn);
5771
SLAMServiceClient.prototype.getInternalState = vi
5872
.fn()
5973
.mockImplementation(() => testInternalStream);
@@ -83,6 +97,24 @@ describe('getPointCloudMap tests', () => {
8397

8498
const array = new Uint8Array([4, 13, 16, 25]);
8599
expect(promise).resolves.toStrictEqual(array);
100+
101+
// test map edit bool
102+
const promiseEdit = slam.getPointCloudMap(true);
103+
// unused chunk
104+
const response3 = new GetPointCloudMapResponse();
105+
const chunk3 = new Uint8Array([4, 27]);
106+
response3.setPointCloudPcdChunk(chunk3);
107+
testPcdStream?.emit('data', response3);
108+
testPcdStream?.emit('end', { code: 0 });
109+
// used chunk
110+
const response3Edited = new GetPointCloudMapResponse();
111+
const chunk3Edited = new Uint8Array([5, 38]);
112+
response3Edited.setPointCloudPcdChunk(chunk3Edited);
113+
testPcdStreamEdited?.emit('data', response3Edited);
114+
testPcdStreamEdited?.emit('end', { code: 0 });
115+
116+
const arrayEdit = new Uint8Array([5, 38]);
117+
expect(promiseEdit).resolves.toStrictEqual(arrayEdit);
86118
});
87119

88120
it('end getPcdMap stream with wrong code', () => {

src/services/slam/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ export class SlamClient implements Slam {
4141
return response.toObject();
4242
}
4343

44-
getPointCloudMap = async (): Promise<Uint8Array> => {
44+
getPointCloudMap = async (returnEditedMap?: boolean): Promise<Uint8Array> => {
4545
const request = new pb.GetPointCloudMapRequest();
4646
request.setName(this.name);
47+
if (returnEditedMap) {
48+
request.setReturnEditedMap(returnEditedMap);
49+
}
4750
this.options.requestLogger?.(request);
4851

4952
const chunks: Uint8Array[] = [];

src/services/slam/slam.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface Slam extends Resource {
1313
getPosition: () => Promise<SlamPosition>;
1414

1515
/** Get the point cloud SLAM map. */
16-
getPointCloudMap: () => Promise<Uint8Array>;
16+
getPointCloudMap: (returnEditedMap?: boolean) => Promise<Uint8Array>;
1717

1818
/**
1919
* Get the internal state of the SLAM algorithm required to continue

0 commit comments

Comments
 (0)