0

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()
khelwood
  • 55,782
  • 14
  • 81
  • 108
Mathews
  • 27
  • 2

1 Answers1

1

I think that i found a solution that's works for me. I edit the following lines:

def mySpeak(self):
        self.my_tts.setVolume(0.1)
        
        self.my_tts.say("Hallo sdiufhsfkasdkjasdnaskjfbnsdkfbskfjn",_async=True)

def killSwitch(self,qwe):
        self.touch.signal.disconnect(self.id)
        #self.leftDet.signal.disconnect(self.id2)
        #print("Test")
        try:
            self.my_tts.stopAll()
            app.stop()
            os._exit(1)    
        except RuntimeError, e:
            print("Fehler:" + e)
il_raffa
  • 5,090
  • 129
  • 31
  • 36
Mathews
  • 27
  • 2