I have tried to code an "emergency switch" that terminates a running application. E.g. I have coded an application where the robot says something and I want to terminate the app by touching the headsensor.
The program terminates the app, but it throws exceptions. How can I make it better?
I tried the same with walking, but it doesn't work.
# -*- encoding: UTF-8 -*-
import qi
import sys
class MyClass(object):
def __init__(self, app):
super(MyClass, self).__init__()
my_session=app.session
app.start()
self.my_tts=my_session.service("ALTextToSpeech")
self.my_memory = my_session.service("ALMemory")
self.touch = self.my_memory.subscriber("FrontTactilTouched")
self.id=self.touch.signal.connect(self.killSwitch)
self.mySpeak()
def killSwitch(self,qwe):
bool_okay=self.touch.signal.disconnect(self.id)
#print("Test")
try:
self.my_tts.stopAll()
app.stop()
sys.exit(1)
except RuntimeError, e:
print("Fehler:" + e)
def mySpeak(self):
self.my_tts.setVolume(0.1)
self.my_tts.say("Hallo sdiufhsfkasdkjasdnaskjfbnsdkfbskfjn")
if __name__ == "__main__":
try:
app = qi.Application(["MyClass", "--qi-url=" + "tcp://192.168.95.80:9559"])
except RuntimeError:
print ("Verbindungsfehler")
sys.exit(1)
myC = MyClass(app)
app.run()