Ejemplo n.º 1
0
    def connect(self, hostname, portnumber):
        try:
            self.broker = broker.Broker('NaoRecorder', nao_id=hostname, nao_port=portnumber)
            if self.broker:
                self.env = naoenv.make_environment(None)
                self.saved_alife_state = None
                try:
                    self.saved_alife_state = self.env.alife.getState()
                    print "Autonomous life was {}".format(self.saved_alife_state)
                    self.env.alife.setState('disabled')
                except RuntimeError:
                    pass

                self.nao = nao.Nao(self.env, None)
                try:
                    if self.event_handlers and self.vocabulary:
                        self.env.speechRecognition.setVocabulary(self.vocabulary.keys(), False)
                except RuntimeError as e:
                    print localized_text('error_set_vocabulary').format(e)
                self.do_subscribe()
                return True
            else:
                return None
        except IOError as e:
            return None
        except RuntimeError as e:
            return None
Ejemplo n.º 2
0
 def connect(self, hostname, portnumber):
     self.broker = broker.Broker('NaoRecorder', naoIp=hostname, naoPort=portnumber)
     if self.broker:
         self.env = naoenv.make_environment(None)
         self.nao = nao.Nao(self.env, None)
         if self.event_handlers and self.vocabulary:
             self.env.speechRecognition.setWordListAsVocabulary(self.vocabulary.keys(), False)
         self.do_subscribe()
         return True
     else:
         return None
Ejemplo n.º 3
0
def main(hostname, portnumber):
    print "Connecting to {}:{}".format(hostname, portnumber)
    b = broker.Broker('NaoRecorder', naoIp=hostname, naoPort=portnumber)
    if b:
        env = naoenv.make_environment(None)
        memory.subscribeToEvent("HandLeftBackTouched", callback)
        memory.subscribeToEvent("FrontTactilTouched", print_events)
        print "waiting for events\n"
        time.sleep(120)
        print_events()
        print "done\n"
Ejemplo n.º 4
0
from providers.time_provider import TimeProvider
from providers.face_recog_provider import FaceRecogProvider
from providers.voice_recog_provider import VoiceRecogProvider
from providers.voice_emotion_provider import VoiceEmotionProvider


#########################
# SETUP: Broker

naoIp = "nao.local"
broker.Broker('bootstrapBroker', naoIp=naoIp, naoPort=9559)

#########################
# SETUP: FluentNao

env = naoenv.make_environment(None)
log = lambda msg: print(msg) 				# lambda for loggin to the console
n = Nao(env, log)

# disable autonomous moves
n.env.add_proxy("ALAutonomousMoves")
autonomous_moves = n.env.proxies["ALAutonomousMoves"] 
autonomous_moves.setExpressiveListeningEnabled(False)


#########################
# SETUP: Nao Consious

#============
# subscribers
sleepy_subscriber = SleepySubscriber(n)
Ejemplo n.º 5
0
import math
import naoutil.naoenv as naoenv
import naoutil.memory as memory
import fluentnao.nao as nao
from datetime import datetime
from naoutil import broker

# naoutil broker & env
naoIp = "192.168.2.12"
broker.Broker('bootstrapBroker', naoIp=naoIp, naoPort=9559)
env = naoenv.make_environment(None) #using broker don't need ->, ipaddr="nao.local", port=9559)

# FluentNao
nao = nao.Nao(env, None)


def doSomething():
	nao.arms.forward().elbows.bent()
	nao.say('I did something')


# subscribe
# callbacks
def unsubscribe_callback(dataName, value, message):
	memory.unsubscribeToEvent('FrontTactilTouched')
	memory.unsubscribeToEvent('WordRecognized')

def subscribe_callback(dataName, value, message):
	memory.subscribeToEvent('FrontTactilTouched', tactil_callback)
	memory.subscribeToEvent('WordRecognized', speech_callback)
Ejemplo n.º 6
0
from providers.touch_provider import TouchProvider
from providers.time_provider import TimeProvider
from providers.face_recog_provider import FaceRecogProvider
from providers.voice_recog_provider import VoiceRecogProvider
#from providers.voice_emotion_provider import VoiceEmotionProvider

#########################
# SETUP: Broker

naoIp = "192.168.1.18"
broker.Broker('bootstrapBroker', naoIp=naoIp, naoPort=9559)

#########################
# SETUP: FluentNao

env = naoenv.make_environment(None)
log = lambda msg: print(msg)  # lambda for loggin to the console
n = Nao(env, log)

# disable autonomous moves
n.env.add_proxy("ALAutonomousMoves")
autonomous_moves = n.env.proxies["ALAutonomousMoves"]
autonomous_moves.setExpressiveListeningEnabled(False)

#########################
# SETUP: Nao Consious

#============
# subscribers
sleepy_subscriber = SleepySubscriber(n)
look_around_subscriber = LookAroundSubscriber(n)
Ejemplo n.º 7
0
def make_wanderer_environment(box_):
    env = make_environment(box_)
    env.set_application_name(WANDERER_NAME)
    return env
Ejemplo n.º 8
0
 def test_create_with_ip_and_port(self):
     env = make_environment(MockBox(), ipaddr="127.0.0.1", port=9559)
     set_mock_add_proxy(env, fake_add_proxy)
     self.assertIsNotNone(env)
     self.assertIsNotNone(env.motion)
Ejemplo n.º 9
0
 def test_find_implicit_resources_dir(self):
     env = make_environment(MockBox())
     rp = env.resources_dir()
     print "Implicit resources path = " + rp
     self.assertNotEqual(None, rp, "Resources path should not be None")
Ejemplo n.º 10
0
def make_environment_with_fake_proxy(func):
    env = make_environment(MockBox())
    set_mock_add_proxy(env, func)
    return env
Ejemplo n.º 11
0
import math
import naoutil.naoenv as naoenv
import naoutil.memory as memory
import fluentnao.nao as nao
from datetime import datetime
from naoutil import broker

# naoutil broker & env
naoIp = "192.168.2.10"
broker.Broker('bootstrapBroker', naoIp=naoIp, naoPort=9559)
env = naoenv.make_environment(
    None)  #using broker don't need ->, ipaddr="nao.local", port=9559)

# FluentNao
nao = nao.Nao(env, None)


def doSomething():
    nao.arms.forward().elbows.bent()
    nao.say('I did something')


# subscribe
# callbacks
def unsubscribe_callback(dataName, value, message):
    memory.unsubscribeToEvent('FrontTactilTouched')
    memory.unsubscribeToEvent('WordRecognized')


def subscribe_callback(dataName, value, message):
    memory.subscribeToEvent('FrontTactilTouched', tactil_callback)
Ejemplo n.º 12
0
 def test_create_with_ip_and_port(self):
     env = make_environment(MockBox(), ipaddr="127.0.0.1", port=9559)
     set_mock_add_proxy(env, fake_add_proxy)
     self.assertIsNotNone(env)
     self.assertIsNotNone(env.motion)
Ejemplo n.º 13
0
 def test_find_implicit_resources_dir(self):
     env = make_environment(MockBox())
     rp = env.resources_dir()
     print "Implicit resources path = " + rp
     self.assertNotEqual(None, rp, "Resources path should not be None")
Ejemplo n.º 14
0
def make_environment_with_fake_proxy(func):
    env = make_environment(MockBox())
    set_mock_add_proxy(env, func)
    return env
Ejemplo n.º 15
0
def make_wanderer_environment(box_):
    env = make_environment(box_)
    env.set_application_name(WANDERER_NAME)
    return env
Ejemplo n.º 16
0
    def naoqiInit(self, selfIP):
        speechEvents = dict()
        speechEvents["nao listen"] = [NaoAgent.EVENT_ORDER_LISTEN, .37]
        speechEvents["Hello nao"] = [NaoAgent.EVENT_ORDER_SAY_HI, .40]
        speechEvents["sit down"] = [NaoAgent.EVENT_ORDER_SIT_DOWN, .40]
        speechEvents["Stand up"] = [NaoAgent.EVENT_ORDER_STAND_UP, .30]
        speechEvents["Tell Raphael to go to the room number 1"] = [
            NaoAgent.EVENT_SALLE_1_RAPHAEL, .27
        ]
        speechEvents["Tell Raphael to go to the room number 2"] = [
            NaoAgent.EVENT_SALLE_2_RAPHAEL, .30
        ]
        speechEvents["Tell Raphael to go to the room number 3"] = [
            NaoAgent.EVENT_SALLE_3_RAPHAEL, .30
        ]
        speechEvents["Tell Samira to go to the room number 1"] = [
            NaoAgent.EVENT_SALLE_1_SAMIRA, .27
        ]
        speechEvents["Tell Samira to go to the room number 2"] = [
            NaoAgent.EVENT_SALLE_2_SAMIRA, .30
        ]
        speechEvents["Tell Samira to go to the room number 3"] = [
            NaoAgent.EVENT_SALLE_3_SAMIRA, .30
        ]
        speechEvents["Tell one turtle to go near the other"] = [
            NaoAgent.EVENT_RASSEMBLEMENT, .35
        ]
        # rajout pour tester. Fabrice Gaignier
        speechEvents["Turtles push the box"] = [NaoAgent.EVENT_POUSSEZ, .30]

        # callbacks
        def recognitionCallback(dataName, value, message):

            d = dict(zip(value[0::2], value[1::2]))

            self.lock.acquire()
            if not self.isListening:
                self.isListening = True
                self.lock.release()
                return
            self.lock.release()

            for word in d:
                self.log(word + " " + str(d[word]))
                if d[word] > speechEvents[word][1]:
                    self.log(speechEvents[word][0])
                    self.raiseEvent(speechEvents[word][0])
                    return

            self.say("I did not understand")

        def speechCallback(eventName, value, subscriberIdentifier):
            if value[1] in ["thrown", "stopped", "done"
                            ] and not self.isAnimatedSay:
                self.lock.acquire()
                self.isListening = False
                self.lock.release()

                sleep(2)
                self.lock.acquire()
                self.isListening = True
                self.lock.release()

        def animatedSpeechCallback(eventName, taskId, subscriberIdentifier):
            self.lock.acquire()
            self.isListening = False
            self.lock.release()

            sleep(5)
            self.lock.acquire()
            self.isListening = True
            self.lock.release()

        def touchChangeCallback(eventName, touchInfo, subscriberIdentifier):
            for i in touchInfo:
                self.log(i)

        def rigthHandCallback(eventName, val, subscriberIdentifier):
            self.log(val)

        self.ip = selfIP
        self.broker = Broker('bootstrapBroker', naoIp=self.ip, naoPort=9559)

        # FluentNao
        self.nao = Nao(naoenv.make_environment(None))
        #self.nao.env.tts.setLanguage(language)
        self.memory = memory

        self.lock = Lock()
        self.isListening = True

        vocabulary = []
        vocabulary.extend(speechEvents.keys())

        try:
            self.nao.env.speechRecognition.pause(False)
            self.nao.env.speechRecognition.setVocabulary(vocabulary, False)
        except RuntimeError as e:
            self.nao.env.speechRecognition.pause(False)
            self.log(e.message, "RuntimeError")

        self.memory.subscribeToEvent('WordRecognized', recognitionCallback)
        self.memory.subscribeToEvent('ALTextToSpeech/Status', speechCallback)
        self.memory.subscribeToEvent('ALAnimatedSpeech/EndOfAnimatedSpeech',
                                     animatedSpeechCallback)
        # self.memory.subscribeToEvent('TouchChanged', touchChangeCallback)
        # self.memory.subscribeToEvent('HandRightBackTouched', rigthHandCallback)
        # self.memory.subscribeToEvent('HandRightLeftTouched', rigthHandCallback)
        # self.memory.subscribeToEvent('HandRightRightTouched', rigthHandCallback)

        self.destinationSpeech = dict()
        self.destinationSpeech["salle1"] = "the room 1"
        self.destinationSpeech["salle2"] = "the room 2"
        self.destinationSpeech["salle3"] = "the room 3"
        self.destinationSpeech["principale"] = "the principal room"

        self.cameraEventSpeech = defaultdict(lambda: "")
        self.cameraEventSpeech[
            "moveIn"] = "La camera m'indique que quelqu'un est entré dans l'espace"
        self.cameraEventSpeech[
            "moveOut"] = "La camera m'indique que quelqu'un est sorti de l'espace"