refactor: use new port negotiation style

As changed in the API document, this now uses the new port negotiation style.

ref: N25B-168
This commit is contained in:
Twirre Meulenbelt
2025-10-16 17:22:04 +02:00
parent e12d88726d
commit 23c3379bfb
8 changed files with 43 additions and 69 deletions

View File

@@ -1,5 +1,4 @@
import logging
import sys
import zmq
@@ -17,32 +16,10 @@ class ActuationReceiver(ReceiverBase):
:param port: The port to use.
:type port: int
"""
super(ActuationReceiver, self).__init__("actuation", "json")
self.create_socket(zmq_context, zmq.SUB, port)
self.socket.setsockopt_string(zmq.SUBSCRIBE, u"") # Subscribe to all topics
self._qi_session = self._get_session()
super(ActuationReceiver, self).__init__("actuation")
self.create_socket(zmq_context, zmq.SUB, port, options=[(zmq.SUBSCRIBE, u"")])
self._tts_service = None
@staticmethod
def _get_session():
if "--qi-url" not in sys.argv:
logging.info("No Qi URL argument given. Running in stand-alone mode.")
return None
try:
import qi
except ImportError:
logging.info("Unable to import qi. Running in stand-alone mode.")
return None
try:
app = qi.Application()
app.start()
return app.session
except RuntimeError:
logging.info("Unable to connect to the robot. Running in stand-alone mode.")
return None
def _handle_speech(self, message):
text = message.get("data")
if not text:

View File

@@ -15,7 +15,7 @@ class MainReceiver(ReceiverBase):
:param port: The port to use.
:type port: int
"""
super(MainReceiver, self).__init__("main", "json")
super(MainReceiver, self).__init__("main")
self.create_socket(zmq_context, zmq.REP, port, bind=False)
@staticmethod

View File

@@ -2,8 +2,6 @@ from abc import ABCMeta
import zmq
from robot_interface.utils import zmq_socket_type_int_to_str, zmq_socket_type_complement
class SocketBase(object):
__metaclass__ = ABCMeta
@@ -11,16 +9,12 @@ class SocketBase(object):
name = None
socket = None
def __init__(self, name, data_type):
def __init__(self, identifier):
"""
:param name: The name of the endpoint.
:type name: str
:param data_type: The data type of the endpoint, e.g. "json", "binary", "text", etc.
:type data_type: str
:param identifier: The identifier of the endpoint.
:type identifier: str
"""
self.name = name
self.data_type = data_type
self.identifier = identifier
self.port = None # Set later by `create_socket`
self.socket = None # Set later by `create_socket`
self.bound = None # Set later by `create_socket`
@@ -71,9 +65,7 @@ class SocketBase(object):
:rtype: dict
"""
return {
"name": self.name,
"id": self.identifier,
"port": self.port,
"pattern": zmq_socket_type_int_to_str[zmq_socket_type_complement[self.socket.getsockopt(zmq.TYPE)]],
"data_type": self.data_type,
"bind": not self.bound
}

View File

@@ -15,12 +15,12 @@ class VideoSender(SocketBase):
def start_video_rcv(self):
"""
Prepares arguments for retrieving video images from Pepper and starts video loop on a separate thread.
"""
app = qi.Application()
app.start()
session = app.session
"""
if not state.qi_session:
logging.info("No QI session available, not starting video loop")
return
video = session.service("ALVideoDevice")
video = state.session.service("ALVideoDevice")
camera_index = 0
kQVGA = 2