Skip to content

Sensor Engine

Bases: ABC

Abstract base class representing a sensor engine.

The sensor engine manages the lifecycle of sensors, including their creation, retrieval, and termination. It serves as a central point for interacting with various sensors within the system.

add_sensor(sensor) abstractmethod

Add a sensor to the sensor engine.

This method registers an existing sensor instance within the sensor engine for management.

Parameters:

Name Type Description Default
sensor ISensor

The sensor instance to add.

required

Raises:

Type Description
TypeError

If the provided sensor is not an instance of ISensor.

ValueError

If the sensor is already registered.

create_sensor(sensor_id, sensor_type, **kwargs) abstractmethod

Create a new sensor of the specified type.

This method initializes a sensor based on the provided type and data, and registers it within the sensor engine for management.

Parameters:

Name Type Description Default
sensor_id str

The unique identifier for the sensor to be created.

required
sensor_type SensorType

The type of sensor to create.

required
Kwargs

**kwargs: Additional keyword arguments for sensor initialization.

Returns:

Name Type Description
ISensor ISensor

The newly created sensor instance.

Raises:

Type Description
ValueError

If the sensor_type is unsupported or sensor_data is invalid.

RuntimeError

If the sensor cannot be created due to system constraints.

custom(name) abstractmethod

Decorator for custom sensor For example, if the user create a new custom sensor, add a new type to SensorType enum and implement the new sensor class, the user can add the custom sensor to the sensor engine using this method.

get_sensor(sensor_id) abstractmethod

Retrieve a sensor by its unique identifier.

This method fetches the sensor instance corresponding to the provided sensor_id.

Parameters:

Name Type Description Default
sensor_id Any

The unique identifier of the sensor to retrieve.

required

Returns:

Name Type Description
ISensor ISensor

The sensor instance associated with the provided sensor_id.

Raises:

Type Description
KeyError

If no sensor with the specified sensor_id exists.

TypeError

If the sensor_id is of an incorrect type.

terminate() abstractmethod

Terminate the sensor engine and perform necessary cleanup operations.

This method gracefully shuts down the sensor engine, ensuring that all sensors are properly terminated and that resources are released.

Raises:

Type Description
RuntimeError

If the sensor engine fails to terminate gracefully.

IOError

If there are issues during the cleanup process.

Sensor


Bases: ABC

Abstract base class representing a generic sensor.

Sensors are responsible for collecting data related to specific aspects of the system. Each sensor has a type and maintains its own data state.

Attributes:

Name Type Description
type SensorType

The type of the sensor.

data Dict[str, Any]

The data collected or maintained by the sensor.

data abstractmethod property

Get the current data maintained by the sensor.

Returns:

Type Description
Union[Dict[str, Any], List[int]]

Dict[str, Any]: The data maintained by the sensor.

Union[Dict[str, Any], List[int]]

List[int]: A list of node identifiers for the NEIGHBOR sensor type.

sensor_id abstractmethod property

Get the unique identifier of the sensor.

Returns:

Name Type Description
str str

The unique identifier of the sensor.

type abstractmethod property

Get the type of the sensor.

Returns:

Name Type Description
SensorType SensorType

The type of the sensor.

sense(node_id) abstractmethod

Perform sensing operations for a given node.

This method collects data related to the specified node and returns the sensed information.

Parameters:

Name Type Description Default
node_id int

The unique identifier of the node to sense.

required
Sensed Data type

Dict[str, Any]: A dictionary containing the sensed data. Only Neigbor sensor returns a list of node ids. List[int]

Raises:

Type Description
ValueError

If the provided node_id is invalid.

RuntimeError

If the sensing operation fails due to system constraints.

set_owner(owner) abstractmethod

Set the owner of the sensor. Owner is a string that identifies the entity responsible for the sensor. Used for setting the owning agent.

This method assigns a specific owner to the sensor, which can be used for identification or management purposes.

Parameters:

Name Type Description Default
owner str or None

The name of the owner to assign to the sensor.

required

Raises:

Type Description
TypeError

If the provided owner is not a string.

ValueError

If the provided owner is invalid or empty.

update(data) abstractmethod

Update the sensor's data.

This method modifies the sensor's internal data based on the provided information.

Parameters:

Name Type Description Default
data Dict[str, Any]

A dictionary containing the data to update the sensor with.

required

Raises:

Type Description
KeyError

If the provided data contains invalid keys.

ValueError

If the provided data is malformed or incomplete.

Sensor Type


Bases: Enum

Enumeration of different sensor types.

Attributes:

Name Type Description
CUSTOM Enum

Dummy Sensor type when the user create a custom sensor. Data Representation depends on the custom sensor implementation.

NEIGHBOR Enum

Sensor type for detecting neighboring entities. Data Representation (List[int]): List of node identifiers representing neighbors.

MAP Enum

Sensor type for map-related data. Data Representation (Dict[str, Dict[int, Union[Node, OSMEdge]]): Keys nodes and edges give respective node and edge data.

AGENT Enum

Sensor type for agent locations. Data Representation (Dict[str, int]): Dictionary mapping agent names to node identifiers.

RANGE Enum

Sensor type for range-based data. Data Representation (Dict[str, Dict[int, Union[Node, OSMEdge]]): Keys nodes and edges give respective node and edge data. Range only version of MAP.

ARC Enum

Sensor type for arc-based data. Data Representation (Dict[str, Dict[int, Union[Node, OSMEdge]]): Keys nodes and edges give respective node and edge data. Range and Fov version of MAP.

AGENT_RANGE Enum

Sensor type for agent range data. Data Representation (Dict[str, int]): Dictionary mapping agent names to node identifiers. Range only version of AGENT.

AGENT_ARC Enum

Sensor type for agent arc data. Data Representation (Dict[str, int]): Dictionary mapping agent names to node identifiers. Range and Fov version of AGENT.