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 specified source component in the point cloud SLAM map.
GetPointCloudMapGet the point cloud SLAM map.
GetPropertiesGet information regarding the current SLAM session.
GetInternalStateGet the internal state of the SLAM algorithm required to continue mapping/localization.
DoCommandSend arbitrary commands to the resource.
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 (Optional[float]): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

Returns:

  • (Pose): A Pose representing the current position of the component the SLAM service is configured to source point cloud data from. For example, a camera named "cam".

For more information, see the Python SDK Docs.

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

Parameters:

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

Returns:

  • (spatialmath.Pose): A Pose representing the current position of the specified component.
  • (string): The "name" of the component the SLAM service is configured to source point cloud data from. For example, a camera named "cam".
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

slam_svc, err := slam.FromRobot(robot, "my_slam_service")

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

GetPointCloudMap

Get the point cloud map.

Parameters:

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

Returns:

For more information, see the Python SDK Docs.

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:

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

Returns:

  • (func() []byte, error): The complete point cloud map in standard PCD format.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

slam_svc, err := slam.FromRobot(robot, "my_slam_service")

// Get the point cloud map in standard PCD format.
pcd_map, err := slam_svc.GetPointCloudMap(context.Background())

GetProperties

Get information about the current SLAM session.

Parameters:

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

Returns:

  • (Properties): Information about the current SLAM session. An object containing four fields:
    • sensor_info (Iterable[SensorInfo]): Information about the sensors (camera and movement sensor) configured for your SLAM service, including the name and type of sensor.
    • cloud_slam (bool): A boolean which indicates whether the session is being run in the cloud.
    • mapping_mode (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.
    • internal_state_file_type (str): The file type the service’s internal state algorithm is stored in.

For more information, see the Python SDK Docs.

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

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.

For more information, see the Go SDK Docs.

slam_svc, err := slam.FromRobot(robot, "my_slam_service")

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

GetInternalState

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

Parameters:

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

Returns:

For more information, see the Python SDK Docs.

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

Parameters:

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

Returns:

  • (func() []byte, error): Chunks of the internal state of the SLAM algorithm.
  • (error): An error, if one occurred.

For more information, see the Go SDK Docs.

slam_svc, err := slam.FromRobot(robot, "my_slam_service")

// Get the internal state of the SLAM algorithm required to continue mapping/localization.
internal_state, err := slam_svc.GetInternalState(context.Background())

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:

Returns:

For more information, see the Python SDK Docs.

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

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

await slam.do_command(my_command)

Parameters:

Returns:

slam_svc, err := slam.FromRobot(robot, "my_slam_service")

resp, err := slam_svc.DoCommand(ctx, map[string]interface{}{"command": "dosomething", "someparameter": 52})

For more information, see the Go SDK Docs.

Close

Safely shut down the resource and prevent further use.

Parameters:

  • None

Returns:

  • None
slam = SLAMClient.from_robot(robot, "my_slam_service")

await slam.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.
slam_svc, err := slam.FromRobot(robot, "my_slam_service")

err := slam_svc.Close(ctx)

For more information, see the Go SDK Docs.