Sensors

Sensors provide a way for node to interact with its environment.

Sensors can also be used to satisfy algorithm prerequisites.

Generally sensors should incorporate some model of measurement insecurity that is inherent in real world sensors. This is implemented as a ProbabilityFunction.

Basic usage:

>>> node.compositeSensor = ('DistSensor','AoASensor')
>>> node.compositeSensor.sensors
(<pydistsim.network.sensor.DistSensor at 0x6d3fbb0>,
 <pydistsim.network.sensor.AoASensor at 0x6d3f950>)

To manually set sensor parameters first make an sensor instance:

>>> import scipy.stats
>>> aoa_sensor = AoASensor({'pf': scipy.stats.norm, 'scale': 10*pi/180 })
>>> node.compositeSensor = (aoa_sensor,)
class Sensor[source]

Abstract base class for all Sensors.

Sensor provides a certain capability for a node, providing information about the outside world. It could be a capability to detect neighbors, measure distance to them, or retrieve the environment temperature.

Parameters:
  • dict_args (dict) – A dictionary containing the scale and probability function.

  • scale (float) – The scale parameter for the probability function.

  • pf (rv_continuous or rv_discrete) – The probability function (e.g. scipy.stats.norm).

classmethod name()[source]

Get the name of the Sensor class.

Returns:

The name of the Sensor class.

Return type:

str

abstract read() dict[source]

Read the sensor data.

This method should be overridden in a subclass.

Returns:

The sensor data.

Return type:

dict

Real world sensors

AoASensor

Provides azimuth between node and its neighbors.

DistSensor

Provides distance between node and its neighbors.

Knowledge sensors

TruePosSensor

Provides node's true position.

Composite sensor

class CompositeSensor(node: Node, componentSensors: tuple[type[Sensor] | str] | None = None)[source]

Wrap multiple sensors, coalesce results and return composite readout.

This class is not a sensor itself, i.e. subclass of Sensor, instead it serves as a placeholder for multiple sensors that can be attached to a Node.

Parameters:
  • node (Node) – The Node that has this composite sensor attached to.

  • componentSensors (tuple[type[Sensor] | str]) – Tuple of Sensor subclasses or their class names.

get_sensor(name: str) Sensor[source]

Get a sensor by its name.

Parameters:

name (str) – The name of the sensor.

Returns:

The sensor object.

Return type:

Sensor

Raises:

SensorError – If multiple or no sensors are found with the given name.

read()[source]

Read measurements from all sensors.

Returns:

A dictionary containing the measurements from all sensors.

Return type:

dict

property sensors: tuple[Sensor]

Get the sensors associated with the object.

Returns:

A tuple of Sensor objects.