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 viam: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 the CONFIGURE tab of your machine’s page in the Viam app.
Click the + icon next to your machine part in the left-hand menu and select Service.
Select the vision
type, then select the obstacles distance
model.
Enter a name or use the suggested 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:
Parameter | Required? | Description |
---|---|---|
num_queries | Optional | How 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.
Tip
To see more code examples of how to use Viam’s vision service, see our example repo.
Next Steps
For general configuration and development info, see:
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.
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!