viam.services.slam.service

Classes

DoCommandRequest

DoCommandRequest represents a generic DoCommand input

DoCommandResponse

DoCommandResponse represents a generic DoCommand output

GetInternalStateRequest

Abstract base class for protocol messages.

GetInternalStateResponse

Abstract base class for protocol messages.

GetPointCloudMapRequest

Abstract base class for protocol messages.

GetPointCloudMapResponse

Abstract base class for protocol messages.

GetPositionRequest

Abstract base class for protocol messages.

GetPositionResponse

Abstract base class for protocol messages.

GetPropertiesRequest

Abstract base class for protocol messages.

GetPropertiesResponse

Returns properties information for the named slam service

SLAMServiceBase

Helper class that provides a standard way to create an ABC using

ResourceRPCServiceBase

Base RPC service for a resource.

SLAM

SLAM represents a SLAM service.

SLAMRPCService

gRPC Service for a SLAM service

Functions

dict_to_struct(→ google.protobuf.struct_pb2.Struct)

struct_to_dict(→ Dict[str, ValueTypes])

Module Contents

class viam.services.slam.service.DoCommandRequest(*, name: str = ..., command: google.protobuf.struct_pb2.Struct | None = ...)

Bases: google.protobuf.message.Message

DoCommandRequest represents a generic DoCommand input

name: str
property command: google.protobuf.struct_pb2.Struct
HasField(field_name: Literal['command', b'command']) bool

Checks if a certain field is set for the message.

For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor, ValueError will be raised.

Parameters:

field_name (str) – The name of the field to check for presence.

Returns:

Whether a value has been set for the named field.

Return type:

bool

Raises:

ValueError – if the field_name is not a member of this message.

class viam.services.slam.service.DoCommandResponse(*, result: google.protobuf.struct_pb2.Struct | None = ...)

Bases: google.protobuf.message.Message

DoCommandResponse represents a generic DoCommand output

property result: google.protobuf.struct_pb2.Struct
HasField(field_name: Literal['result', b'result']) bool

Checks if a certain field is set for the message.

For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor, ValueError will be raised.

Parameters:

field_name (str) – The name of the field to check for presence.

Returns:

Whether a value has been set for the named field.

Return type:

bool

Raises:

ValueError – if the field_name is not a member of this message.

class viam.services.slam.service.GetInternalStateRequest(*, name: str = ...)

Bases: google.protobuf.message.Message

Abstract base class for protocol messages.

Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.

name: str

Name of slam service

class viam.services.slam.service.GetInternalStateResponse(*, internal_state_chunk: bytes = ...)

Bases: google.protobuf.message.Message

Abstract base class for protocol messages.

Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.

internal_state_chunk: bytes

Chunk of the internal state of the SLAM algorithm required to continue mapping/localization

class viam.services.slam.service.GetPointCloudMapRequest(*, name: str = ..., return_edited_map: bool | None = ...)

Bases: google.protobuf.message.Message

Abstract base class for protocol messages.

Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.

name: str

Name of slam service

return_edited_map: bool

For SLAM services that implement handling an edited map, this boolean should indicate whether to return that edited map. If the SLAM service does not handle edited maps, the unedited map will be returned instead.

HasField(field_name: Literal['_return_edited_map', b'_return_edited_map', 'return_edited_map', b'return_edited_map']) bool

Checks if a certain field is set for the message.

For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor, ValueError will be raised.

Parameters:

field_name (str) – The name of the field to check for presence.

Returns:

Whether a value has been set for the named field.

Return type:

bool

Raises:

ValueError – if the field_name is not a member of this message.

WhichOneof(oneof_group: Literal['_return_edited_map', b'_return_edited_map']) Literal['return_edited_map'] | None

Returns the name of the field that is set inside a oneof group.

If no field is set, returns None.

Parameters:

oneof_group (str) – the name of the oneof group to check.

Returns:

The name of the group that is set, or None.

Return type:

str or None

Raises:

ValueError – no group with the given name exists

class viam.services.slam.service.GetPointCloudMapResponse(*, point_cloud_pcd_chunk: bytes = ...)

Bases: google.protobuf.message.Message

Abstract base class for protocol messages.

Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.

point_cloud_pcd_chunk: bytes

One chunk of the PointCloud. For a given GetPointCloudMap request, concatenating all GetPointCloudMapResponse.point_cloud_pcd_chunk values in the order received result in the complete pointcloud in standard PCD format where XY is the ground plane and positive Z is up, following the Right Hand Rule.

Read more about the pointcloud format here: https://pointclouds.org/documentation/tutorials/pcd_file_format.html

Viam expects pointcloud data with fields “x y z” or “x y z rgb”, and for this to be specified in the pointcloud header in the FIELDS entry. If color data is included in the pointcloud, Viam’s services assume that the color value encodes a confidence score for that data point. Viam expects the confidence score to be encoded in the blue parameter of the RGB value, on a scale from 1-100.

Pointclouds are little endian encoded.

class viam.services.slam.service.GetPositionRequest(*, name: str = ...)

Bases: google.protobuf.message.Message

Abstract base class for protocol messages.

Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.

name: str

Name of slam service

class viam.services.slam.service.GetPositionResponse(*, pose: viam.gen.common.v1.common_pb2.Pose | None = ...)

Bases: google.protobuf.message.Message

Abstract base class for protocol messages.

Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.

property pose: viam.gen.common.v1.common_pb2.Pose

Current position of the specified component in the SLAM Map

HasField(field_name: Literal['pose', b'pose']) bool

Checks if a certain field is set for the message.

For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor, ValueError will be raised.

Parameters:

field_name (str) – The name of the field to check for presence.

Returns:

Whether a value has been set for the named field.

Return type:

bool

Raises:

ValueError – if the field_name is not a member of this message.

class viam.services.slam.service.GetPropertiesRequest(*, name: str = ...)

Bases: google.protobuf.message.Message

Abstract base class for protocol messages.

Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.

name: str

Name of the slam service

class viam.services.slam.service.GetPropertiesResponse(*, cloud_slam: bool = ..., mapping_mode: global___MappingMode = ..., internal_state_file_type: str | None = ..., sensor_info: collections.abc.Iterable[global___SensorInfo] | None = ...)

Bases: google.protobuf.message.Message

Returns properties information for the named slam service

cloud_slam: bool
mapping_mode: global___MappingMode
internal_state_file_type: str
property sensor_info: google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___SensorInfo]
HasField(field_name: Literal['_internal_state_file_type', b'_internal_state_file_type', 'internal_state_file_type', b'internal_state_file_type']) bool

Checks if a certain field is set for the message.

For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor, ValueError will be raised.

Parameters:

field_name (str) – The name of the field to check for presence.

Returns:

Whether a value has been set for the named field.

Return type:

bool

Raises:

ValueError – if the field_name is not a member of this message.

WhichOneof(oneof_group: Literal['_internal_state_file_type', b'_internal_state_file_type']) Literal['internal_state_file_type'] | None

Returns the name of the field that is set inside a oneof group.

If no field is set, returns None.

Parameters:

oneof_group (str) – the name of the oneof group to check.

Returns:

The name of the group that is set, or None.

Return type:

str or None

Raises:

ValueError – no group with the given name exists

class viam.services.slam.service.SLAMServiceBase[source]

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

abstract GetPosition(stream: grpclib.server.Stream[service.slam.v1.slam_pb2.GetPositionRequest, service.slam.v1.slam_pb2.GetPositionResponse]) None[source]
Async:

abstract GetPointCloudMap(stream: grpclib.server.Stream[service.slam.v1.slam_pb2.GetPointCloudMapRequest, service.slam.v1.slam_pb2.GetPointCloudMapResponse]) None[source]
Async:

abstract GetInternalState(stream: grpclib.server.Stream[service.slam.v1.slam_pb2.GetInternalStateRequest, service.slam.v1.slam_pb2.GetInternalStateResponse]) None[source]
Async:

abstract GetProperties(stream: grpclib.server.Stream[service.slam.v1.slam_pb2.GetPropertiesRequest, service.slam.v1.slam_pb2.GetPropertiesResponse]) None[source]
Async:

abstract DoCommand(stream: grpclib.server.Stream[common.v1.common_pb2.DoCommandRequest, common.v1.common_pb2.DoCommandResponse]) None[source]
Async:

__mapping__() Dict[str, grpclib.const.Handler][source]
class viam.services.slam.service.ResourceRPCServiceBase(manager: viam.resource.manager.ResourceManager)[source]

Bases: abc.ABC, viam.rpc.types.RPCServiceBase, Generic[viam.resource.manager.ResourceType]

Base RPC service for a resource. All resource RPC services must inherit from this class.

RESOURCE_TYPE
manager: viam.resource.manager.ResourceManager
get_resource(name: str) viam.resource.manager.ResourceType[source]

Return the resource with the given name if it exists in the registry. If the resource does not exist in the registry, this function will raise an error

Parameters:

name (str) – Name of the resource

Raises:

GRPCError with the status code Status.NOT_FOUND

Returns:

The resource

Return type:

ResourceType

viam.services.slam.service.dict_to_struct(obj: Mapping[str, ValueTypes]) google.protobuf.struct_pb2.Struct[source]
viam.services.slam.service.struct_to_dict(struct: google.protobuf.struct_pb2.Struct) Dict[str, ValueTypes][source]
class viam.services.slam.service.SLAM(name: str)[source]

Bases: viam.services.service_base.ServiceBase

SLAM represents a SLAM service.

This acts as an abstract base class for any drivers representing specific arm implementations. This cannot be used on its own. If the __init__() function is overridden, it must call the super().__init__() function.

SUBTYPE: Final
Properties: TypeAlias = GetPropertiesResponse
abstract get_internal_state(*, timeout: float | None) List[bytes][source]
Async:

Get the internal state of the SLAM algorithm required to continue mapping/localization.

slam = SLAMClient.from_robot(robot=robot, name="my_slam_service")

# Get the internal state of the SLAM algorithm required to continue mapping/localization.
internal_state = await slam.get_internal_state()
Returns:

Chunks of the internal state of the SLAM algorithm

Return type:

List[GetInternalStateResponse]

abstract get_point_cloud_map(return_edited_map: bool = False, *, timeout: float | None) List[bytes][source]
Async:

Get the point cloud map.

slam_svc = SLAMClient.from_robot(robot=robot, name="my_slam_service")

# Get the point cloud map in standard PCD format.
pcd_map = await slam_svc.get_point_cloud_map()
Parameters:

return_edited_map (bool) – signal to the SLAM service to return an edited map, if the map package contains one and if the SLAM service supports the feature

Returns:

Complete pointcloud in standard PCD format. Chunks of the PointCloud, concatenating all GetPointCloudMapResponse.point_cloud_pcd_chunk values.

Return type:

List[GetPointCloudMapResponse]

abstract get_position(*, timeout: float | None) viam.services.slam.Pose[source]
Async:

Get current position of the specified component in the SLAM Map.

slam_svc = SLAMClient.from_robot(robot=robot, name="my_slam_service")

# Get the current position of the specified source component in the SLAM map as a Pose.
pose = await slam.get_position()
Returns:

The current position of the specified component

Return type:

Pose

abstract get_properties(*, timeout: float | None) Properties[source]
Async:

Get information regarding the current SLAM session.

slam_svc = SLAMClient.from_robot(robot=robot, name="my_slam_service")

# Get the properties of your current SLAM session.
slam_properties = await slam_svc.get_properties()
Returns:

The properties of SLAM

Return type:

Properties

classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self

Get the service named name from the provided robot.

async def connect() -> ViamClient:
    # Replace "<API-KEY>" (including brackets) with your API key and "<API-KEY-ID>" with your API key ID
    dial_options = DialOptions.with_api_key("<API-KEY>", "<API-KEY-ID>")
    return await ViamClient.create_from_dial_options(dial_options)

async def main():
    robot = await connect()

    # Can be used with any resource, using the motion service as an example
    motion = MotionClient.from_robot(robot=robot, name="builtin")

    robot.close()
Parameters:
  • robot (RobotClient) – The robot

  • name (str) – The name of the service

Returns:

The service, if it exists on the robot

Return type:

Self

abstract do_command(command: Mapping[str, viam.utils.ValueTypes], *, timeout: float | None = None, **kwargs) Mapping[str, viam.utils.ValueTypes]
Async:

Send/receive arbitrary commands.

motion = MotionClient.from_robot(robot, "builtin")

my_command = {
  "cmnd": "dosomething",
  "someparameter": 52
}

# Can be used with any resource, using the motion service as an example
await motion.do_command(command=my_command)
Parameters:

command (Dict[str, ValueTypes]) – The command to execute

Returns:

Result of the executed command

Return type:

Dict[str, ValueTypes]

classmethod get_resource_name(name: str) viam.proto.common.ResourceName

Get the ResourceName for this Resource with the given name

# Can be used with any resource, using an arm as an example
my_arm_name = my_arm.get_resource_name("my_arm")
Parameters:

name (str) – The name of the Resource

Returns:

The ResourceName of this Resource

Return type:

ResourceName

get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation

Get the Operation associated with the currently running function.

When writing custom resources, you should get the Operation by calling this function and check to see if it’s cancelled. If the Operation is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).

Parameters:

kwargs (Mapping[str, Any]) – The kwargs object containing the operation

Returns:

The operation associated with this function

Return type:

viam.operations.Operation

async close()

Safely shut down the resource and prevent further use.

Close must be idempotent. Later configuration may allow a resource to be “open” again. If a resource does not want or need a close function, it is assumed that the resource does not need to return errors when future non-Close methods are called.

await component.close()
class viam.services.slam.service.SLAMRPCService(manager: viam.resource.manager.ResourceManager)[source]

Bases: viam.proto.service.slam.SLAMServiceBase, viam.resource.rpc_service_base.ResourceRPCServiceBase

gRPC Service for a SLAM service

RESOURCE_TYPE
async GetInternalState(stream: grpclib.server.Stream[viam.proto.service.slam.GetInternalStateRequest, viam.proto.service.slam.GetInternalStateResponse]) None[source]
async GetPointCloudMap(stream: grpclib.server.Stream[viam.proto.service.slam.GetPointCloudMapRequest, viam.proto.service.slam.GetPointCloudMapResponse]) None[source]
async GetPosition(stream: grpclib.server.Stream[viam.proto.service.slam.GetPositionRequest, viam.proto.service.slam.GetPositionResponse]) None[source]
async GetProperties(stream: grpclib.server.Stream[viam.proto.service.slam.GetPropertiesRequest, viam.proto.service.slam.GetPropertiesResponse]) None[source]
async DoCommand(stream: grpclib.server.Stream[viam.proto.common.DoCommandRequest, viam.proto.common.DoCommandResponse]) None[source]