1

I'm using a Nao robot, and the python SDK, and I'm trying to create my own module for it. Right now it is just a dummy module with one function: getJoke().

I have my file tellAJoke.py located under the path /home/nao/tellAJoke.py and I have updated the autoload.ini file to include the following:

[python]
/home/nao/tellAJoke.py

When I boot up the robot, it says what it normally does on startup, but also says what my getJoke() function returns, "This is a bad joke".

I'm not sure what I'm doing wrong here. When I ssh onto the robot, and run the code it runs just fine, but never when I want to import the module with ALProxy in Choreographe.

EDIT: I added the actual dummy code I have.

from naoqi import ALBroker
from naoqi import ALModule
from naoqi import ALProxy
import sys

class JokerModule(ALModule):
    """Tells you a random joke"""
    def __init__(self, name):
        print "WE HAVE INITED"


        self.tts = ALProxy("ALTextToSpeech")
        ALModule.__init__(self, name)

        global memory
        memory = ALProxy("ALMemory")
        memory.subscribeToEvent("SayingJoke", "Joker", "getJoke")

    def getJoke(self, *_args):
        """Returns a joke"""
        self.tts.say("Joke time!")

def main():
    """main entry point"""
    pip = '192.168.1.104'
    pport = 9559

    myBroker = ALBroker("myBroker", '0.0.0.0', 0, pip, pport)

    global Joker
    Joker = JokerModule("Joker")
    speechProxy = ALProxy("ALTextToSpeech")
    Joker.getJoke()

if __name__ == '__main__':
    main()

1 Answers1

0

Here is a guide on making services (a.k.a. "modules", but that term is confusing because it has another meaning in Python): http://doc.aldebaran.com/2-4/dev/libqi/guide/py-service.html (this doc is for NAOqi 2.4 but things should work mostly the same for 2.1, which is more often used on NAO)

But, you might want to try Robot Jumpstarter, that contains templates for various typical projects, including a python service (that works as explained in the document above).

clone it and run python jumpstart.py python-service tell-a-joke TellAJoke

... and it will generate a project that you can:

  • install on the robot witch Choregraphe
  • run in standalone with python tell-a-joke/app/scripts/tellajoke.py --qi-url your-naos-ip

... and in both cases you will be able to call it from from Choregraphe boxes etc.

(edit)

Now that you posted your code - in this specific case your problem is just that after Joker.getJoke(), your program reaches the end and terminates. The usual "modern" way of doing that would be with a qi.Application() that would .run() (all that is done in the jumpstarter template). You could do a while True: sleep(1) or something, which is not very pretty but would work (I recommend migrating to NAOqi 2, and instead of using ALProxy and ALBroker, use session.service and qi.Application ... the two are interoperable)

Emile
  • 2,946
  • 2
  • 19
  • 22
  • Thank you for that, the Robot Jumpstarter seems really neat for future use, I think my issue however is slightly different. I can create the module, (services use qiMessaging which we aren't trying to use yet) however I can't get it installed on the robot so that it recognizes it as a module, or choreographe block – Nicholas Hernandez Aug 31 '18 at 18:52
  • ah, now that you added your code I updated it. I think your issue is just that your program terminates. BTW, do you have a particular reason to not use qimessaging ? – Emile Aug 31 '18 at 20:35
  • Under the documentation for the version we are using, it says it is in beta. So we haven't been using that yet. – Nicholas Hernandez Sep 10 '18 at 18:10