Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0c8ee93
add slam service client, mock, and test
purplenicole730 Apr 25, 2023
f9c13ce
fix get_internal and get_pcm functions to expect lists
purplenicole730 Apr 26, 2023
adc08bb
test multiple chunks for get_internal_state and get_pcm
purplenicole730 Apr 26, 2023
10ceaf8
add abstract slam class and slamservice service files
purplenicole730 Apr 26, 2023
feb6e24
add server and slam class tests
purplenicole730 Apr 26, 2023
b1c8511
use responses in test service assertions
purplenicole730 Apr 26, 2023
ff2ed67
add example slam
purplenicole730 Apr 28, 2023
fed4971
remove name as an argument
purplenicole730 Apr 28, 2023
1276d47
change service name to be more clear
purplenicole730 Apr 28, 2023
3c55626
rename test file
purplenicole730 Apr 28, 2023
7982fab
add example slam
purplenicole730 Apr 28, 2023
8e65707
fix comments
purplenicole730 Apr 28, 2023
b6a99d2
fix circular import
purplenicole730 Apr 28, 2023
67ab3dc
clean up imports
purplenicole730 Apr 28, 2023
6ab4a12
rename slam class to be slamservice
purplenicole730 Apr 28, 2023
f79c704
fix comments
purplenicole730 Apr 28, 2023
ea039f1
clean up imports
purplenicole730 Apr 28, 2023
9c72391
add "service" to slam examples and mocks
purplenicole730 Apr 28, 2023
6f71b42
fix name
purplenicole730 Apr 28, 2023
007ba1a
nits
purplenicole730 May 1, 2023
058bc96
fix var name
purplenicole730 May 1, 2023
6040daf
keep client naming consistent
purplenicole730 May 1, 2023
2b62e76
make service name consistent across services and components
purplenicole730 May 1, 2023
47b10c9
Merge branch 'main' into RSDK-1831-slam-wrapper
purplenicole730 May 1, 2023
8a9d522
cleanup
purplenicole730 May 1, 2023
166c020
call mock properties from mock in examples
purplenicole730 May 1, 2023
a61b1f7
define mock properties in mock class
purplenicole730 May 1, 2023
7401614
fix docs for service clients
purplenicole730 May 1, 2023
77ff830
rely on MockSLAM for test constants
purplenicole730 May 1, 2023
244298a
rename components to resources
purplenicole730 May 1, 2023
1dbd449
fix keyword
purplenicole730 May 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 115 additions & 115 deletions docs/examples/example.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/module/src/summation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
requests of the Summation service. It extends both from ``SummationServiceBase`` and ``RPCServiceBase``.
The former is the gRPC service as defined by the proto, and the latter is the class that all gRPC services must inherit from.

Finally, the ``SummationServiceClient`` is the gRPC client for a Summation service. It inherits from SummationService since it implements
Finally, the ``SummationClient`` is the gRPC client for a Summation service. It inherits from SummationService since it implements
all the same functions. The implementations are simply gRPC calls to some remote Summation service.

To see how this custom modular service is registered, see the __init__.py file.
Expand Down
5 changes: 4 additions & 1 deletion examples/server/v1/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ExampleServo,
MovementSensor,
)
from .services import ExampleSLAM


async def run(host: str, port: int, log_level: int):
Expand Down Expand Up @@ -69,8 +70,9 @@ async def run(host: str, port: int, log_level: int):
my_pose_tracker = ExamplePoseTracker("pose_tracker0")
my_sensor = ExampleSensor("sensor0")
my_servo = ExampleServo("servo0")
my_slam = ExampleSLAM("slam0")
server = Server(
components=[
resources=[
my_arm,
my_audio_input,
my_base,
Expand All @@ -84,6 +86,7 @@ async def run(host: str, port: int, log_level: int):
my_pose_tracker,
my_sensor,
my_servo,
my_slam,
]
)
await server.serve(host=host, port=port, log_level=log_level)
Expand Down
20 changes: 20 additions & 0 deletions examples/server/v1/services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import List
from viam.services.slam import Pose, SLAM
from tests.mocks.services import MockSLAM


class ExampleSLAM(SLAM):
def __init__(self, name: str):
self.position = MockSLAM.POSITION
self.internal_chunks = MockSLAM.INTERNAL_STATE_CHUNKS
self.point_cloud_chunks = MockSLAM.POINT_CLOUD_PCD_CHUNKS
super().__init__(name)

async def get_internal_state(self, **kwargs) -> List[bytes]:
return self.internal_chunks

async def get_point_cloud_map(self, **kwargs) -> List[bytes]:
return self.point_cloud_chunks

async def get_position(self, **kwargs) -> Pose:
return self.position
10 changes: 3 additions & 7 deletions src/viam/components/arm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .arm import Arm
from .client import ArmClient
from .service import ArmService
from .service import ArmRPCService

__all__ = [
"Arm",
Expand All @@ -19,11 +19,7 @@


async def create_status(component: Arm) -> Status:
(
end_position,
joint_positions,
is_moving,
) = await asyncio.gather(
(end_position, joint_positions, is_moving,) = await asyncio.gather(
component.get_end_position(),
component.get_joint_positions(),
component.is_moving(),
Expand All @@ -36,4 +32,4 @@ async def create_status(component: Arm) -> Status:
return Status(name=Arm.get_resource_name(component.name), status=message_to_struct(s))


Registry.register_subtype(ResourceRegistration(Arm, ArmService, lambda name, channel: ArmClient(name, channel), create_status))
Registry.register_subtype(ResourceRegistration(Arm, ArmRPCService, lambda name, channel: ArmClient(name, channel), create_status))
2 changes: 1 addition & 1 deletion src/viam/components/arm/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .arm import Arm


class ArmService(ArmServiceBase, ResourceRPCServiceBase[Arm]):
class ArmRPCService(ArmServiceBase, ResourceRPCServiceBase[Arm]):
"""
gRPC Service for an Arm
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/audio_input/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .audio_input import AudioInput
from .client import AudioInputClient
from .service import AudioInputService
from .service import AudioInputRPCService

__all__ = [
"AudioInput",
Expand All @@ -12,7 +12,7 @@
Registry.register_subtype(
ResourceRegistration(
AudioInput,
AudioInputService,
AudioInputRPCService,
lambda name, channel: AudioInputClient(name, channel),
)
)
2 changes: 1 addition & 1 deletion src/viam/components/audio_input/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .audio_input import AudioInput


class AudioInputService(AudioInputServiceBase, ResourceRPCServiceBase[AudioInput]):
class AudioInputRPCService(AudioInputServiceBase, ResourceRPCServiceBase[AudioInput]):
"""
gRPC Service for a generic AudioInput
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .base import Base
from .client import BaseClient
from .service import BaseService
from .service import BaseRPCService

__all__ = ["Base", "Vector3"]

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


Registry.register_subtype(ResourceRegistration(Base, BaseService, lambda name, channel: BaseClient(name, channel), create_status))
Registry.register_subtype(ResourceRegistration(Base, BaseRPCService, lambda name, channel: BaseClient(name, channel), create_status))
2 changes: 1 addition & 1 deletion src/viam/components/base/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .base import Base


class BaseService(BaseServiceBase, ResourceRPCServiceBase[Base]):
class BaseRPCService(BaseServiceBase, ResourceRPCServiceBase[Base]):
"""
gRPC service for a robotic Base
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/board/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .board import Board
from .client import BoardClient
from .service import BoardService
from .service import BoardRPCService

__all__ = [
"Board",
Expand All @@ -15,4 +15,4 @@ async def create_status(component: Board) -> Status:
return Status(name=Board.get_resource_name(component.name), status=message_to_struct(await component.status()))


Registry.register_subtype(ResourceRegistration(Board, BoardService, lambda name, channel: BoardClient(name, channel), create_status))
Registry.register_subtype(ResourceRegistration(Board, BoardRPCService, lambda name, channel: BoardClient(name, channel), create_status))
2 changes: 1 addition & 1 deletion src/viam/components/board/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .board import Board


class BoardService(BoardServiceBase, ResourceRPCServiceBase[Board]):
class BoardRPCService(BoardServiceBase, ResourceRPCServiceBase[Board]):
"""
gRPC Service for a Board
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .camera import Camera
from .client import CameraClient
from .service import CameraService
from .service import CameraRPCService

__all__ = [
"Camera",
Expand All @@ -16,7 +16,7 @@
Registry.register_subtype(
ResourceRegistration(
Camera,
CameraService,
CameraRPCService,
lambda name, channel: CameraClient(name, channel),
)
)
2 changes: 1 addition & 1 deletion src/viam/components/camera/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from . import Camera, RawImage


class CameraService(CameraServiceBase, ResourceRPCServiceBase[Camera]):
class CameraRPCService(CameraServiceBase, ResourceRPCServiceBase[Camera]):
"""
gRPC Service for a generic Camera
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/encoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .client import EncoderClient
from .encoder import Encoder
from .service import EncoderService
from .service import EncoderRPCService

__all__ = [
"Encoder",
Expand All @@ -12,7 +12,7 @@
Registry.register_subtype(
ResourceRegistration(
Encoder,
EncoderService,
EncoderRPCService,
lambda name, channel: EncoderClient(name, channel),
)
)
2 changes: 1 addition & 1 deletion src/viam/components/encoder/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .encoder import Encoder


class EncoderService(EncoderServiceBase, ResourceRPCServiceBase[Encoder]):
class EncoderRPCService(EncoderServiceBase, ResourceRPCServiceBase[Encoder]):
"""
gRPC Service for an Encoder
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/gantry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .client import GantryClient
from .gantry import Gantry
from .service import GantryService
from .service import GantryRPCService

__all__ = [
"Gantry",
Expand All @@ -20,4 +20,4 @@ async def create_status(component: Gantry) -> Status:
return Status(name=Gantry.get_resource_name(component.name), status=message_to_struct(s))


Registry.register_subtype(ResourceRegistration(Gantry, GantryService, lambda name, channel: GantryClient(name, channel), create_status))
Registry.register_subtype(ResourceRegistration(Gantry, GantryRPCService, lambda name, channel: GantryClient(name, channel), create_status))
2 changes: 1 addition & 1 deletion src/viam/components/gantry/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .gantry import Gantry


class GantryService(GantryServiceBase, ResourceRPCServiceBase[Gantry]):
class GantryRPCService(GantryServiceBase, ResourceRPCServiceBase[Gantry]):
"""
gRPC Service for a Gantry
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/generic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .client import GenericClient
from .generic import Generic
from .service import GenericService
from .service import GenericRPCService

__all__ = [
"Generic",
Expand All @@ -12,7 +12,7 @@
Registry.register_subtype(
ResourceRegistration(
Generic,
GenericService,
GenericRPCService,
lambda name, channel: GenericClient(name, channel),
)
)
2 changes: 1 addition & 1 deletion src/viam/components/generic/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# from .generic import Generic


class GenericService(GenericServiceBase, ResourceRPCServiceBase[ComponentBase]):
class GenericRPCService(GenericServiceBase, ResourceRPCServiceBase[ComponentBase]):
"""
gRPC Service for a Generic component
"""
Expand Down
6 changes: 4 additions & 2 deletions src/viam/components/gripper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .client import GripperClient
from .gripper import Gripper
from .service import GripperService
from .service import GripperRPCService

__all__ = [
"Gripper",
Expand All @@ -18,4 +18,6 @@ async def create_status(component: Gripper) -> Status:
return Status(name=Gripper.get_resource_name(component.name), status=message_to_struct(s))


Registry.register_subtype(ResourceRegistration(Gripper, GripperService, lambda name, channel: GripperClient(name, channel), create_status))
Registry.register_subtype(
ResourceRegistration(Gripper, GripperRPCService, lambda name, channel: GripperClient(name, channel), create_status)
)
2 changes: 1 addition & 1 deletion src/viam/components/gripper/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .gripper import Gripper


class GripperService(GripperServiceBase, ResourceRPCServiceBase[Gripper]):
class GripperRPCService(GripperServiceBase, ResourceRPCServiceBase[Gripper]):
"""
gRPC Service for a Gripper
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/input/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .client import ControllerClient
from .input import Control, ControlFunction, Controller, Event, EventType
from .service import InputControllerService
from .service import InputControllerRPCService

__all__ = [
"Controller",
Expand All @@ -24,5 +24,5 @@ async def create_status(component: Controller) -> Status:


Registry.register_subtype(
ResourceRegistration(Controller, InputControllerService, lambda name, channel: ControllerClient(name, channel), create_status)
ResourceRegistration(Controller, InputControllerRPCService, lambda name, channel: ControllerClient(name, channel), create_status)
)
2 changes: 1 addition & 1 deletion src/viam/components/input/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
LOGGER = viam.logging.getLogger(__name__)


class InputControllerService(InputControllerServiceBase, ResourceRPCServiceBase[Controller]):
class InputControllerRPCService(InputControllerServiceBase, ResourceRPCServiceBase[Controller]):
"""
gRPC Service for an input controller
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/motor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .client import MotorClient
from .motor import Motor
from .service import MotorService
from .service import MotorRPCService

__all__ = [
"Motor",
Expand All @@ -28,4 +28,4 @@ async def create_status(component: Motor) -> Status:
return Status(name=Motor.get_resource_name(component.name), status=message_to_struct(s))


Registry.register_subtype(ResourceRegistration(Motor, MotorService, lambda name, channel: MotorClient(name, channel), create_status))
Registry.register_subtype(ResourceRegistration(Motor, MotorRPCService, lambda name, channel: MotorClient(name, channel), create_status))
2 changes: 1 addition & 1 deletion src/viam/components/motor/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .motor import Motor


class MotorService(MotorServiceBase, ResourceRPCServiceBase[Motor]):
class MotorRPCService(MotorServiceBase, ResourceRPCServiceBase[Motor]):
"""
gRPC Service for a Motor
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/movement_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .client import MovementSensorClient
from .movement_sensor import MovementSensor
from .service import MovementSensorService
from .service import MovementSensorRPCService

__all__ = [
"MovementSensor",
Expand All @@ -15,7 +15,7 @@
Registry.register_subtype(
ResourceRegistration(
MovementSensor,
MovementSensorService,
MovementSensorRPCService,
lambda name, channel: MovementSensorClient(name, channel),
)
)
2 changes: 1 addition & 1 deletion src/viam/components/movement_sensor/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from viam.utils import dict_to_struct, struct_to_dict


class MovementSensorService(MovementSensorServiceBase, ResourceRPCServiceBase[MovementSensor]):
class MovementSensorRPCService(MovementSensorServiceBase, ResourceRPCServiceBase[MovementSensor]):
"""
gRPC Service for a MovementSensor
"""
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/pose_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .client import PoseTrackerClient
from .pose_tracker import PoseTracker
from .service import PoseTrackerService
from .service import PoseTrackerRPCService

__all__ = [
"PoseTracker",
Expand All @@ -11,7 +11,7 @@
Registry.register_subtype(
ResourceRegistration(
PoseTracker,
PoseTrackerService,
PoseTrackerRPCService,
lambda name, channel: PoseTrackerClient(name, channel),
)
)
Loading