The Big One #43

Merged
k.marinus merged 93 commits from feat/reset-experiment-and-phase into dev 2026-01-26 19:20:45 +00:00
2 changed files with 21 additions and 1 deletions
Showing only changes of commit c91b999104 - Show all commits

View File

@@ -83,6 +83,8 @@ class RobotGestureAgent(BaseAgent):
self.subsocket.close() self.subsocket.close()
if self.pubsocket: if self.pubsocket:
self.pubsocket.close() self.pubsocket.close()
if self.repsocket:
self.repsocket.close()
await super().stop() await super().stop()
async def handle_message(self, msg: InternalMessage): async def handle_message(self, msg: InternalMessage):

View File

@@ -48,6 +48,8 @@ class RICommunicationAgent(BaseAgent):
self._req_socket: azmq.Socket | None = None self._req_socket: azmq.Socket | None = None
self.pub_socket: azmq.Socket | None = None self.pub_socket: azmq.Socket | None = None
self.connected = False self.connected = False
self.gesture_agent: RobotGestureAgent | None = None
self.speech_agent: RobotSpeechAgent | None = None
async def setup(self): async def setup(self):
""" """
@@ -141,6 +143,7 @@ class RICommunicationAgent(BaseAgent):
# At this point, we have a valid response # At this point, we have a valid response
try: try:
self.logger.debug("Negotiation successful. Handling rn")
await self._handle_negotiation_response(received_message) await self._handle_negotiation_response(received_message)
# Let UI know that we're connected # Let UI know that we're connected
topic = b"ping" topic = b"ping"
@@ -189,6 +192,7 @@ class RICommunicationAgent(BaseAgent):
address=addr, address=addr,
bind=bind, bind=bind,
) )
self.speech_agent = robot_speech_agent
robot_gesture_agent = RobotGestureAgent( robot_gesture_agent = RobotGestureAgent(
settings.agent_settings.robot_gesture_name, settings.agent_settings.robot_gesture_name,
address=addr, address=addr,
@@ -196,6 +200,7 @@ class RICommunicationAgent(BaseAgent):
gesture_data=gesture_data, gesture_data=gesture_data,
single_gesture_data=single_gesture_data, single_gesture_data=single_gesture_data,
) )
self.gesture_agent = robot_gesture_agent
await robot_speech_agent.start() await robot_speech_agent.start()
await asyncio.sleep(0.1) # Small delay await asyncio.sleep(0.1) # Small delay
await robot_gesture_agent.start() await robot_gesture_agent.start()
@@ -226,6 +231,7 @@ class RICommunicationAgent(BaseAgent):
while self._running: while self._running:
if not self.connected: if not self.connected:
await asyncio.sleep(settings.behaviour_settings.sleep_s) await asyncio.sleep(settings.behaviour_settings.sleep_s)
self.logger.debug("Not connected, skipping ping loop iteration.")
continue continue
# We need to listen and send pings. # We need to listen and send pings.
@@ -289,15 +295,27 @@ class RICommunicationAgent(BaseAgent):
# Tell UI we're disconnected. # Tell UI we're disconnected.
topic = b"ping" topic = b"ping"
data = json.dumps(False).encode() data = json.dumps(False).encode()
self.logger.debug("1")
if self.pub_socket: if self.pub_socket:
try: try:
self.logger.debug("2")
await asyncio.wait_for(self.pub_socket.send_multipart([topic, data]), 5) await asyncio.wait_for(self.pub_socket.send_multipart([topic, data]), 5)
except TimeoutError: except TimeoutError:
self.logger.debug("3")
self.logger.warning("Connection ping for router timed out.") self.logger.warning("Connection ping for router timed out.")
# Try to reboot/renegotiate # Try to reboot/renegotiate
if self.gesture_agent is not None:
await self.gesture_agent.stop()
if self.speech_agent is not None:
await self.speech_agent.stop()
if self.pub_socket is not None:
self.pub_socket.close()
self.logger.debug("Restarting communication negotiation.") self.logger.debug("Restarting communication negotiation.")
if await self._negotiate_connection(max_retries=1): if await self._negotiate_connection(max_retries=2):
self.connected = True self.connected = True
async def handle_message(self, msg: InternalMessage): async def handle_message(self, msg: InternalMessage):