Search code examples
pepperchoregraphe

Pepper: pass variable from Python to web JS


I'm programming an App for the Aldebaran's Pepper robot. I'm using Choregraphe and I made an html for displaying in robots tablet. I have made the boxes for displaying the web and I need to pass a variable from Python to the web Javascript.

Is there any way to do it?

The Python code is the same as the default of a Raise Event box, it receives a string "IMAGE" on his onStart input:

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        pass

    def onLoad(self):
        self.memory = ALProxy("ALMemory")

    def onUnload(self):
        self.memory = None

    def onInput_onStart(self, p):
        self.memory.raiseEvent(self.getParameter("key"), p)
        self.onStopped(p)

    def onInput_onStop(self):
        self.onUnload() #~ it is recommended to call onUnload of this box in a onStop method, as the code written in onUnload is used to stop the box as well
        pass

And the Javascript code is this:

$('document').ready(function(){

    var session = new QiSession();

    session.service("ALMemory").done(function (ALMemory) {
        ALMemory.subscriber("PepperQiMessaging/totablet").done(function(subscriber) {
            $("#log").text("AAA");
            subscriber.signal.connect(toTabletHandler);
        });
    });

    function toTabletHandler(value) {
          $("#log").text("-> ");
    }
});

It enters the first #log but not the second of JS.

Choregraphe scheme


Solution

  • I solved the problem. I put a delay box of 2 seconds between the show HTML box and the sendImage box like in the image below:

    Choreographe Scheme

    I think the problem was that the string that is send to tabled was sent before the web was prepared to receive it, and the delay of 2 seconds (with 1 it doesn't work) the page have time to prepare for receiving data.