feat: face recognition agent #53

Open
2584433 wants to merge 31 commits from feat/face-recognition into main
2 changed files with 61 additions and 1 deletions
Showing only changes of commit 03954bef54 - Show all commits

View File

@@ -10,7 +10,7 @@ from control_backend.agents.actuation.robot_gesture_agent import RobotGestureAge
from control_backend.core.config import settings from control_backend.core.config import settings
from ..actuation.robot_speech_agent import RobotSpeechAgent from ..actuation.robot_speech_agent import RobotSpeechAgent
from ..perception import VADAgent from ..perception import FacePerceptionAgent, VADAgent
class RICommunicationAgent(BaseAgent): class RICommunicationAgent(BaseAgent):
@@ -201,6 +201,13 @@ class RICommunicationAgent(BaseAgent):
case "audio": case "audio":
vad_agent = VADAgent(audio_in_address=addr, audio_in_bind=bind) vad_agent = VADAgent(audio_in_address=addr, audio_in_bind=bind)
await vad_agent.start() await vad_agent.start()
case "face":
face_agent = FacePerceptionAgent(
settings.agent_settings.face_agent_name,
address=addr,
bind=bind,
)
await face_agent.start()
case _: case _:
self.logger.warning("Unhandled negotiation id: %s", id) self.logger.warning("Unhandled negotiation id: %s", id)

View File

@@ -0,0 +1,53 @@
import asyncio
import zmq
import zmq.asyncio as azmq
from control_backend.agents import BaseAgent
from control_backend.core.config import settings
class FacePerceptionAgent(BaseAgent):
"""
Receives and processes face detection events from Pepper.
"""
def __init__(self, name, address, bind=False):
super().__init__(name)
self._address = address
self._bind = bind
self._socket: azmq.Socket | None = None
async def setup(self):
self.logger.info("Starting FacePerceptionAgent")
ctx = azmq.Context.instance()
self._socket = ctx.socket(zmq.SUB)
self._socket.setsockopt_string(zmq.SUBSCRIBE, "")
if self._bind:
self._socket.bind(self._address)
else:
self._socket.connect(self._address)
self.add_behavior(self._listen_loop())
async def _listen_loop(self):
while self._running:
try:
msg = await self._socket.recv_json()
await self._process_face_data(msg)
except Exception:
self.logger.exception("Error receiving face data")
async def _process_face_data(self, data: dict):
"""
Central place to handle face perception.
"""
face_count = data.get("face_count", 0)
if face_count > 0:
self.logger.debug("Detected %d face(s)", face_count)
#Post belief
else:
self.logger.debug("No faces detected")