combinedsensor

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

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

combined-sensor Viam Sensor Module (aka Lord of the Sensors)

A Viam 'sensor' module that combines readings from other built-in viam components. The primary use case for this sensor is to combine values from multiple components into a single data capture record. Correlating related data after capture is hard, this module combines them before storing.

For Example: You have a GPS movement sensor and a temperature sensor that you want to correlate to build a heatmap of an outdoor space. Normally, you would capture and store separate GPS and temperature sensor readings independently. The logic to correlate the correct location to the temperature reading after the fact will require crafty query code since timestamps will not line up perfectly.

{
  "coordinate": {
    "longitude": -73.98,
    "latitude": 40.7
  },
  "altitude_m": 50.5
}
{
  "readings": {
    "temp": 23.95
  }
}

By using this module, you can store both pieces of data on the same document, make it trivial to associate the temperature reading to the location.

{
  "readings": {
    "gps": {
      "position": {
        "coordinate": {
          "lat": 40.7,
          "lng": -73.98
        },
        "altitude_m": 50.5
      }
    },
    "temp": {
      "readings": {
        "volts": 1.5,
        "amps": 2.2,
        "is_ac": true,
        "watts": 9.8
      }
    }
  }
}

Disclaimer: some attempt was made to match the data structure supported by the Viam Data Service

Build

make

TODO: registry information

Configure

The combined-sensor uses the list of dependencies to know which components' data to gather. All methods eligible for data collection for that resource will be called. For example, movement sensors will have Readings, AngularVelocity, CompassHeading, LinearAcceleration, LinearVelocity, and Orientation called.

The data capture configuration for the combined-sensor should be configured with the Readings method.

Attributes

None.

Example configuration

Assuming there are configured movement_sensor, sensor, power_sensor, and motor components, this configuration for a combined_sensor will collect, wrap, and sync data for all of them.

    {
      "namespace": "rdk",
      "attributes": {},
      "name": "combined_sensor",
      "model": "stevebriskin:sensor:combined-sensor",
      "type": "sensor",
      "depends_on": [
        "movement_sensor",
        "sensor",
        "power_sensor",
        "motor"
      ],
      "service_configs": [
        {
          "type": "data_manager",
          "attributes": {
            "capture_methods": [
              {
                "method": "Readings",
                "additional_params": {}
              }
            ]
          }
        }
      ]
    }

Features and Limitations

APIs supported:

  • Motor
  • Movement Sensor
  • Power Sensor
  • Sensor

Others will be added later. All methods will be collected for each configured resource. In the future it will be possible to include or exclude which methods are captured.

Credits and History

Lord of the Sensors

It all began with the forging of the Great Sensors. Three were given to the Data engineers; immortal, wisest and fairest of all engineers. Seven, to the Fleet engineers, great thinkers and craftsmen of the cloud. And nine, nine sensors were gifted to the SDK/Netcode engineers, who above all else desire connectivity. For within these sensors was bound the strength and the will to govern over each domain. But they were all deceived, for another sensor was made. In the land of RDK, in the fires of Mount Bucket, the Dark Lord Briskin forged in secret, a master sensor, to control all others. And into this sensor he poured all his skills, his malice and his will to dominate all data. One sensor to rule them all.

-- @npmenard

Credit to @abe-winter for the idea

License

Copyright 2021-2024 Viam Inc.
Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Model = resource.NewModel("stevebriskin", "sensor", "combined-sensor")
)

Functions

This section is empty.

Types

type MergedSensor

type MergedSensor struct {
	resource.Named
	resource.AlwaysRebuild
	resource.TriviallyCloseable
	// contains filtered or unexported fields
}

func (*MergedSensor) Readings

func (ms *MergedSensor) Readings(ctx context.Context, extra map[string]interface{}) (map[string]interface{}, error)

type MyConfig

type MyConfig struct {
}

TODO: allow control over which methods are captured

func (*MyConfig) Validate

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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