I decided to wire up the Google AIY box to Marty the Robot.
The first thing to do was to upgrade the software so I did not have to press the button to work the robot. I followed Eric Duncan Google AIY upgrade steps.
After stopping the service
sudo systemctl stop voice-recognizer.service
I then edited the config file to switch to "Ok Google" mode rather than button mode.
And set the trigger to be
trigger = ok-google
Configuring for Marty
Next I installed the Marty Python library from Robotical
cd ~/voice-recognizer-raspi source env/bin/activate pip install martypy
Next up is adding some custom actions to google AIY
I edited the actions file and included the Marty library.
import datetime import logging import subprocess import martypy import phue from rgbxy import Converter
Then in the make_actor function I added my own command.
# ========================================= # Makers! Add your own voice commands here. # ========================================= actor.add_keyword(_('raspberry power off'), PowerCommand(say, 'shutdown')) actor.add_keyword(_('raspberry reboot'), PowerCommand(say, 'reboot')) actor.add_keyword(_('marty walk'), MartyCommand(say, 'walk')) return actor
Then finally I added a class to process that command, I based the flow on the Hue Lightbulb one provided. I used the "calibrate tool" to find my Marty but I think it's also possible to find them in code. I'd also recommend enhancing the code to cope with exceptions.
# Control Marty the robot # # class MartyCommand(object): """Control Marty the Robot""" def __init__(self, say, command): self.say = say self.command = command mymarty = self.connect() mymarty.hello() # Move to zero positions and wink mymarty.enable_motors() def connect(self): return martypy.Marty('socket://192.168.1.77') # Change IP to match your Marty def run(self, voice_command): if self.command == "walk": self.say("Walking forward 5 paces") mymarty = self.connect() mymarty.walk(5) else: logging.error("Error identifying Martys command.") self.say("Sorry I didn't identify that command")
Finally to test run
Once you are happy with testing you can restart the recogniser service with
sudo systemctl start voice-recognizer
My biggest issue was that Google did not like my accent so I ended up adding lots of keywords with the combinations that the voice recognition had detected. Also the detection needs to match exactly so you'd end up having to add lots of different commands. One approach is the approach taken by Marcin Gorecki to use wild cards. You could then say "Marty Walk Forward Five Paces" and have the recognition software parse the number of steps.