SLAM Service
Stability Notice
The SLAM service is an experimental feature. Stability is not guaranteed. Breaking changes are likely to occur, and occur often.
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:
Configuration
Integrated SLAM libraries include the following. Click the model name for configuration instructions.
Model | Description |
---|---|
viam:slam:cartographer | The Cartographer Project performs dense SLAM using LIDAR data. |
API
The SLAM service supports the following methods:
Method Name | Description |
---|---|
GetPosition | Get the current position of the specified source component in the point cloud SLAM map. |
GetPointCloudMap | Get the point cloud SLAM map. |
GetInternalState | Get the internal state of the SLAM algorithm required to continue mapping/localization. |
GetLatestMapInfo | Get the timestamp of the last update to the point cloud SLAM map. |
Tip
The following code examples assume that you have a robot configured with a SLAM service called "my_slam_service"
, and that you add the required code to connect to your robot and import any required packages at the top of your code file.
Go to your robot’s Code sample tab on the Viam app for boilerplate code to connect to your robot.
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:
- (List[GetPointCloudMapResponse]): The complete point cloud map in standard PCD format.
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:
- (List[GetInternalStateResponse]): Chunks of the internal state of the SLAM algorithm.
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
Important
This method is not yet available in the Viam Python SDK.
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())
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!