Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Sensors #902

Open
5 tasks
MichaelDecent opened this issue Dec 9, 2024 · 0 comments
Open
5 tasks

[Feature Request]: Sensors #902

MichaelDecent opened this issue Dec 9, 2024 · 0 comments

Comments

@MichaelDecent
Copy link
Collaborator

MichaelDecent commented Dec 9, 2024

Feature Name

Sensors

Feature Description

Sensors that collect data within the multiagent system. This will define a standard interface and provide a base class for creating and integrating various types of sensors.

The sensor framework includes the following key classes:

  • ISensor: Interface defining standard methods for sensors.
  • SensorBase: Base class providing shared functionalities for sensor management.
  • Sensor: Core class implementing ISensor and extending SensorBase to handle specific sensor functionalities.

Motivation

The sensor is essential for enabling agents to interact with their environment by collecting, processing, and sharing data. The design will:

  • Ensure Consistency: Provide a standard way to integrate different types of sensors.
  • Enable Extensibility: Allow the addition of new sensor types with minimal effort.
  • Improve Modularity: Separate sensor management logic from agent behavior.

Potential Solutions

# swarmauri_core/sensors/ISensor.py
from abc import ABC, abstractmethod

class ISensor(ABC):
    @abstractmethod
    def read(self) -> any:
        pass
# swarmauri/sensors/base/SensorBase.py
from swarmauri_core.sensors.ISensor import ISensor

class SensorBase(ISensor):
    def read(self) -> any:
        raise NotImplementedError("Subclass must implement the read method")
# swarmauri/sensors/concrete/JoystickModuleSensor.py
from RPi.GPIO import RPi

from swarmauri.sensors.base.SensorBase import SensorBase

class JoystickModuleSensor(SensorBase):
    def __init__(self, pin):
        self.pin = pin
        self.GPIO = RPi.GPIO
        self.GPIO.setmode(self.GPIO.BCM)
        self.GPIO.setup(self.pin, self.GPIO.IN, pull_up_down=self.GPIO.PUD_DOWN)
        self.GPIO.add_event_detect(self.pin, self.GPIO.RISING, callback=self.on_read)

    def on_read(self, channel):
        # Detect joystick direction based on GPIO pin
        if self.GPIO.input(channel):
            print("Joystick moved")

    def read(self) -> bool:
        return self.GPIO.input(self.pin)

Additional Context (optional)

No response

Affected Areas

None

Priority

Low

Required Files

  • Test File
  • Component File
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant