Pepper:将变量从Python传递到Web JS [英] Pepper: pass variable from Python to web JS
问题描述
我正在为Aldebaran的Pepper机器人编写一个应用程序.我正在使用Choregraphe,并制作了一个用于在机器人平板电脑中显示的html.我已经完成了用于显示网络的框,并且需要将Python中的变量传递给网络Javascript.
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.
有什么办法吗?
Python代码与引发事件"框的默认代码相同,它在onStart
输入上接收到字符串"IMAGE":
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
而Javascript代码是这样的:
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("-> ");
}
});
它进入JS的第一个#log
而不是第二个.
It enters the first #log
but not the second of JS.
推荐答案
我解决了这个问题.我在 show HTML 框和 sendImage 框之间放置了一个2秒钟的 delay 框,如下图所示:
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:
我认为问题在于发送到表的字符串是在Web准备接收之前发送的,并且2秒的延迟(如果1则不起作用),页面有时间准备接收数据.
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.
这篇关于Pepper:将变量从Python传递到Web JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!