On Sunday, I plugged in the lifting servo after unplugging the spinning servo, and just blindly ran the code for my angle testing. I had completely forgotten that the servo was not the same as the spinning servo, and had a much smaller range of motion. The servo ended up moving and tried to go further than the lifter barrel had tolerance for. You can see the lifter assembly quite well at the beginning of the video in Dougs blog number 8. So, I actually broke the screw flange on the inner lifter. Not a huge deal, as these parts were 3d printed. I had some unsticky glue that I used to tack the 2 pieces back together so I could get the proper angles for lifting the bottles.
Tonight, I added code in to select the right bottle location and lift it. Unfortunately it still causes a segmentation fault that I don't seem to be able to find the reason for. I will have to cut back on some bottle code so I can reduce the complexity and get it working with 2 or 3 bottles and then add more bottles until I am complete.
#!/usr/bin/env python3
import logging import subprocess import sys import aiy.assistant.auth_helpers import aiy.audio import aiy.voicehat from google.assistant.library import Assistant from google.assistant.library.event import EventType from gpiozero import AngularServo import time
logging.basicConfig( level=logging.INFO, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s" )
def power_off_pi(): aiy.audio.say('Good bye!') subprocess.call('sudo shutdown now', shell=True)
def reboot_pi(): aiy.audio.say('See you in a bit!') subprocess.call('sudo reboot', shell=True)
def say_ip(): ip_address = subprocess.check_output("hostname -I | cut -d' ' -f1", shell=True) aiy.audio.say('My IP address is %s' % ip_address.decode('utf-8'))
def get_spice(SpinAngle, LiftAngle): spinner=AngularServo(6,min_angle=-180, max_angle=180,frame_width = 10/1000) lifter = AngularServo(5,min_angle = -45, max_angle = 30, frame_width = 10/1000) spinner.detach() lifter.detach() lifter.angle = -20 time.sleep(1) spinner.angle = SpinAngle print ('Moving platter') time.sleep(4) spinner.detach() lifter.angle=LiftAngle print ('Lifting bottle') time.sleep(1) lifter.detach() print ('Enjoy your spice!')
def process_event(assistant, event): status_ui = aiy.voicehat.get_status_ui() if event.type == EventType.ON_START_FINISHED: status_ui.status('ready') if sys.stdout.isatty(): print('Say "OK, Google" then speak, or press Ctrl+C to quit...')
elif event.type == EventType.ON_CONVERSATION_TURN_STARTED: status_ui.status('listening')
elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and event.args: print('You said:', event.args['text']) text = event.args['text'].lower() if text == 'power off': assistant.stop_conversation() power_off_pi() elif text == 'reboot': assistant.stop_conversation() reboot_pi() elif text == 'jar 1': assistant.stop_conversation() get_spice(-176,-20) elif text == 'jar 2': assistant.stop_conversation() get_spice(-155,-20) elif text == 'jar 3': assistant.stop_conversation() get_spice(-155,20) elif text == 'jar 4': assistant.stop_conversation() get_spice(-135,-20) elif text == 'jar 5': assistant.stop_conversation() get_spice(-113,-20) elif text == 'jar 6': assistant.stop_conversation() get_spice(-113,20) elif text == 'jar 7': assistant.stop_conversation() get_spice(-95,-20) elif text == 'jar 8': assistant.stop_conversation() get_spice(-73,-20) elif text == 'jar 9': assistant.stop_conversation() get_spice(-73,20) elif text == 'jar 10': assistant.stop_conversation() get_spice(-53,-20) elif text == 'jar 11': assistant.stop_conversation() get_spice(-31,-20) elif text == 'jar 12': assistant.stop_conversation() get_spice(-31,20) elif text == 'jar 13': assistant.stop_conversation() get_spice(-18,-20) elif text == 'jar 14': assistant.stop_conversation() get_spice(10,-20) elif text == 'jar 15': assistant.stop_conversation() get_spice(10,20) elif text == 'jar 16': assistant.stop_conversation() get_spice(36,-20) elif text == 'jar 17': assistant.stop_conversation() get_spice(58,-20) elif text == 'jar 18': assistant.stop_conversation() get_spice(58,20) elif text == 'jar 19': assistant.stop_conversation() get_spice(85,-20) elif text == 'jar 20': assistant.stop_conversation() get_spice(107,-20) elif text == 'jar 21': assistant.stop_conversation() get_spice(107,20) elif text == 'jar 22': assistant.stop_conversation() get_spice(129,-20) elif text == 'jar 23': assistant.stop_conversation() get_spice(151,-20) elif text == 'jar 24': assistant.stop_conversation() get_spice(151,20)
elif event.type == EventType.ON_END_OF_UTTERANCE: status_ui.status('thinking')
elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED: status_ui.status('ready')
elif event.type == EventType.ON_ASSISTANT_ERROR and event.args and event.args['is_fatal']: sys.exit(1)
def main(): credentials = aiy.assistant.auth_helpers.get_assistant_credentials() with Assistant(credentials) as assistant: for event in assistant.start(): process_event(assistant, event)
if __name__ == '__main__': main() |
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
The Spice of Pi - Glenn blog # 6