Using Extra Params with Viam's SDKs

How to utilize and define the extra parameters that many resource API methods offer in the Go and Python SDKs.

Utilize

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:

async def main():
    # ... Connect to the machine.

    # Get your sensor resource from the machine.
    your_sensor = YourSensor.from_robot(robot, "your-sensor")

    # Define a dictionary containing extra information.
    your_info = {"type": "temperature", "description": "more info", "id": 123}

    # Send this information in an call to the sensor resource's API.
    await your_sensor.get_readings(extra=your_info)

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:

func main() {
    ... // Connect to the machine

    // Get your sensor resource from the machine.
    yourSensor, err := YourSensor.FromRobot(robot, "your-sensor")

    // Define a map containing extra information.
    your_info := map[string]interface{}{"type": "temperature", "description": "more info", "id": 123}

    // Send this information in an call to the sensor resource's API.
    err := yourSensor.Readings(context.Background(), your_info)
}

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 utilize extra params


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.