= [[https://is.muni.cz/auth/predmet/fi/pv277|PV277 Programming Applications for Social Robots]] (autumn 2019) = == Pepper API * http://doc.aldebaran.com/2-5/index_dev_guide.html === programming in Choregraphe via Python * enter only one box `Python Script` * edit its contents via double click: * to `__init__` add: {{{#!python self.tts = ALProxy('ALTextToSpeech') self.tts.setLanguage('Czech') }}} * to `onInput_onStart` add: {{{#!python self.tts.say("Ahoj, jak se máš?") self.onStopped() }}} * add `Czech` into Project Properties [[br]] [[Image(pepper_project_cz.png)]] * save the project and run in on a virtual robot * 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 === speech input via Python * in `__init__` add: {{{#!python try: self.speech = ALProxy("ALSpeechRecognition") self.speech.setLanguage('Czech') except: self.logger.info('Running on virtual robot') self.speech = None }}} * process speech accordingly {{{#!python def get_answer(self, reactions): if self.speech is None: return (random.choice(reactions.keys())) else: self.speech.setVocabulary(reactions.keys(), False) self.speech.subscribe("Test_ASR") self.logger.info('Speech recognition engine started') time.sleep(20) self.speech.unsubscribe("Test_ASR") def onInput_onStart(self): self.tts.say("Ahoj, jak se máš?") reactions = { 'dobře': 'to je super!', 'špatně': 'doufám, že to brzo bude lepší', 'nevím': 'tak to určitě nebude tak zlé', } answer = self.get_answer(reactions) react = reactions.get(answer) self.logger.info('answer={}, react={}'.format(answer, react)) self.tts.say(react) self.onStopped() }}} * see [http://doc.aldebaran.com/2-5/naoqi/audio/alspeechrecognition.html ALSpeechRecognition] documentation === dialog * add boxes `Set Language` with `Czech` and add `Czech` to project properties * right click the free area -> `Create a new box` -> `Dialog...` * 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) * connect `onStart` -> `Set Language` -> `Dialog` * in Project files double click on `dialog_czc.top` and enter {{{ topic: ~dialog() language: czc concept:(ahoj) "ahoj robote" concept:(dobrý_den) ["dobrý den" "krásný den" "krásný den přeju"] u:(~ahoj) ahoj člověče \pau=1000\ to máme dnes hezký den u:(~dobrý_den) ~dobrý_den }}} * 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 === adding animations * single animation - via `Animation` box * connect to dialog: * add rule to topic: {{{ u:(["můžeš zamávat" zamávej] {prosím}) ahojky $zamavej=1 }}} * 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) * add `Kisses` animation box, connect it to the `zamavej` output * within the dialog: {{{ u:(~ahoj) ^start(animations/Stand/Gestures/Hey_1) ahoj člověče \pau=1000\ to máme dnes hezký den ^wait(animations/Stand/Gestures/Hey_1) }}} 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] == Pepper API II * tablet: * [http://doc.aldebaran.com/2-5/getting_started/creating_applications/using_peppers_tablet.html Using Pepper’s Tablet] * from a dialogue (see [http://doc.aldebaran.com/2-5/getting_started/creating_applications/using_peppers_tablet.html QiChat - pCall]): {{{ u:(jak se můžu dostat na fakultu bez přijímaček?) Způsobů je celá řada. ^pCall(ALTabletService.showWebview("https://www.fi.muni.cz/admission/guide.html.cs")) Všechno se dozvíš dnes na přednášce, od paní ze studijního ^start(animations/Stand/Gestures/ShowTablet_3) nebo na webu vvv fi muni cz v sekci pro uchazeče. ^wait(animations/Stand/Gestures/ShowTablet_3) }}} * deploy application to the robot * make a ssh key (replace `` with your login): {{{ ssh-keygen -t ecdsa -N '' -f ~/.ssh/pepper_ }}} * copy your '''public''' key to the course directory: {{{ cp ~/.ssh/pepper_.pub /nlp/projekty/pepper/course/keys/ }}} * creating application [http://doc.aldebaran.com/2-5/dev/tutos/create_a_new_service.html outside Choregraphe]