Sensor API | Component APIs
Sensor API
The sensor API allows you to get measurements from your sensor components.
The sensor component supports the following methods:
| Method Name | Description | viam-micro-server Support |
|---|---|---|
GetReadings |
Get the measurements or readings that this sensor provides. | |
GetGeometries |
Get all the geometries associated with the sensor in its current configuration, in the frame of the sensor. | |
Reconfigure |
Reconfigure this resource. | |
DoCommand |
Execute model-specific commands that are not otherwise defined by the component API. | |
GetResourceName |
Get the ResourceName for this sensor. |
|
Close |
Safely shut down the resource and prevent further use. |
API
GetReadings
Get the measurements or readings that this sensor provides. Supported by viam-micro-server.
Parameters:
extra(Mapping[ str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (Mapping[ str, viam.utils.SensorReading]): : The measurements. Can be of any type.
Example:
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.extra(map[string]interface{}): Extra options to pass to the underlying RPC call.
Returns:
- (map[string]interface{}): A map containing the measurements from the sensor. Contents depend on sensor model and can be of any type.
- (error): An error, if one occurred.
Example:
For more information, see the Go SDK Docs.
GetGeometries
Get all the geometries associated with the sensor in its current configuration, in the frame of the sensor. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.
Parameters:
Returns:
- ( List[viam.proto.common.Geometry]): : The geometries associated with the Component.
Example:
For more information, see the Python SDK Docs.
Reconfigure
Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.
Parameters:
ctx(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.deps(Dependencies): The resource dependencies.conf(Config): The resource configuration.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
DoCommand
Execute model-specific commands that are not otherwise defined by the component API. Most models do not implement DoCommand. Any available model-specific commands should be covered in the model’s documentation. If you are implementing your own sensor and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.
Parameters:
command(Mapping[ str, ValueTypes]) (required): The command to execute.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (Mapping[ str, viam.utils.ValueTypes]): : Result of the executed command.
Raises:
- (NotImplementedError): Raised if the Resource does not support arbitrary commands.
Example:
For more information, see the Python SDK Docs.
GetResourceName
Get the ResourceName for this sensor.
Parameters:
name( str) (required): The name of the Resource.
Returns:
- ( viam.proto.common.ResourceName): : The ResourceName of this Resource.
Example:
For more information, see the Python SDK Docs.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None.
Returns:
- None.
Example:
For more information, see the Python SDK Docs.