Skip to content

Commit f3fbb9f

Browse files
Rsdk 1831 slam wrapper (#272)
1 parent 73a8bc2 commit f3fbb9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+816
-443
lines changed

docs/examples/example.ipynb

Lines changed: 115 additions & 115 deletions
Large diffs are not rendered by default.

examples/module/src/summation/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
requests of the Summation service. It extends both from ``SummationServiceBase`` and ``RPCServiceBase``.
1414
The former is the gRPC service as defined by the proto, and the latter is the class that all gRPC services must inherit from.
1515
16-
Finally, the ``SummationServiceClient`` is the gRPC client for a Summation service. It inherits from SummationService since it implements
16+
Finally, the ``SummationClient`` is the gRPC client for a Summation service. It inherits from SummationService since it implements
1717
all the same functions. The implementations are simply gRPC calls to some remote Summation service.
1818
1919
To see how this custom modular service is registered, see the __init__.py file.

examples/server/v1/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ExampleServo,
2525
MovementSensor,
2626
)
27+
from .services import ExampleSLAM
2728

2829

2930
async def run(host: str, port: int, log_level: int):
@@ -69,8 +70,9 @@ async def run(host: str, port: int, log_level: int):
6970
my_pose_tracker = ExamplePoseTracker("pose_tracker0")
7071
my_sensor = ExampleSensor("sensor0")
7172
my_servo = ExampleServo("servo0")
73+
my_slam = ExampleSLAM("slam0")
7274
server = Server(
73-
components=[
75+
resources=[
7476
my_arm,
7577
my_audio_input,
7678
my_base,
@@ -84,6 +86,7 @@ async def run(host: str, port: int, log_level: int):
8486
my_pose_tracker,
8587
my_sensor,
8688
my_servo,
89+
my_slam,
8790
]
8891
)
8992
await server.serve(host=host, port=port, log_level=log_level)

examples/server/v1/services.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import List
2+
from viam.services.slam import Pose, SLAM
3+
from tests.mocks.services import MockSLAM
4+
5+
6+
class ExampleSLAM(SLAM):
7+
def __init__(self, name: str):
8+
self.position = MockSLAM.POSITION
9+
self.internal_chunks = MockSLAM.INTERNAL_STATE_CHUNKS
10+
self.point_cloud_chunks = MockSLAM.POINT_CLOUD_PCD_CHUNKS
11+
super().__init__(name)
12+
13+
async def get_internal_state(self, **kwargs) -> List[bytes]:
14+
return self.internal_chunks
15+
16+
async def get_point_cloud_map(self, **kwargs) -> List[bytes]:
17+
return self.point_cloud_chunks
18+
19+
async def get_position(self, **kwargs) -> Pose:
20+
return self.position

src/viam/components/arm/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .arm import Arm
1111
from .client import ArmClient
12-
from .service import ArmService
12+
from .service import ArmRPCService
1313

1414
__all__ = [
1515
"Arm",
@@ -19,11 +19,7 @@
1919

2020

2121
async def create_status(component: Arm) -> Status:
22-
(
23-
end_position,
24-
joint_positions,
25-
is_moving,
26-
) = await asyncio.gather(
22+
(end_position, joint_positions, is_moving,) = await asyncio.gather(
2723
component.get_end_position(),
2824
component.get_joint_positions(),
2925
component.is_moving(),
@@ -36,4 +32,4 @@ async def create_status(component: Arm) -> Status:
3632
return Status(name=Arm.get_resource_name(component.name), status=message_to_struct(s))
3733

3834

39-
Registry.register_subtype(ResourceRegistration(Arm, ArmService, lambda name, channel: ArmClient(name, channel), create_status))
35+
Registry.register_subtype(ResourceRegistration(Arm, ArmRPCService, lambda name, channel: ArmClient(name, channel), create_status))

src/viam/components/arm/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .arm import Arm
2424

2525

26-
class ArmService(ArmServiceBase, ResourceRPCServiceBase[Arm]):
26+
class ArmRPCService(ArmServiceBase, ResourceRPCServiceBase[Arm]):
2727
"""
2828
gRPC Service for an Arm
2929
"""

src/viam/components/audio_input/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .audio_input import AudioInput
44
from .client import AudioInputClient
5-
from .service import AudioInputService
5+
from .service import AudioInputRPCService
66

77
__all__ = [
88
"AudioInput",
@@ -12,7 +12,7 @@
1212
Registry.register_subtype(
1313
ResourceRegistration(
1414
AudioInput,
15-
AudioInputService,
15+
AudioInputRPCService,
1616
lambda name, channel: AudioInputClient(name, channel),
1717
)
1818
)

src/viam/components/audio_input/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .audio_input import AudioInput
2424

2525

26-
class AudioInputService(AudioInputServiceBase, ResourceRPCServiceBase[AudioInput]):
26+
class AudioInputRPCService(AudioInputServiceBase, ResourceRPCServiceBase[AudioInput]):
2727
"""
2828
gRPC Service for a generic AudioInput
2929
"""

src/viam/components/base/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from .base import Base
77
from .client import BaseClient
8-
from .service import BaseService
8+
from .service import BaseRPCService
99

1010
__all__ = ["Base", "Vector3"]
1111

@@ -15,4 +15,4 @@ async def create_status(component: Base) -> Status:
1515
return Status(name=Base.get_resource_name(component.name), status=message_to_struct(s))
1616

1717

18-
Registry.register_subtype(ResourceRegistration(Base, BaseService, lambda name, channel: BaseClient(name, channel), create_status))
18+
Registry.register_subtype(ResourceRegistration(Base, BaseRPCService, lambda name, channel: BaseClient(name, channel), create_status))

src/viam/components/base/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .base import Base
2424

2525

26-
class BaseService(BaseServiceBase, ResourceRPCServiceBase[Base]):
26+
class BaseRPCService(BaseServiceBase, ResourceRPCServiceBase[Base]):
2727
"""
2828
gRPC service for a robotic Base
2929
"""

0 commit comments

Comments
 (0)