Configure an obstacles_distance Segmenter

Changed in RDK v0.2.36 and API v0.1.118

obstacles_distance is a segmenter that takes point clouds from a camera input and returns the average single closest point to the camera as a perceived obstacle. It is best for transient obstacle avoidance.

For example, if you have an ultrasonic distance sensor as an ultrasonic camera, this model will query the sensor "num_queries" times, and then take the average point from those measurements and return that as an obstacle.

Navigate to your machine’s Config tab on the Viam app. Click the Services subtab and click Create service in the lower-left corner. Select the Vision type, then select the Obstacles Distance model. Enter a name for your service and click Create.

In your vision service’s configuration panel, fill in the Attributes field with the following:

{
  "num_queries": 10
}

Add the vision service object to the services array in your raw JSON configuration:

"services": [
    {
      "name": "<segmenter_name>",
      "type": "vision",
      "namespace": "rdk",
      "model": "obstacles_distance",
      "attributes": {
        "num_queries": 10
      }
    },
    ... // Other services
]
"services": [
    {
        "name": "my_segmenter",
        "type": "vision",
        "namespace": "rdk",
        "model": "obstacles_distance",
        "attributes": {
            "num_queries": 10
        }
    }
]

The following parameters are available for a obstacles_distance segmenter:

ParameterInclusionDescription
num_queriesOptionalHow many times the model should call GetPointCloud() before taking the average of the measurements and returning the single closest point. Accepts an integer between 1 and 20.
Default: 10

Test your segmenter

The following code uses the GetObjectPointClouds method to run a segmenter vision model on an image from the machine’s camera "cam1":

from viam.services.vision import VisionClient

robot = await connect()

# Grab Viam's vision service for the segmenter
my_segmenter = VisionClient.from_robot(robot, "my_segmenter")

objects = await my_segmenter.get_object_point_clouds("cam1")

await robot.close()

To learn more about how to use segmentation, see the Python SDK docs.

import (
"go.viam.com/rdk/config"
"go.viam.com/rdk/services/vision"
"go.viam.com/rdk/components/camera"
)

cameraName := "cam1" // Use the same component name that you have in your machine configuration

// Get the vision service you configured with name "my_segmenter" from the machine
mySegmenter, err := vision.from_robot(robot, "my_segmenter")
if err != nil {
    logger.Fatalf("Cannot get vision service: %v", err)
}

// Get segments
segments, err := mySegmenter.ObjectPointClouds(context.Background(), cameraName, nil)
if err != nil {
    logger.Fatalf("Could not get segments: %v", err)
}
if len(segments) > 0 {
    logger.Info(segments[0])
}

To learn more about how to use segmentation, see the Go SDK docs.



Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.