Configure an ultrasonic Camera
Usage
An ultrasonic distance sensor can also be configured as a sensor resource.
When configured as a sensor, you can use the sensor method GetReadings()
, rather than the camera method GetPointCloud()
.
Configure an ultrasonic
camera to integrate the HC-S204 ultrasonic distance sensor into your robot:
Navigate to the Config tab of your robot’s page in the Viam app.
Click on the Components subtab and click Create component.
Select the camera
type, then select the ultrasonic
model.
Enter a name for your camera and click Create.
Copy and paste the following attribute template into your camera’s Attributes box. Then remove and fill in the attributes as applicable to your camera, according to the table below.
{
"trigger_pin": "<pin-number>",
"echo_interrupt_pin": "<pin-number>",
"board": "<your-board-name>",
"timeout_ms": <int>
}
{
"trigger_pin": "5",
"echo_interrupt_pin": "15",
"board": "local",
"timeout_ms": "1200"
}
{
"components": [
{
"name": "<your-ultrasonic-sensor-name>",
"model": "ultrasonic",
"type": "camera",
"namespace": "rdk",
"attributes": {
"trigger_pin": "<pin-number>",
"echo_interrupt_pin": "<pin-number>",
"board": "<your-board-name>",
"timeout_ms": <int>
},
"depends_on": []
}
]
}
{
"components": [
{
"name": "my-ultrasonic-sensor",
"model": "ultrasonic",
"type": "camera",
"namespace": "rdk",
"attributes": {
"trigger_pin": "5",
"echo_interrupt_pin": "15",
"board": "local",
"timeout_ms": "1200"
},
"depends_on": []
}
]
}
The following attributes are available for ultrasonic
cameras:
Attribute | Type | Inclusion | Description |
---|---|---|---|
trigger_pin | string | Required | The pin number of the board’s GPIO pin that you have wired the ultrasonic’s trigger pin to. |
echo_interrupt_pin | string | Required | The pin number of the pin the ultrasonic’s echo pin is wired to on the board. If you have already created a digital interrupt for this pin in the board’s configuration, use that digital interrupt’s name instead. |
board | string | Required | The name of the board the ultrasonic is wired to. |
timeout_ms | int | Optional | Time to wait in milliseconds before timing out of requesting to get ultrasonic distance readings. Default: 1000 . |
Next Steps
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!