feat: adapt actuation receiver to state's qi_session
Makes actuation tests pass. In main, the timing of the socket no longer contains the time to receive and send data, but only the processing time of the message handler. ref: N25B-168
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
import time
|
||||
|
||||
import zmq
|
||||
|
||||
@@ -8,6 +7,7 @@ from robot_interface.endpoints.actuation_receiver import ActuationReceiver
|
||||
from robot_interface.endpoints.main_receiver import MainReceiver
|
||||
from robot_interface.endpoints.video_sender import VideoSender
|
||||
from robot_interface.state import state
|
||||
from robot_interface.utils.timeblock import TimeBlock
|
||||
|
||||
|
||||
def main_loop(context):
|
||||
@@ -44,17 +44,21 @@ def main_loop(context):
|
||||
for receiver in receivers:
|
||||
if receiver.socket not in socks: continue
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
message = receiver.socket.recv_json()
|
||||
response = receiver.handle_message(message)
|
||||
if not isinstance(message, dict) or "endpoint" not in message or "data" not in message:
|
||||
logging.error("Received message of unexpected format: {}".format(message))
|
||||
continue
|
||||
|
||||
def overtime_callback(time_ms):
|
||||
logging.warn("Endpoint \"%s\" took too long (%.2f ms) on the main thread.",
|
||||
message["endpoint"], time_ms)
|
||||
|
||||
with TimeBlock(overtime_callback, 50):
|
||||
response = receiver.handle_message(message)
|
||||
|
||||
if receiver.socket.getsockopt(zmq.TYPE) == zmq.REP:
|
||||
receiver.socket.send_json(response)
|
||||
|
||||
time_spent_ms = (time.time() - start_time) * 1000
|
||||
if time_spent_ms > 50:
|
||||
logging.warn("Endpoint \"%s\" took too long (%.2f ms) on the main thread.", receiver.name, time_spent_ms)
|
||||
|
||||
|
||||
def main():
|
||||
context = zmq.Context()
|
||||
|
||||
Reference in New Issue
Block a user