LoginSignup
12
14

More than 5 years have passed since last update.

PepperのPythonで自作Box作成をしていくメモ

Posted at

PepperのBoxを作ってみます。色々と他の人が書いた記事は出てるけど備忘録です。

参考
pythonモジュール追加 http://qiita.com/hws-hitorobo/items/5b0178d291e87c643bf3
自作関数 http://qiita.com/Ryo87/items/77e1d19b80c77d2733c8
HTTP GETボックスの作成 http://qiita.com/Atelier-Akihabara/items/acc8d2ad6c3881f112a4

環境

  • Choregraphe 2.3.1
  • Python 2.7

作成

Box libraries > Programming > TemplatesにあるPython ScriptのBoxを追加しましょう。

ダブルクリックすると初期コードがみれます。

app.py
class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        #put initialization code here
        pass

    def onUnload(self):
        #put clean-up code here
        pass

    def onInput_onStart(self):
        #self.onStopped() #activate the output of the box
        pass

    def onInput_onStop(self):
        self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
        self.onStopped() #activate the output of the box

ログを出してみる

JavaScriptでいうconsole.log()が欲しいところだけど、
self.logger.info()が使えそうです。

わかりやすくするために初期コメントを消して追記しました。

app.py
class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        pass

    def onUnload(self):
        pass

    def onInput_onStart(self):
        self.logger.info("はろー") #←追記
        pass

    def onInput_onStop(self):
        self.onUnload()
        self.onStopped()

実行するとこんな感じでLog Viewerに流れます。

しゃべらせる

self.tts = ALProxy('ALTextToSpeech')でしゃべる機能を使う準備です。
self.tts.post.say()で実際にしゃべります。

app.py
class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        self.tts = ALProxy('ALTextToSpeech') #←追記

    def onLoad(self):
        pass

    def onUnload(self):
        pass

    def onInput_onStart(self):
        self.logger.info("はろー")
        self.tts.post.say("りゅうざきさん、おはようございます。") #←追記
        pass

    def onInput_onStop(self):
        self.onUnload()
        self.onStopped()

ちょうど通りかかった龍崎さんに話しかけました。


http://liginc.co.jp/member/member_detail?user=dragon

まとめ

self.logger.info()self.tts.post.say()を覚えた。

12
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
14