Skip to content

Instantly share code, notes, and snippets.

@tai-fukaya
Last active May 25, 2016 07:04
Show Gist options
  • Save tai-fukaya/53eef8f7caab8c29ecc25ece5cc8d085 to your computer and use it in GitHub Desktop.
Save tai-fukaya/53eef8f7caab8c29ecc25ece5cc8d085 to your computer and use it in GitHub Desktop.
見逃した夢をもう一度見るスクリプト※残念ながら、Pepperでしか使用できません。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from naoqi import ALProxy
if (len(sys.argv) < 2):
print "Usage: 'python itsudemo_yumewo.py IP [PORT]'"
sys.exit(1)
IP = sys.argv[1]
PORT = 9559
if (len(sys.argv) > 2):
PORT = sys.argv[2]
try:
behav = ALProxy("ALBehaviorManager", IP, PORT)
except Exception,e:
print "Could not create proxy to ALBehaviorManager"
print "Error was: ",e
sys.exit(1)
try:
tts = ALProxy("ALTextToSpeech", IP, PORT)
except Exception,e:
print "Could not create proxy to ALTextToSpeech"
print "Error was: ",e
sys.exit(1)
try:
autonomous = ALProxy("ALAutonomousLife", IP, PORT)
except Exception,e:
print "Could not create proxy to ALAutonomousLife"
print "Error was: ",e
sys.exit(1)
try:
motion = ALProxy("ALMotion", IP, PORT)
except Exception,e:
print "Could not create proxy to ALMotion"
print "Error was: ",e
sys.exit(1)
# 夢のビヘイビアパスを取得
behavList = [b for b in behav.getInstalledBehaviors() if '_pepper-dream365_' in b]
# behavMaps[month][date]に置き換え
behavMaps = {}
for b in behavList:
month = b[-4:-2]
date = b[-2:]
if month not in behavMaps:
behavMaps[month] = {}
behavMaps[month][date] = b
# 指定日付の夢を見る
def seeDream(month, date):
print 'This is a %s/%s\'s dream' % (month, date)
behav.runBehavior(behavMaps[month][date])
# 日付を選択する
def selectDream():
print "Which month?"
keys = behavMaps.keys()
keys.sort()
print keys
input_month = raw_input('>>> ')
if input_month in behavMaps:
keys = behavMaps[input_month].keys()
keys.sort()
print "What's the date?"
print keys
input_date = raw_input('>>> ')
if input_date in behavMaps[input_month]:
seeDream(input_month, input_date)
next()
# まだ見るかどうか
def next():
input = raw_input('more?[Y/n]>>> ')
if input != 'n':
selectDream()
# 前処理(オートノマスを切る)
autonomous.setState('disabled')
motion.wakeUp()
tts.setParameter("inputMode", 2)
# 夢選択
selectDream()
# 後始末(オートノマスを再始動)
tts.setParameter("inputMode", 3)
autonomous.setState('solitary')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment