我使用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()