【问题标题】:Callback function when PEPPER's tablet gets touched, only works correctly the first time触摸 PEPPER 的平板电脑时的回调函数,只有第一次才能正常工作
【发布时间】:2023-01-24 18:50:42
【问题描述】:

我一直试图在 PEPPER 的平板电脑上制作一个简单的“是或否”按钮。

我只是通过显示带有“是-否”的图像并在有人使用 tabletService.onTouchDown 功能触摸平板电脑时捕获 X 坐标来做到这一点。

问题是它第一次工作得很好,但我需要它来处理多个答案,第二次我调用它“跳过”等待回调的函数,就好像它已经得到它一样。

这是捕捉触摸的功能; 它只检查触摸的 X 坐标并返回 1 或 0,具体取决于它是在屏幕的左侧还是右侧进行的:

def getAnswer():
global ans
showIm()
try: 
    signalID=0
    ans = -1

    def callback(x, y): #it doesn't enter the callback on the second time
        global ans
        print "coordinate are x: ", x, " y: ", y
        if x > 640:
            ans = 0
        elif x < 640:
            ans = 1
            
        app.stop()
        return ans
    print(signalID)
    signalID = tabletService.onTouchDown.connect(callback)
    print(signalID)
    app.run()

    tabletService.onTouchDown.disconnect(signalID)
    return ans

except Exception, e:
    print "Error was: ", e    

这是两次调用“getAnswer”的函数:

def start():
global messagetosend, context, ans

outer = "Test Si o No"
produce_outer(outer)

ans = getAnswer()

if ans == 1:
    outer = "Hai cliccato SI"
    produce_outer(outer)

elif ans == 0:
    outer = "Hai cliccato NO"
    produce_outer(outer)


#-------------------------------------------------------------------------
ans = getAnswer()
#tabletService.resetTablet()

if ans == 1:
    outer = "Hai cliccato SI"
    produce_outer(outer)

elif ans == 0:
    outer = "Hai cliccato NO"
    produce_outer(outer)

tabletService.hideImage() 

甚至尝试了一个应该重置平板电脑缓存的功能等等,但它似乎没有帮助所以我删除了它。 奇怪的是,如果你“垃圾点击”屏幕,在程序跳过它之前,回调有效但不能真正要求人们垃圾点击它。

附:我知道代码可能很脏,但我正在“尝试让这东西工作模式”,所以我现在并没有真正专注于让它变得优雅。 p.p.s.不知道您是否需要我设置连接的代码部分,现在就让我来吧。

非常感谢你提前

【问题讨论】:

  • 你回调中的这个“app.stop()”对我来说似乎很奇怪。如果你停止某件事,下次它就不会起作用......
  • 试图删除 app.stop() 但它不再退出回调,即使返回
  • 没有理由回调不退出,它应该是别的东西,就像你认为它不退出,但它是。

标签: python callback signals robotics pepper


【解决方案1】:

app.stop() 停止处理所有 NAOqi 信号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多