chore: replace print with logging and make robot conditional

All print statements in the main program, and components used by the main program, have been replaced with appropriate logging statements. The connection to the robot now only gets made when it's possible, otherwise only the microphone will be run.

ref: N25B-119
This commit is contained in:
Twirre Meulenbelt
2025-10-02 16:13:39 +02:00
parent 2132a74321
commit c634e4b516
3 changed files with 40 additions and 10 deletions

30
main.py
View File

@@ -1,4 +1,7 @@
import qi
import sys
import logging
logging.
import zmq
from src.audio_streaming import AudioStreaming
@@ -19,23 +22,38 @@ def listen_for_messages(session):
poller = zmq.Poller()
poller.register(socket, zmq.POLLIN)
print("Listening for messages")
logging.info("Listening for messages")
while not state.exit_event.is_set():
if not poller.poll(200): continue # At most 200 ms delay after CTRL+C
# We now know there's a message waiting for us
message = socket.recv_string()
print("Received message: {}".format(message))
logging.debug("Received message: {}".format(message))
if session: say(session, message)
def main():
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()
session = app.session
return app.session
except RuntimeError:
session = None
logging.info("Unable to connect to the robot. Running in stand-alone mode.")
return None
def main():
session = get_session()
audio_streamer = AudioStreaming()
audio_streamer.run()