Skip to content

Commit 48d1621

Browse files
authored
[RSDK-6871] add edited map to slam client (#556)
1 parent 1b3aba2 commit 48d1621

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

src/viam/services/slam/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ async def get_position(self, *, timeout: Optional[float] = None) -> Pose:
3737
response: GetPositionResponse = await self.client.GetPosition(request, timeout=timeout)
3838
return response.pose
3939

40-
async def get_point_cloud_map(self, *, timeout: Optional[float] = None) -> List[bytes]:
41-
request = GetPointCloudMapRequest(name=self.name)
40+
async def get_point_cloud_map(self, return_edited_map: bool = False, *, timeout: Optional[float] = None) -> List[bytes]:
41+
request = GetPointCloudMapRequest(name=self.name, return_edited_map=return_edited_map)
4242
response: List[GetPointCloudMapResponse] = await self.client.GetPointCloudMap(request, timeout=timeout)
4343
return [r.point_cloud_pcd_chunk for r in response]
4444

src/viam/services/slam/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def GetPointCloudMap(self, stream: Stream[GetPointCloudMapRequest, GetPoin
4242
name = request.name
4343
slam = self.get_resource(name)
4444
timeout = stream.deadline.time_remaining() if stream.deadline else None
45-
chunks = await slam.get_point_cloud_map(timeout=timeout)
45+
chunks = await slam.get_point_cloud_map(return_edited_map=request.return_edited_map, timeout=timeout)
4646
for chunk in chunks:
4747
response = GetPointCloudMapResponse(point_cloud_pcd_chunk=chunk)
4848
await stream.send_message(response)

src/viam/services/slam/slam.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def get_internal_state(self, *, timeout: Optional[float]) -> List[bytes]:
4545
...
4646

4747
@abc.abstractmethod
48-
async def get_point_cloud_map(self, *, timeout: Optional[float]) -> List[bytes]:
48+
async def get_point_cloud_map(self, return_edited_map: bool = False, *, timeout: Optional[float]) -> List[bytes]:
4949
"""
5050
Get the point cloud map.
5151
@@ -56,6 +56,10 @@ async def get_point_cloud_map(self, *, timeout: Optional[float]) -> List[bytes]:
5656
# Get the point cloud map in standard PCD format.
5757
pcd_map = await slam_svc.get_point_cloud_map()
5858
59+
Args:
60+
return_edited_map (bool): signal to the SLAM service to return an edited map, if the map package contains one and if
61+
the SLAM service supports the feature
62+
5963
Returns:
6064
List[GetPointCloudMapResponse]: Complete pointcloud in standard PCD format. Chunks of the PointCloud, concatenating all
6165
GetPointCloudMapResponse.point_cloud_pcd_chunk values

tests/mocks/services.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -
600600
class MockSLAM(SLAM):
601601
INTERNAL_STATE_CHUNKS = [bytes(5), bytes(2)]
602602
POINT_CLOUD_PCD_CHUNKS = [bytes(3), bytes(2)]
603+
POINT_CLOUD_PCD_CHUNKS_EDITED = [bytes(7), bytes(4)]
603604
POSITION = Pose(x=1, y=2, z=3, o_x=2, o_y=3, o_z=4, theta=20)
604605
CLOUD_SLAM = False
605606
MAPPING_MODE = MappingMode.MAPPING_MODE_UNSPECIFIED
@@ -624,8 +625,10 @@ async def get_internal_state(self, *, timeout: Optional[float] = None) -> List[b
624625
self.timeout = timeout
625626
return self.INTERNAL_STATE_CHUNKS
626627

627-
async def get_point_cloud_map(self, *, timeout: Optional[float] = None) -> List[bytes]:
628+
async def get_point_cloud_map(self, return_edited_map: bool = False, *, timeout: Optional[float] = None) -> List[bytes]:
628629
self.timeout = timeout
630+
if return_edited_map:
631+
return self.POINT_CLOUD_PCD_CHUNKS_EDITED
629632
return self.POINT_CLOUD_PCD_CHUNKS
630633

631634
async def get_position(self, *, timeout: Optional[float] = None) -> Pose:

tests/test_slam.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ async def test_get_point_cloud_map(self):
3636
chunks = await self.slam.get_point_cloud_map()
3737
assert chunks == MockSLAM.POINT_CLOUD_PCD_CHUNKS
3838

39+
async def test_get_point_cloud_map_return_edited(self):
40+
chunks = await self.slam.get_point_cloud_map(return_edited_map=True)
41+
assert chunks == MockSLAM.POINT_CLOUD_PCD_CHUNKS_EDITED
42+
3943
@pytest.mark.asyncio
4044
async def test_get_position(self):
4145
pos = await self.slam.get_position()

0 commit comments

Comments
 (0)