This repository has been archived on 2026-10-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PICKA_python/tools/exit_condition.py
T
2026-09-22 11:52:03 +02:00

81 lines
2.5 KiB
Python

import sys
import time
import os
from naoqi import ALProxy
from naoqi import ALModule
from celery.task.control import revoke
memory = None
a = 0
class ExitExperimentModule(ALModule):
'''Module that will exit the experiment when one of the foot bumpers is touched'''
def __init__(self, name, broker, language):
ALModule.__init__(self, name)
self.tts = ALProxy("ALTextToSpeech")
self.con = ALProxy("ALConnectionManager")
self.spr = ALProxy("ALSpeechRecognition")
self.all = ALProxy("ALLeds")
answers = ["yes", "no"]
self.spr.setVocabulary(answers, False)
self.broker = broker
self.name = name
self.language = language
global memory
memory = ALProxy("ALMemory")
memory.subscribeToEvent("RightBumperPressed",
name, "onBumperPressed")
def onBumperPressed(self, *_args):
import settings
if self.name == "stop_audio":
aap = ALProxy("ALAudioPlayer")
aap.stopAll()
return
global a
print settings.task_id
memory.unsubscribeToEvent(
"RightBumperPressed", self.name)
if self. language == "EN":
self.tts.say(
"If you're sure you want to exit, \\pau=500\\ press my \\pau=500\\ left foot.")
elif self.language == "NL":
self.tts.say(
"Als je zeker weet dat je wilt stoppen, \\pau=500\\ raak dan mijn linkervoet aan.")
# self.tts.say("Exit?")
memory.subscribeToEvent(
"LeftBumperPressed", self.name, "onLeftBumperPressed")
time.sleep(5)
if a == 1:
revoke(self.task_id, terminate=True)
else:
memory.unsubscribeToEvent(
"LeftBumperPressed", self.name)
if self. language == "EN":
self.tts.say("Ok then. Let's continue.")
elif self.language == "NL":
self.tts.say("Ok, laten we dan verder gaan.")
memory.subscribeToEvent("RightBumperPressed",
"expe_exit", "onBumperPressed")
def onLeftBumperPressed(self, *_args):
global a
a = 1
memory.unsubscribeToEvent(
"LeftBumperPressed", self.name)
self.all.fadeRGB("FaceLeds", "white", 0.05)
if self. language == "EN":
self.tts.say("Goodbye")
elif self.language == "NL":
self.tts.say("Tot ziens")
self.broker.shutdown()