Another day, another blog...
So after getting the servos to work I found out that the pigpio library, although it works marvelously, kills the AIY voice control dead. As soon as the service is started (with sudo pigpio command), the AIY microphone didn't hear what I was saying. I have numbers android phones and tablets on my desk, and they all heard and responded to my Hey/OK Google attempts, but not the Voice Hat. The only way to recover (even after doing a killall pigpio command) was to reboot. So I had to go back to the jittery gpiozero library. I did find that there was a command to detach from the servo and that stopped the jittering completely. So, when I start my code loop, the first thing i do is detach from the servo. When I have to move the servo, I set the angle desired, and then sleep for 4 seconds to allow the servo to move. By the time the sleep is done, the servo is in its proper spot and then it is detached from. I also changed the frame width parameter from the default setting of 20 down to 10. That seemed to slow the jitter down.
Using the old-new library I figured out the proper angles to stop the servo at so that the lifter was as close as possible to the middle of the opening. The video shows the voice activated control of the spinning platter.
And here is the test code...
Code block |
---|
#!/usr/bin/env python3 import aiy.audio import aiy.cloudspeech import aiy.voicehat from gpiozero import AngularServo import time
def main(): recognizer = aiy.cloudspeech.get_recognizer() recognizer.expect_phrase('meat') recognizer.expect_phrase('cheese') recognizer.expect_phrase('water') recognizer.expect_phrase('milk') recognizer.expect_phrase('toaster') recognizer.expect_phrase('oven') recognizer.expect_phrase('knife') recognizer.expect_phrase('spoon') recognizer.expect_phrase('pan') recognizer.expect_phrase('pepper') recognizer.expect_phrase('salt') recognizer.expect_phrase('spatula') recognizer.expect_phrase('sugar') recognizer.expect_phrase('basil') recognizer.expect_phrase('lemon') recognizer.expect_phrase('clove') button = aiy.voicehat.get_button() aiy.audio.get_recorder().start() #servo =AngularServo(6) s =AngularServo(6,min_angle=-180, max_angle=180,frame_width = 10/1000)
while True: s.detach() print('Press the button and speak') button.wait_for_press() print('Listening...') text = recognizer.recognize() if text is None: print('Sorry, I did not hear you.') else: print('You said "', text, '"') if 'meat' in text: print('Moving servo to bottle one') s.angle=-176
time.sleep(4)
elif'cheese'in text: print('Moving servo to bottle two') #servo.min() s.angle=-155 time.sleep(4)
elif'water'in text: print('Moving servo to bottle three') #servo.mid() s.angle=-135 time.sleep(4)
elif 'milk' in text: print('Moving servo to bottle four') #servo.mid() s.angle=-113 time.sleep(4)
elif'toaster'in text: print('Moving servo to bottle five') #servo.mid() s.angle=-95 time.sleep(4)
elif'oven'in text: print('Moving servo to bottle six') #servo.mid() s.angle=-73 time.sleep(4)
elif'knife'in text: print('Moving servo to bottle seven') #servo.mid() s.angle=-53 time.sleep(4)
elif'spoon'in text: print('Moving servo to bottle eight') #servo.mid() s.angle=-31 time.sleep(4)
elif'pan'in text: print('Moving servo to bottle nine') #servo.mid() s.angle=-18 time.sleep(4)
elif'pepper'in text: print('Moving servo to bottle ten') #servo.mid() s.angle=10 time.sleep(4)
elif'salt'in text: print('Moving servo to bottle eleven') #servo.mid() s.angle=36 time.sleep(4)
elif'spatula'in text: print('Moving servo to bottle twelve') #servo.mid() s.angle=58 time.sleep(4)
elif'sugar'in text: print('Moving servo to bottle thirteen') #servo.mid() s.angle=85 time.sleep(4)
elif'basil'in text: print('Moving servo to bottle fourteen') #servo.mid() s.angle=107 time.sleep(4)
elif'lemon'in text: print('Moving servo to bottle fifteen') #servo.mid() s.angle=129 time.sleep(4)
elif'clove'in text: print('Moving servo to bottle sixteen') #servo.mid() s.angle=151 time.sleep(4)
if __name__ =='__main__': main() |
Now to find the proper values for the lifting mechanism and activate the motion and lifting with an OK/Hey Google alert instead of using the push button.
Design Challenge Links:
Project Links:
Blog Glenn 1 - AIY Voice Kit Unboxing
Blog Doug 2 - The Block Diagram and Bill of Materials
Blog Doug 3 - Spice Jar Lift Mechanism
Blog Glenn 2 - Firmware Considerations
Blog Doug 5 - Platter Rotation Mechanism
The Spice of Pi - Blog Glenn 3
Blog Doug 6 - 3D Printed Platter Parts
Blog Doug 7 - Main Drive Assembly
Blog Doug 8 - Working Carousel
Blog Doug 9 - Google Assistant
The Spice of Pi - Glenn blog #4
The Spice of Pi - Glenn blog #5
Top Comments