sensor_filter

package module
v0.0.0-...-f594bd0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

sensor-filter modular component

This module implements the Viam generic service API in a viam:generic:sensor-filter model. With this model, you can filter sensor data according to user-specified conditions, allowing you to return true or false based on other sensor readings.

Navigate to the CONFIGURE tab of your machine's page. Click the + button, select Component or service, then select the generic / sensor-filter model provided by the sensor-filter module. Click Add module, enter a name for your service, and click Create.

Configure your sensor-filter service

On the new component panel, copy and paste the following attribute template into your service's Attributes box:

{
  "sensor_name": "<string>",
  "reading": "<string>",
  "conditions": [
    {
      "value": <any>,
      "operator": "<string>"
    }
  ]
}
Attributes

The following attributes are available for viam:generic:sensor-filter services:

Name Type Inclusion Description
sensor_name string Required Sensor name to be used as input
reading string Required The specific reading from the sensor to filter
conditions list Optional Each condition contains an operator and a value. Possible operators include: "gt", "gte", "lt", "lte", "eq", and "neq". They correspond to >, >=, <, <=, =, and !=, respectively. Values can be anything. Without any conditions, the service will always return true
Example Configuration
{
  "sensor_name": "mySensor",
  "reading": "distance",
  "conditions": [
    {
      "value": 2,
      "operator": "gt"
    },
    {
      "value": 10,
      "operator": "lt"
    }
  ]
}

Full configuration with example sensor:

{
  "components": [
    {
      "name": "mySensor",
      "namespace": "rdk",
      "type": "sensor",
      "model": "viam:ultrasonic:sensor",
      "attributes": {
        "board": "local",
        "echo_interrupt_pin": "13",
        "trigger_pin": "11"
      }
    }
  ]
  "services": [
    {
      "attributes": {
        "sensor_name": "mySensor",
        "reading": "distance"
        "conditions": [
          {
            "value": 2,
            "operator": "gt"
          }
        ]
      }
      "name": "SF-module",
      "type": "generic",
      "namespace": "rdk",
      "model": "viam:generic:sensor-filter"
    }
  ]
}

Documentation

Overview

Package sensor_filter implements a generic service.

Index

Constants

This section is empty.

Variables

View Source
var (
	Model = resource.NewModel("viam", "generic", "sensor-filter")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	SensorName string           `json:"sensor_name"`
	Reading    string           `json:"reading"`
	Conditions []*apputils.Eval `json:"conditions"`
}

Sensor filter service configuration. Each of the three fields are required.

func (*Config) Validate

func (cfg *Config) Validate(path string) ([]string, error)

Validate validates the config and returns implicit dependencies.

Directories

Path Synopsis
Package main is a module which serves the customservo custom model.
Package main is a module which serves the customservo custom model.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL