SLAM Service

Simultaneous Localization And Mapping (SLAM) allows your machine to create a map of its surroundings and find its location within that map. SLAM is an important area of ongoing research in robotics, particularly for mobile applications such as drones, boats, and rovers.

The Viam SLAM service supports the integration of SLAM as a service on your machine. You can conduct SLAM with data collected live by a RPlidar or with LIDAR data you provide in configuration, and easily view the map you build on the SLAM library tab of your location’s page in the Viam app:

Completed SLAM maps in the SLAM library tab

Used with

* Required for use

Configuration

Integrated SLAM libraries include the following. Click the model name for configuration instructions.

ModelDescription
viam:slam:cartographerThe Cartographer Project performs dense SLAM using LIDAR data.

API

The SLAM service supports the following methods:

Method NameDescription
GetPositionGet the current position of the component the SLAM service is configured to source point cloud data from in the SLAM map as a Pose.
GetPointCloudMapGet the point cloud map.
GetInternalStateGet the internal state of the SLAM algorithm required to continue mapping/localization.
GetPropertiesGet information about the current SLAM session.
InternalStateFullInternalStateFull concatenates the streaming responses from InternalState into the internal serialized state of the SLAM algorithm.
PointCloudMapFullPointCloudMapFull concatenates the streaming responses from PointCloudMap into a full point cloud.
ReconfigureReconfigure this resource.
DoCommandExecute model-specific commands that are not otherwise defined by the service API.
GetResourceNameGet the ResourceName for this instance of the SLAM service with the given name.
CloseSafely shut down the resource and prevent further use.

GetPosition

Get the current position of the component the SLAM service is configured to source point cloud data from in the SLAM map as a Pose.

Parameters:

  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

Example:

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()

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

Example:

// Get the current position of the specified source component
// in the SLAM map as a Pose.
pos, name, err := mySLAMService.Position(context.Background())

For more information, see the Go SDK Docs.

GetPointCloudMap

Get the point cloud map.

Parameters:

  • return_edited_map (bool) (required): signal to the SLAM service to return an edited map, if the map package contains one and if the SLAM service supports the feature.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (List[bytes]): Complete pointcloud in standard PCD format. Chunks of the PointCloud, concatenating all GetPointCloudMapResponse.point_cloud_pcd_chunk values.

Example:

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()

For more information, see the Python SDK Docs.

GetInternalState

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

Parameters:

  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (List[bytes]): Chunks of the internal state of the SLAM algorithm.

Example:

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()

For more information, see the Python SDK Docs.

GetProperties

Get information about the current SLAM session.

Parameters:

  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (viam.services.slam.slam.SLAM.Properties): The properties of SLAM.

Example:

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()

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (Properties): Information about the current SLAM session. An object containing four fields:

    • SensorInfo (SensorInfo[]): Information about the sensors (camera and movement sensor) configured for your SLAM service, including the name and type of sensor.
    • CloudSlam (bool): A boolean which indicates whether the session is being run in the cloud.
    • MappingMode (MappingMode): Represents the form of mapping and localizing the current session is performing. This includes creating a new map, localizing on an existing map and updating an existing map.
    • InternalStateFileType (string): The file type the service’s internal state algorithm is stored in.
  • (error): An error, if one occurred.

Example:

// Get the properties of your current SLAM session
properties, err := mySLAMService.Properties(context.Background())

For more information, see the Go SDK Docs.

InternalStateFull

InternalStateFull concatenates the streaming responses from InternalState into the internal serialized state of the SLAM algorithm.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • slamSvc (Service): The SLAM service name to fetch the internal state for.

Returns:

  • ([]byte): A byte value representing the internal serialized state of the SLAM algorithm.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

PointCloudMapFull

PointCloudMapFull concatenates the streaming responses from PointCloudMap into a full point cloud.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • slamSvc (Service): The SLAM service name to fetch the point cloud map for.
  • returnEditedMap (bool): A boolean representing whether to return the edited map (true) or not (false).

Returns:

For more information, see the Go SDK Docs.

Reconfigure

Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
  • deps (Dependencies): The resource dependencies.
  • conf (Config): The resource configuration.

Returns:

  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

DoCommand

Execute model-specific commands that are not otherwise defined by the service API. For built-in service models, any model-specific commands available are covered with each model’s documentation. If you are implementing your own SLAM service and add features that have no built-in API method, you can access them with DoCommand.

Parameters:

  • command (Mapping[str, ValueTypes]) (required): The command to execute.
  • timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (Mapping[str, viam.utils.ValueTypes]): Result of the executed command.

Example:

service = SERVICE.from_robot(robot, "builtin")  # replace SERVICE with the appropriate class

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

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

For more information, see the Python SDK Docs.

Parameters:

Returns:

Example:

// This example shows using DoCommand with an arm component.
myArm, err := arm.FromRobot(machine, "my_arm")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myArm.DoCommand(context.Background(), command)

For more information, see the Go SDK Docs.

GetResourceName

Get the ResourceName for this instance of the SLAM service with the given name.

Parameters:

  • name (str) (required): The name of the Resource.

Returns:

Example:

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

For more information, see the Python SDK Docs.

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None.

Returns:

  • None.

Example:

await component.close()

For more information, see the Python SDK Docs.

Parameters:

  • ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.

Returns:

  • (error): An error, if one occurred.

Example:

// This example shows using Close with an arm component.
myArm, err := arm.FromRobot(machine, "my_arm")

err = myArm.Close(ctx)

For more information, see the Go SDK Docs.