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 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:
Used with
* Required for use
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. |
GetProperties | Get information regarding the current SLAM session. |
GetInternalState | Get the internal state of the SLAM algorithm required to continue mapping/localization. |
DoCommand | Send arbitrary commands to the resource. |
Close | Safely shut down the resource and prevent further use. |
Tip
The following code examples assume that you have a machine configured with a SLAM service called "my_slam_service"
, and that you add the required code to connect to your machine and import any required packages at the top of your code file.
Go to your machine’s CONNECT tab on the Viam app and select the Code sample page for boilerplate code to connect to your machine.
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:
- (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()
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:
- (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()
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:
command
(Mapping[str, ValueTypes]): The command to execute.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:
- (Mapping[str, ValueTypes]): Result of the executed command.
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:
ctx
(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.cmd
(map[string]interface{}): The command to execute.
Returns:
- (map[string]interface{}): Result of the executed command.
- (error): An error, if one occurred.
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.
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!