SLAM Service

Simultaneous Localization And Mapping (SLAM) allows your robot 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 robot. 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 Control tab of your robot’s page in the Viam app:

SLAM map built with Viam of a triangle shaped building.

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.
GetInternalStateGet the internal state of the SLAM algorithm required to continue mapping/localization.
GetLatestMapInfoGet the timestamp of the last update to the point cloud SLAM map.

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:

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

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

GetPointCloudMap

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

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

GetInternalState

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

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

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

GetLatestMapInfo

Get the timestamp of the last update to the point cloud SLAM map.

Parameters:

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

Returns:

  • (time.Time): The timestamp of the last update to the point cloud SLAM map.
  • (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 timestamp of the last update to the point cloud SLAM map.
timestamp, err := slam_svc.GetLatestMapInfo(context.Background())