我已经用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()发布于 2018-06-26 19:07:42
只保留一个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()https://stackoverflow.com/questions/51024767
复制相似问题