繁体   English   中英

如何修复 ALDialog Python 脚本 NAOqi 错误

[英]How to fix ALDialog Python Script NAOqi Error

我正在尝试使用 ALDialog 模块与 Choregraphe 模拟的 NAO6 机器人进行虚拟对话。 我有以下脚本:

import qi
import argparse
import sys

def main(session):
    """
    This example uses ALDialog methods.
    It's a short dialog session with two topics.
    """
    # Getting the service ALDialog
    ALDialog = session.service("ALDialog")
    ALDialog.setLanguage("English")

    # writing topics' qichat code as text strings (end-of-line characters are important!)
    topic_content_1 = ('topic: ~example_topic_content()\n'
                       'language: enu\n'
                       'concept:(food) [fruits chicken beef eggs]\n'
                       'u: (I [want "would like"] {some} _~food) Sure! You must really like $1 .\n'
                       'u: (how are you today) Hello human, I am fine thank you and you?\n'
                       'u: (Good morning Nao did you sleep well) No damn! You forgot to switch me off!\n'
                       'u: ([e:FrontTactilTouched e:MiddleTactilTouched e:RearTactilTouched]) You touched my head!\n')

    topic_content_2 = ('topic: ~dummy_topic()\n'
                       'language: enu\n'
                       'u:(test) [a b "c d" "e f g"]\n')

    # Loading the topics directly as text strings
    topic_name_1 = ALDialog.loadTopicContent(topic_content_1)
    topic_name_2 = ALDialog.loadTopicContent(topic_content_2)

    # Activating the loaded topics
    ALDialog.activateTopic(topic_name_1)
    ALDialog.activateTopic(topic_name_2)

    # Starting the dialog engine - we need to type an arbitrary string as the identifier
    # We subscribe only ONCE, regardless of the number of topics we have activated
    ALDialog.subscribe('my_dialog_example')

    try:
        raw_input("\nSpeak to the robot using rules from both the activated topics. Press Enter when finished:")
    finally:
        # stopping the dialog engine
        ALDialog.unsubscribe('my_dialog_example')

        # Deactivating all topics
        ALDialog.deactivateTopic(topic_name_1)
        ALDialog.deactivateTopic(topic_name_2)

        # now that the dialog engine is stopped and there are no more activated topics,
        # we can unload all topics and free the associated memory
        ALDialog.unloadTopic(topic_name_1)
        ALDialog.unloadTopic(topic_name_2)


if __name__ == "__main__":

    session = qi.Session()
    try:
        session.connect("tcp://desktop-6d4cqe5.local:9559")
    except RuntimeError:
        print ("\nCan't connect to Naoqi at IP desktop-6d4cqe5.local(port 9559).\nPlease check your script's arguments."
               " Run with -h option for help.\n")
        sys.exit(1)
    main(session, "desktop-6d4cqe5.local")

我的模拟机器人有 desktop-6d4cqe5.local 作为 IP 地址,它的 NAOqi 端口在 63361 上运行。我想在 python 脚本中运行 Choregraphe 之外的对话框,并且只能使用 Choregraphe 中的对话框进行测试. 当我运行上面的 python 文件时,我得到了:

Traceback (most recent call last):
  File "C:\Users\...\Documents\...\choregraphe_codes\Welcome\speak.py", line 6, in <module>
    import qi
  File "C:\Python27\Lib\site-packages\pynaoqi\lib\qi\__init__.py", line 93
    async, PeriodicTask)
    ^
SyntaxError: invalid syntax
  

我无法弄清楚问题所在,因为在线资源不多,而且机器人的文档有点难以理解。

请帮忙,谢谢。

您正在使用大于 3.5 的 Python 版本运行脚本,现在将async视为关键字。

NAOqi 仅支持 Python 2. 尝试使用python2显式运行脚本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM