| 1 | = [[https://is.muni.cz/auth/predmet/fi/pv277|PV277 Programming Applications for Social Robots]] (autumn 2019) = |
| 2 | |
| 3 | == Pepper API |
| 4 | |
| 5 | * http://doc.aldebaran.com/2-5/index_dev_guide.html |
| 6 | |
| 7 | === programming in Choregraphe via Python |
| 8 | * enter only one box `Python Script` |
| 9 | * edit its contents via double click: |
| 10 | * to `__init__` add: |
| 11 | {{{#!python |
| 12 | self.tts = ALProxy('ALTextToSpeech') |
| 13 | self.tts.setLanguage('Czech') |
| 14 | }}} |
| 15 | * to `onInput_onStart` add: |
| 16 | {{{#!python |
| 17 | self.tts.say("Ahoj, jak se máš?") |
| 18 | self.onStopped() |
| 19 | }}} |
| 20 | * add `Czech` into Project Properties [[br]] |
| 21 | [[Image(pepper_project_cz.png)]] |
| 22 | * save the project and run in on a virtual robot |
| 23 | * for details see http://doc.aldebaran.com/2-5/software/choregraphe/objects/python_script.html and http://doc.aldebaran.com/2-5/software/choregraphe/reference.html |
| 24 | |
| 25 | === speech input via Python |
| 26 | * in `__init__` add: |
| 27 | {{{#!python |
| 28 | try: |
| 29 | self.speech = ALProxy("ALSpeechRecognition") |
| 30 | self.speech.setLanguage('Czech') |
| 31 | except: |
| 32 | self.logger.info('Running on virtual robot') |
| 33 | self.speech = None |
| 34 | }}} |
| 35 | * process speech accordingly |
| 36 | {{{#!python |
| 37 | def get_answer(self, reactions): |
| 38 | if self.speech is None: |
| 39 | return (random.choice(reactions.keys())) |
| 40 | else: |
| 41 | self.speech.setVocabulary(reactions.keys(), False) |
| 42 | self.speech.subscribe("Test_ASR") |
| 43 | self.logger.info('Speech recognition engine started') |
| 44 | time.sleep(20) |
| 45 | self.speech.unsubscribe("Test_ASR") |
| 46 | |
| 47 | def onInput_onStart(self): |
| 48 | self.tts.say("Ahoj, jak se máš?") |
| 49 | reactions = { |
| 50 | 'dobře': 'to je super!', |
| 51 | 'špatně': 'doufám, že to brzo bude lepší', |
| 52 | 'nevím': 'tak to určitě nebude tak zlé', |
| 53 | } |
| 54 | answer = self.get_answer(reactions) |
| 55 | react = reactions.get(answer) |
| 56 | self.logger.info('answer={}, react={}'.format(answer, react)) |
| 57 | self.tts.say(react) |
| 58 | self.onStopped() |
| 59 | }}} |
| 60 | * see [http://doc.aldebaran.com/2-5/naoqi/audio/alspeechrecognition.html ALSpeechRecognition] documentation |
| 61 | |
| 62 | === dialog |
| 63 | * add boxes `Set Language` with `Czech` and add `Czech` to project properties |
| 64 | * right click the free area -> `Create a new box` -> `Dialog...` |
| 65 | * in the Dialog -> `Add Topic` - choose `Czech` and `Add to the package content as collaborative dialog` (allows to start the dialog just by talking to the robot) |
| 66 | * connect `onStart` -> `Set Language` -> `Dialog` |
| 67 | * in Project files double click on `dialog_czc.top` and enter |
| 68 | {{{ |
| 69 | topic: ~dialog() |
| 70 | language: czc |
| 71 | |
| 72 | concept:(ahoj) "ahoj robote" |
| 73 | concept:(dobrý_den) ["dobrý den" "krásný den" "krásný den přeju"] |
| 74 | |
| 75 | u:(~ahoj) ahoj člověče |
| 76 | \pau=1000\ |
| 77 | to máme dnes hezký den |
| 78 | |
| 79 | u:(~dobrý_den) ~dobrý_den |
| 80 | }}} |
| 81 | * see [http://doc.aldebaran.com/2-5/naoqi/interaction/dialog/dialog.html QiChat - Introduction] and [http://doc.aldebaran.com/2-5/naoqi/interaction/dialog/dialog-syntax_full.html QiChat - Syntax] for details |
| 82 | * beware that the "nice" function of recognizing any text via `_*` is unfortunately not available in the real robot - free speech recognition works only as a payed service over-the-network. The dialog must use predefined (possibly dynamic) concepts instead via `_~conceptName`. |
| 83 | |
| 84 | === adding animations |
| 85 | |
| 86 | * single animation - via `Animation` box |
| 87 | * connect to dialog: |
| 88 | * add rule to topic: |
| 89 | {{{ |
| 90 | u:(["můžeš zamávat" zamávej] {prosím}) ahojky $zamavej=1 |
| 91 | }}} |
| 92 | * add [http://doc.aldebaran.com/2-5/software/choregraphe/objects/box_input_output.html#choregraphe-reference-box-output output] to the dialog box (right click -> Edit box) named `zamavej` (Bang, punctual) |
| 93 | * add `Kisses` animation box, connect it to the `zamavej` output |
| 94 | * within the dialog: |
| 95 | {{{ |
| 96 | u:(~ahoj) ^start(animations/Stand/Gestures/Hey_1) ahoj člověče |
| 97 | \pau=1000\ |
| 98 | to máme dnes hezký den |
| 99 | ^wait(animations/Stand/Gestures/Hey_1) |
| 100 | }}} |
| 101 | shows only on real robot, see [http://doc.aldebaran.com/2-5/naoqi/motion/alanimationplayer-advanced.html#animationplayer-list-behaviors-pepper default list of animations] |
| 102 | |
| 103 | == Pepper API II |
| 104 | |
| 105 | === installing application to the robot |
| 106 | * make a ssh key (replace `<xlogin>` with your login): |
| 107 | {{{ |
| 108 | ssh-keygen -m PEM -t ecdsa -N '' -f ~/.ssh/pepper_<xlogin> |
| 109 | }}} |
| 110 | * copy your '''public''' key to the course directory: |
| 111 | {{{ |
| 112 | cp ~/.ssh/pepper_<xlogin>.pub /nlp/projekty/pepper/course/keys/ |
| 113 | }}} |
| 114 | * add host `karel` to your `$HOME/.ssh/config`: |
| 115 | {{{ |
| 116 | Host karel |
| 117 | User nao |
| 118 | HostName 192.168.88.10 |
| 119 | # IdentityFile is important for install_pkg.py |
| 120 | IdentityFile ~/.ssh/pepper_<xlogin> |
| 121 | StrictHostKeyChecking no |
| 122 | PubkeyAuthentication yes |
| 123 | }}} |
| 124 | * build the PKG package in Choregraphe |
| 125 | * test [https://nlp.fi.muni.cz/trac/pepper/wiki/LogView logview] |
| 126 | {{{ |
| 127 | ssh aurora |
| 128 | /nlp/projekty/pepper/bin/logview |
| 129 | }}} |
| 130 | * after the key is allowed, install it to the robot |
| 131 | {{{ |
| 132 | ssh aurora |
| 133 | /nlp/projekty/pepper/bin/install_pkg.py your_package.pkg |
| 134 | }}} |
| 135 | === running/launching the application |
| 136 | |
| 137 | * if the application contains a ''behavior'' (`behavior.xar`), it needs to be ''launched''. Behaviors can have two natures: ''interactive'' (used as a dialog) or ''solitary'' (used without a direct listener). Any behavior can be launched using one of 3 ways: |
| 138 | 1. specify the behavior's '''[http://doc.aldebaran.com/2-5/naoqi/interaction/triggerconditions.html trigger conditions]''' (works with both [http://doc.aldebaran.com/2-5/software/choregraphe/tutos/create_solitary_activity.html solitary] and [http://doc.aldebaran.com/2-5/software/choregraphe/tutos/create_interactive_activity.html interactive]) and/or its [http://doc.aldebaran.com/2-5/software/choregraphe/tutos/create_interactive_activity.html#step-2-transform-it-into-an-interactive-activity trigger sentences] |
| 139 | 1. run it with `run_app.py`: |
| 140 | {{{ |
| 141 | /nlp/projekty/pepper/bin/run_app.py your_package[/path_to_behavior] |
| 142 | }}} |
| 143 | call `run_app.py -l` to obtain a list of installed behaviors. |
| 144 | 1. call ''[http://doc.aldebaran.com/2-5/naoqi/interaction/autonomouslife-api.html#ALAutonomousLifeProxy::switchFocus ALAutonomousLife.switchFocus]'' or !QiChat [http://doc.aldebaran.com/2-5/naoqi/interaction/dialog/dialog-syntax_full.html#switchfocus ^switchFocus] |
| 145 | === using tablet |
| 146 | * from a dialogue (see [http://doc.aldebaran.com/2-5/getting_started/creating_applications/using_peppers_tablet.html QiChat - pCall]): |
| 147 | {{{ |
| 148 | u:(jak se můžu dostat na fakultu bez přijímaček?) |
| 149 | Způsobů je celá řada. |
| 150 | ^pCall(ALTabletService.showWebview("https://www.fi.muni.cz/admission/guide.html.cs")) |
| 151 | Všechno se dozvíš dnes na přednášce, od paní ze studijního |
| 152 | ^start(animations/Stand/Gestures/ShowTablet_3) |
| 153 | nebo na webu vvv fi muni cz v sekci pro uchazeče. |
| 154 | ^wait(animations/Stand/Gestures/ShowTablet_3) |
| 155 | }}} |
| 156 | * [http://doc.aldebaran.com/2-5/getting_started/creating_applications/using_peppers_tablet.html Using Pepper’s Tablet] |
| 157 | |
| 158 | === face characteristics |
| 159 | |
| 160 | * [http://doc.aldebaran.com/2-5/software/choregraphe/tutos/get_age.html Get Age]/Get Gender |
| 161 | * [http://doc.aldebaran.com/2-5/software/choregraphe/tutos/get_expression.html Get Expression] |
| 162 | |
| 163 | === creating application outside Choregraphe |
| 164 | |
| 165 | * prepare your `pepper` directory unless you already have one |
| 166 | {{{ |
| 167 | mkdir $HOME/pepper |
| 168 | }}} |
| 169 | * copy `template` directory |
| 170 | {{{ |
| 171 | cp -r /nlp/projekty/pepper/course/template $HOME/pepper/ |
| 172 | }}} |
| 173 | * rename the `template` to `template_<xlogin>` (replace `<xlogin>` with your login) or something else: |
| 174 | {{{ |
| 175 | mv $HOME/pepper/template $HOME/pepper/template_<xlogin> |
| 176 | cd $HOME/pepper/template_<xlogin> |
| 177 | }}} |
| 178 | * go through all files, rename the application where necessary |
| 179 | * build the PKG package (the version number will be increased): |
| 180 | {{{ |
| 181 | cd $HOME/pepper/template_<xlogin> |
| 182 | make pkg |
| 183 | }}} |
| 184 | * and install it |
| 185 | {{{ |
| 186 | cd $HOME/pepper/template_<xlogin> |
| 187 | make install |
| 188 | }}} |
| 189 | During the development this can be in one command |
| 190 | {{{ |
| 191 | make pkg install |
| 192 | }}} |
| 193 | |
| 194 | === creating own service |
| 195 | |
| 196 | * copy and rename `template-service` directory |
| 197 | {{{ |
| 198 | cp -r /nlp/projekty/pepper/course/template-service $HOME/pepper/ |
| 199 | mv $HOME/pepper/template-service $HOME/pepper/template-service_<xlogin> |
| 200 | cd $HOME/pepper/template-service_<xlogin> |
| 201 | }}} |
| 202 | * go through all files, rename the application where necessary |
| 203 | * build the PKG and install it |