Skip to content

Instantly share code, notes, and snippets.

@beaucarnes
Created January 8, 2019 18:48
Show Gist options
  • Save beaucarnes/fd9da92afa38c82a29b577ab52598f9d to your computer and use it in GitHub Desktop.
Save beaucarnes/fd9da92afa38c82a29b577ab52598f9d to your computer and use it in GitHub Desktop.
Code to control my Vector through YouTube live stream.
#!/usr/bin/env python
from time import sleep
import anki_vector
from youtubechat import YoutubeLiveChat, get_live_chat_id_for_stream_now
livechat_id = get_live_chat_id_for_stream_now("oauth_creds")
chat_obj = YoutubeLiveChat("oauth_creds", [livechat_id])
args = anki_vector.util.parse_command_args()
def respond(msgs, chatid):
for msg in msgs:
print(msg)
author = str(msg.author.display_name)
msg = str(msg)
if msg.startswith("hey vector"):
with anki_vector.Robot(args.serial) as robot:
if msg == "hey vector leave charger":
print('driving off charger')
robot.behavior.drive_off_charger()
if msg == "hey vector i love you":
robot.anim.play_animation("anim_feedback_iloveyou_01")
if msg == "hey vector it is cold":
robot.anim.play_animation("anim_weather_cold_01")
if msg == "hey vector beep":
robot.anim.play_animation("anim_timer_beep_01")
if msg == "hey vector go home":
robot.behavior.drive_on_charger()
if msg == "hey vector eyes blue":
robot.behavior.set_eye_color(hue=.75, saturation=0.99)
sleep(5)
if msg == "hey vector eyes green":
robot.behavior.set_eye_color(hue=.25, saturation=0.99)
sleep(5)
if msg == "hey vector eyes red":
robot.behavior.set_eye_color(hue=.0, saturation=0.99)
sleep(5)
if msg == "hey vector drive circle":
robot.behavior.drive_off_charger()
robot.behavior.turn_in_place(anki_vector.util.degrees(360))
if msg == "hey vector turn left":
robot.behavior.drive_off_charger()
robot.behavior.turn_in_place(anki_vector.util.degrees(90))
if msg == "hey vector turn right":
robot.behavior.drive_off_charger()
robot.behavior.turn_in_place(anki_vector.util.degrees(-90))
if msg == "hey vector lift arm":
robot.behavior.set_lift_height(0.7)
if msg == "hey vector subscribe reminder":
robot.say_text("Smash that subscribe button.")
if msg == "hey vector hello":
robot.say_text("Hello " + author)
try:
chat_obj.start()
chat_obj.subscribe_chat_message(respond)
chat_obj.join()
finally:
chat_obj.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment