Using extra parameters with Viam's SDKs | SDKs
Using extra parameters with Viam's SDKs
How to use and define the extra parameters that many resource API methods offer in the Go and Python SDKs.
Use
You can use extra parameters with modular resource implementations that are models of built-in resource types.
For example, a new model of sensor, or a new model of SLAM service.
The extra parameters in that built-in resource type’s API allow users to pass information to a resource’s driver that isn’t specified as a parameter for all models of the resource type. This is necessary to keep the API of resource types consistent across, for example, all models of motor or all models of camera.
Send extra information in an API call in extra parameters as follows:
Optional[Dict[str, Any]] indicates you are required to pass in an object of either type Dict[str, Any] or None as a parameter when calling this method.
An object of type Dict[str, Any] is a dictionary with keys of type str and values of any type,
For example:
Copy
Tip
If passing an object of type None, you do not have to specify None in the method call.
extra (map[string]interface{}) indicates you are required to pass in an object of either type map[string]interface{} or nil as a parameter when calling this method.
An object of type map[string]interface{} is an map with keys of type string and values of any type that you have cast to an interface.
For example:
Copy
Important
If passing an object of type nil, you must specify nil in the method call or the method will fail.
Define
If extra information must be passed to a resource, it is handled within a new, modular resource model’s custom API wrapper.
Click for instructions on defining a custom model to use extra params
To do this, define a custom implementation of the resource’s API as a new model, and modify the resource’s API methods to handle the extra information you send. Follow the steps in the Modular Resources documentation to do so.
For an example of how to check the values of keys in an extra parameter of a built-in resource API method, reference this modification to the built-in sensor resource type’s Readings method in the code of a new sensor model:
Copy
Copy
See Create a module for more information and instructions on modifying built-in API specifications.