【问题标题】:Python Definition and Arguments With Flask-Ask Intent带有 Flask-Ask 意图的 Python 定义和参数
【发布时间】:2018-06-25 13:33:22
【问题描述】:

我使用flask-ask 编写了一个python 程序来制作一个控制步进电机的自定义alexa 技能。当 Alexa 运行该技能时,它会运行并询问我想要哪个位置,值从 1 到 7。但是我不确定我是否正确定义了我的函数和参数。下面的代码包含我的 Alexa 技能中的意图,以及电机可以设置到的第一个位置。对于我定义函数、包含参数以及将它们链接到我的 if 语句以及是否需要以不同方式完成的方式的任何反馈,我们将不胜感激。

#Position intent, this is our answer to the welcome message
@ask.intent("PositionIntent", convert ={'one': int, 'two': int, 'three': int,
                                        'four': int, 'five': int, 'six': int,
                                        'seven': int})


def position(one, two, three, four, five, six, seven):

    if [one] == 1:
            if (pos1 < previous_position):  
                step_count = abs(pos1 - previous_position)
                turn_motor()
                previous_position = pos1
            else:
                GPIO.output(DIR, CCW)
                step_count = abs(pos1 - previous_position)
                turn_motor()
                previous_position = pos1
            GPIO.cleanup()

【问题讨论】:

    标签: python python-2.7 flask-ask


    【解决方案1】:

    不要保留多个槽,只保留一个AMAZON.NUMBER 类型的槽。相应地在 Web 应用中实现逻辑。

        @ask.intent("PositionIntent", convert = {'pos': int})
        def position(pos)
            if pos == 1:
                if (pos1 < previous_position):  
                    step_count = abs(pos1 - previous_position)
                    turn_motor()
                    previous_position = pos1
                else:
                    GPIO.output(DIR, CCW)
                    step_count = abs(pos1 - previous_position)
                    turn_motor()
                    previous_position = pos1
                GPIO.cleanup()
    

    【讨论】:

    • 我会试一试。昨晚我进行了更多测试,并且能够使用多个意图使其工作。我只想使用一个意图,所以我会尝试像这样设置它并回复你。
    猜你喜欢
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    相关资源
    最近更新 更多