def sendPicture(self): ## Ask for recipient if not self.isAvailable(self.recipient_id): self.recipient_full = self.sp.dialog(self.__class__.__name__, self.recipient_options, checkValidity=True, askForConfirmation=True, noisy=self.asr) self.recipient_id = self.getIDFromAttribute(self.recipient_params, "full", self.recipient_full) else: self.recipient_full = self.getAttributeFromID(self.recipient_params, self.recipient_id, "full") self.sp.monolog(self.__class__.__name__, "with-keyword", param={"$KEYWORD$" : self.recipient_full}, group="parameter-answer", tag=speech.TAGS[1]) ## Ask for the way to send the picture telegram_id = self.getAttributeFromID(self.recipient_params, self.recipient_id, TELEGRAM) line_id = self.getAttributeFromID(self.recipient_params, self.recipient_id, LINE) email_id = self.getAttributeFromID(self.recipient_params, self.recipient_id, EMAIL) sending_ways = [sw[0] for sw in [[TELEGRAM, telegram_id], [EMAIL, email_id]] if not sw[1] == ""] if len(sending_ways) == 1: send_via = sending_ways[0] else: self.choice = mlt.MultiPageChoiceManager(caressestools.Settings.robotIP.encode('utf-8')) self.sp.monolog(self.__class__.__name__, "9", param={"$RECIPIENT$": self.recipient_full}, tag=speech.TAGS[1]) if self.sp._input==2: self.sp.gothread = True thr = threading.Thread(name="getinput", target=self.sp.getOptionsFromSmartphone, args=[sending_ways]) thr.start() send_via = self.choice.giveChoiceMultiPage(self.choice_mode, sending_ways) self.sp.gothread=False send_via = [unicode(send_via[0], "utf-8"), send_via[1]] self.choice.kill() self.sp.checkIfKilledDuringMcm(self.choice, send_via) send_via = send_via[0] self.recipient_send_id = self.getAttributeFromID(self.recipient_params, self.recipient_id, send_via) pic = self.path_take % caressestools.DEF_IMG_APP pic = pic + self.pic_file_name + "." + self.extension email_object = self.sp.script[self.__class__.__name__]["settings"]["email-object"][self.language].replace("$USERNAME$", self.username) message = self.sp.script[self.__class__.__name__]["settings"]["message"][self.language].replace("$USERNAME$", self.username).replace("$RECIPIENT$", self.recipient_full) ## Insert data in memory [email_object, sender_mail, sender_password, smtp, recipient_address(telegram or line or email), message, pic_path] data = [email_object, self.address, self.password, self.smtp, self.recipient_send_id, message, pic] self.sMemory.insertData("CARESSES_send_pic", data) if not self.sBehavior.isBehaviorRunning(self.behaviors[send_via]): self.sBehavior.startBehavior(self.behaviors[send_via]) self.sp.monolog(self.__class__.__name__, "11", param={"$RECIPIENT$": self.recipient_full}, tag=speech.TAGS[1]) self.recipient_id = '"n/a"'
def run(self): self.sp.monolog(self.__class__.__name__, "0", tag=speech.TAGS[1]) caressestools.setAutonomousAbilities(self.session, False, False, False, False, False) self.sPosture.goToPosture("Stand", 0.5) if not self.sBehavior.isBehaviorRunning( "User/follow-me-no-security-avatarion"): self.sBehavior.startBehavior( "User/follow-me-no-security-avatarion") question = self.sp.script[self.__class__.__name__]["other"]["2"][ self.language].encode('utf-8') options = [ self.sp.script[self.__class__.__name__]["user"]["0"][ self.language].encode('utf-8') ] self.choice = mlt.MultiPageChoiceManager( caressestools.Settings.robotIP.encode('utf-8')) if self.sp._input == 2: self.sp.gothread = True thr = threading.Thread(name="getinput", target=self.sp.getOptionsFromSmartphone, args=[options]) thr.start() answer = self.choice.giveChoiceMultiPage(question, options, timer=1200, exitOnTouch=False) self.sp.gothread = False answer = [unicode(answer[0], "utf-8"), answer[1]] self.choice.kill() self.sp.checkIfKilledDuringMcm(self.choice, answer, self.end) self.sp.monolog(self.__class__.__name__, "1", tag=speech.TAGS[1]) self.end() self.sp.askYesOrNoQuestion( self.sp.script[self.__class__.__name__]["evaluation"]["0"][ self.language].encode('utf-8'), speech.TAGS[3], noisy=self.asr) self.sp.monolog(self.__class__.__name__, "1", group="evaluation", tag=speech.TAGS[1])
def run(self): self.sp.monolog(self.__class__.__name__, "0", tag=speech.TAGS[1]) caressestools.setAutonomousAbilities(self.session, False, False, False, False, False) self.sPosture.goToPosture("Stand", 0.5) if not self.sBehavior.isBehaviorRunning("User/follow-me-no-security-avatarion"): self.sBehavior.startBehavior("User/follow-me-no-security-avatarion") question = "" nodes = Graph.nodes options = [x.getLabel() for x in Graph.nodes if not x.getLabel().startswith("node")] self.choice = mlt.MultiPageChoiceManager(caressestools.Settings.robotIP.encode('utf-8')) if self.sp._input==2: self.sp.gothread = True thr = threading.Thread(name="getinput", target=self.sp.getOptionsFromSmartphone, args=[options]) thr.start() answer = self.choice.giveChoiceMultiPage(question, options, timer=1200, exitOnTouch=False) self.sp.gothread=False answer = [unicode(answer[0], "utf-8"), answer[1]] self.choice.kill() self.sp.checkIfKilledDuringMcm(self.choice, answer, self.end) node = findNodeFromLabel(answer[0]) position = self.sMotion.getRobotPosition(True) self.sMemory.insertData("CARESSES_fixedPose", [node.x * self.file.k, node.y * self.file.k, math.radians(node.th)]) self.logger.info("Storing the following pose as node '%s': (%g, %g, %g) ==> (%g, %g, 0)" % (answer, position[0], position[1], position[2], node.x, node.y)) self.sp.monolog(self.__class__.__name__, "1", tag=speech.TAGS[1]) self.end()
def run(self): if not self.isAvailable(self.item_id): self.item_full = self.sp.dialog(self.topic_item, self.items_options, checkValidity=True, askForConfirmation=False) self.item_id = self.getIDFromAttribute(self.items_params, "full", self.item_full) else: self.item_full = self.getAttributeFromID(self.items_params, self.item_id, "full") self.sp.monolog(self.topic_item, speech.WITH_KEYWORD, param={"$KEYWORD$": self.item_full}, group="parameter-answer") if not self.isAvailable(self.room): room_options = [r.encode('utf-8') for r in self.items_params["IDs"][self.item_id]["locations"]] if len(room_options) == 1: self.room = room_options[0] else: self.room = self.sp.dialog(self.topic_room, room_options, checkValidity=True, askForConfirmation=False) get_ihouse_error = False try: current_val, status_str = self.getDeviceStatus(self.item_id, self.room) except: get_ihouse_error = True error = self.sp.script[self.topic_item]["other"]["4"][self.language] self.sp.say(error) return # raise Exception, "No answer from iHouse..." finally: if get_ihouse_error: self.sp.askYesOrNoQuestion( self.sp.script[self.__class__.__name__]["evaluation"]["0"][self.language].encode('utf-8')) self.sp.say(self.sp.script[self.__class__.__name__]["evaluation"]["1"][self.language].encode('utf-8')) if not self.isAvailable(self.operation): available_operations = [self.items_params["IDs"][self.item_id]["operations"][op].encode('utf-8') for op in self.items_params["IDs"][self.item_id]["operations"].keys() if not op == status_str] ## 1 - by automatically choosing the single possible one if len(available_operations) == 1: operation_str = available_operations[0] question = self.sp.script[self.topic_item]["other"]["3"][self.language].replace("$DEVICE$", self.item_full).replace( "$STATUS$", status_str).replace("$ACTION$", operation_str).replace("$ROOM$", self.room) answer = self.sp.askYesOrNoQuestion(question) ## 2 - or by proposing all of the possible ones except for the one which would leave unchanged the status of the device else: choice = mlt.MultiPageChoiceManager(caressestools.Settings.robotIP.encode('utf-8')) import time time.sleep(3) question = self.sp.script[self.topic_item]["other"]["0"][self.language].replace("$DEVICE$", self.item_full).replace("$STATUS$", status_str) self.sp.say(question) operation_str = choice.giveChoiceMultiPage(self.item_full, available_operations)[0] self.sp.playLine(self.sp.USER, operation_str) choice.kill() answer = True for k in self.items_params["IDs"][self.item_id]["operations"].keys(): if self.items_params["IDs"][self.item_id]["operations"][k].encode('utf-8') == operation_str: self.operation = k break ## ... or from apar else: operation_str = self.items_params["IDs"][self.item_id]["operations"][self.operation] ## If the requested operation has no effect on the device, stop the action if self.operation == status_str: self.sp.monolog(self.topic_item, "1", param={"$DEVICE$": self.item_full, "$STATUS$": status_str}) self.stop() return ## Otherwise execute it else: operation_str = self.items_params["IDs"][self.item_id]["operations"][self.operation] question = self.sp.script[self.topic_item]["other"]["3"][self.language].replace("$DEVICE$", self.item_full).replace( "$STATUS$", status_str).replace("$ACTION$", operation_str).replace("$ROOM$", self.room) # answer = self.sp.askYesOrNoQuestion(question) answer = True if answer: success = False try: success = self.setDeviceStatus(self.item_id, self.room, self.operation, current_val) except: error = self.sp.script[self.topic_item]["other"]["4"][self.language] self.sp.say(error) return # raise Exception, "No answer from iHouse..." finally: if success: self.sp.monolog(self.topic_item, "2") self.sp.askYesOrNoQuestion( self.sp.script[self.__class__.__name__]["evaluation"]["0"][self.language].encode('utf-8')) self.sp.say(self.sp.script[self.__class__.__name__]["evaluation"]["1"][self.language].encode('utf-8')) else: self.sp.replyAffirmative()
def run(self): if len(self.recipient_options) == 0: self.sp.monolog(self.__class__.__name__, "4", tag=speech.TAGS[1]) return if not self.isAvailable(self.recipient_id): self.recipient_full = self.sp.dialog( self.__class__.__name__, self.recipient_options, checkValidity=True, askForConfirmation=True, useChoiceManagerFromStart=True, noisy=self.asr) self.recipient_id = self.getIDFromAttribute( self.recipient_params, "full", self.recipient_full) else: self.recipient_full = self.getAttributeFromID( self.recipient_params, self.recipient_id, "full") self.sp.monolog(self.__class__.__name__, "with-keyword", param={"$KEYWORD$": self.recipient_full}, group="parameter-answer", tag=speech.TAGS[1]) if self.recipient_id == "caregiver": self.msg_options = self.msg_options_caregiver else: self.msg_options = self.msg_options_other self.mcm = mcm.MultiPageChoiceManager( caressestools.Settings.robotIP.encode('utf-8')) if not self.isAvailable(self.message_id): self.sp.monolog(self.__class__.__name__, "0", tag=speech.TAGS[1]) if self.sp._input == 2: self.sp.gothread = True thr = threading.Thread(name="getinput", target=self.sp.getOptionsFromSmartphone, args=[self.msg_options]) thr.start() self.message_full = self.mcm.giveChoiceMultiPage( "", self.msg_options) self.sp.gothread = False self.message_full = [ unicode(self.message_full[0], "utf-8"), self.message_full[1] ] self.mcm.kill() self.sp.checkIfKilledDuringMcm(self.mcm, self.message_full) self.message_id = self.getIDFromAttribute(self.msg_params, "full", self.message_full[0]) self.recipient_line = self.getAttributeFromID(self.recipient_params, self.recipient_id, "line") self.message = self.getAttributeFromID(self.msg_params, self.message_id, "message") if self.message_id == "customMessage": correct = False content = "" while not correct: self.sASR.startReco(caressestools.Language.lang_naoqi, False, True) self.sp.monolog(self.__class__.__name__, "3", tag=speech.TAGS[5]) content = self.sp.getInput() self.sp.userSaid(content) self.sASR.stopReco() question = self.sp.script[self.__class__.__name__][ "ask-confirmation"]["without-keyword"][ self.language].replace("$CONFIRM$", content) correct = self.sp.askYesOrNoQuestion(question, speech.TAGS[2], noisy=self.asr) self.message = self.message.replace("$CONTENT$", content) self.sp.replyAffirmative() result = self.sendMessage( self.recipient_line, self.message.replace("$USERNAME$", self.username)) if result == 'OK': self.sp.monolog(self.__class__.__name__, "1", param={"$RECIPIENT$": self.recipient_full}, tag=speech.TAGS[1]) self.sp.askYesOrNoQuestion( self.sp.script[self.__class__.__name__]["evaluation"]["0"][ self.language].encode('utf-8'), speech.TAGS[3], noisy=self.asr) self.sp.monolog(self.__class__.__name__, "1", group="evaluation", tag=speech.TAGS[1]) else: self.sp.monolog(self.__class__.__name__, "2", tag=speech.TAGS[1])
def run(self): if self.sBehavior.isBehaviorRunning("caresses_game_memory/behavior_1"): self.sBehavior.stopBehavior("caresses_game_memory/behavior_1") self.sBehavior.startBehavior("caresses_game_memory/behavior_1") self.sp.monolog(self.__class__.__name__, "0", tag=speech.TAGS[1]) while self.again and not self.is_stopped: if not self.isAvailable(self.topic_id): self.topic_full = self.sp.dialog(self.__class__.__name__, self.topic_options, checkValidity=True, askForConfirmation=False, noisy=self.asr) self.topic_id = self.getIDFromAttribute(self.topic_params, "full", self.topic_full) else: self.topic_full = self.getAttributeFromID(self.topic_params, self.topic_id, "full") self.sp.monolog(self.__class__.__name__, "with-keyword", param={"$KEYWORD$" : self.topic_full}, group="parameter-answer", tag=speech.TAGS[1]) self.sMemory.raiseEvent("CARESSES/game_memory/topic", self.topic_id) self.sp.monolog(self.__class__.__name__, "1", tag=speech.TAGS[1]) self.sp.askYesOrNoQuestion(self.sp.script[self.__class__.__name__][speech.OTHER]["2"][self.language].encode('utf-8'), speech.TAGS[4], noisy=self.asr) imgs_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "NAOqi_apps", "game_memory_APP", "CARESSES Game Memory", "html", "images", self.topic_id) imgs = os.listdir(imgs_folder) index = randint(1, len(imgs)) index = str(index).zfill(2) self.sMemory.raiseEvent("CARESSES/game_memory/show", index) while self.sBehavior.isBehaviorRunning("caresses_game_memory/behavior_1"): pass self.mcm = mcm.MultiPageChoiceManager(caressestools.Settings.robotIP) memorygames_conf = os.path.join(os.path.dirname(os.path.realpath(__file__)), "aux_files", "memorygames-conf.json") with open(memorygames_conf) as f: content = json.load(f) num_of_questions = len(content["pictures"][self.topic_id][index]) for q in range(1, num_of_questions + 1): question = content["pictures"][self.topic_id][index][str(q)]["question"][self.language].encode('utf-8') question_tablet = content["pictures"][self.topic_id][index][str(q)]["question-tablet"][self.language].encode('utf-8') options = [o.encode('utf-8') for o in content["pictures"][self.topic_id][index][str(q)]["answers"][self.language]] correct_answer = content["pictures"][self.topic_id][index][str(q)]["correct-answer"][self.language] options = [o for o in options] self.sp.say(question) if self.sp._input==2: self.sp.gothread = True thr = threading.Thread(name="getinput", target=self.sp.getOptionsFromSmartphone, args=[options]) thr.start() answer = self.mcm.giveChoiceMultiPage(question_tablet, options) self.sp.gothread=False answer = [unicode(answer[0], "utf-8"), answer[1]] self.sp.checkIfKilledDuringMcm(self.mcm, answer, self.end) while not answer[0].lower() == correct_answer.lower(): self.sp.monolog(self.__class__.__name__, "5", tag=speech.TAGS[1]) self.sp.say(question, speech.TAGS[4]) if self.sp._input==2: self.sp.gothread = True thr = threading.Thread(name="getinput", target=self.sp.getOptionsFromSmartphone, args=[options]) thr.start() answer = self.mcm.giveChoiceMultiPage(question_tablet, options) self.sp.gothread=False answer = [unicode(answer[0], "utf-8"), answer[1]] self.sp.checkIfKilledDuringMcm(self.mcm, answer, self.end) self.sp.monolog(self.__class__.__name__, "4", tag=speech.TAGS[1]) caressestools.showImg(self.session, caressestools.TABLET_IMG_EXECUTION) self.sBehavior.stopBehavior("caresses_game_memory/behavior_1") self.sBehavior.startBehavior("caresses_game_memory/behavior_1") question = self.sp.script[self.__class__.__name__][speech.OTHER]["6"][self.language].encode('utf-8') self.again = self.sp.askYesOrNoQuestion(question, speech.TAGS[11], noisy=self.asr) if self.again: self.topic_id = '"n/a"' else: self.sp.replyAffirmative() self.sp.monolog(self.__class__.__name__, "3", tag=speech.TAGS[1]) self.sp.askYesOrNoQuestion( self.sp.script[self.__class__.__name__]["evaluation"]["0"][self.language].encode('utf-8'), speech.TAGS[3], noisy=self.asr) self.sp.monolog(self.__class__.__name__, "1", group="evaluation", tag=speech.TAGS[1]) self.end()
def run(self): choice_ready = self.sp.script[self.__class__.__name__][speech.OTHER]["1"][self.language].encode('utf-8') line_send = self.sp.script[self.__class__.__name__][speech.OTHER]["5"][self.language].encode('utf-8') line_another = self.sp.script[self.__class__.__name__][speech.OTHER]["6"][self.language].encode('utf-8') choice_keep_delete = self.sp.script[self.__class__.__name__][speech.OTHER]["8"][self.language].encode('utf-8') self.choice_mode = self.sp.script[self.__class__.__name__][speech.OTHER]["10"][self.language].encode('utf-8') option_ready = [o.encode('utf-8') for o in self.sp.script[self.__class__.__name__][speech.USER]["0"][self.language]] options_keep_del = [self.sp.script[self.__class__.__name__][speech.USER]["keep"][self.language][0].encode('utf-8'), self.sp.script[self.__class__.__name__][speech.USER]["delete"][self.language][0].encode( 'utf-8')] keywords_keep = [o.encode('utf-8') for o in self.sp.script[self.__class__.__name__][speech.USER]["keep"][self.language]] keywords_del = [o.encode('utf-8') for o in self.sp.script[self.__class__.__name__][speech.USER]["delete"][self.language]] take_another = True while take_another and not self.is_stopped: self.choice = mlt.MultiPageChoiceManager(caressestools.Settings.robotIP.encode('utf-8')) self.sp.monolog(self.__class__.__name__, "0", tag=speech.TAGS[1]) caressestools.setAutonomousAbilities(self.session, False, False, False, False, False) self.sPosture.goToPosture("Stand", 0.5) self.sPhoto.setResolution(3) # 1280*960px (reference at http://doc.aldebaran.com/2-5/family/pepper_technical/video_2D_pep_v18a.html#cameraresolution-ov5640) self.sPhoto.setPictureFormat(self.extension) if self.sp._input==2: self.sp.gothread = True thr = threading.Thread(name="getinput", target=self.sp.getOptionsFromSmartphone, args=[option_ready]) thr.start() answer = self.choice.giveChoiceMultiPage(choice_ready, option_ready) self.sp.gothread=False answer = [unicode(answer[0], "utf-8"), answer[1]] self.choice.kill() self.sp.checkIfKilledDuringMcm(self.choice, answer) self.sp.monolog(self.__class__.__name__, "2", tag=speech.TAGS[1]) self.sBehavior.startBehavior(self.behaviors["shutter"]) ## Take picture self.pic_file_name = "img_%s" % datetime.datetime.now().strftime("%Y%m%d_%H%M%S") self.sPhoto.takePicture(self.path_take % caressestools.DEF_IMG_APP, self.pic_file_name) pic_path = self.path_show % (caressestools.Settings.robotIP, caressestools.DEF_IMG_APP, self.pic_file_name + "." + self.extension) ## Show picture self.sTablet.preLoadImage(pic_path) self.sp.monolog(self.__class__.__name__, "3", tag=speech.TAGS[1]) self.sTablet.showImage(pic_path) ## Keep or delete picture time.sleep(3) caressestools.setAutonomousAbilities(self.session, False, True, True, True, True) self.sp.monolog(self.__class__.__name__, "4", tag=speech.TAGS[4]) self.sASR.startReco(caressestools.Language.lang_naoqi, False, True) user_input = self.sp.getInput() if user_input is None: user_input = "" self.sp.userSaid(user_input) not_understood = True self.sASR.stopReco() while not_understood and not self.is_stopped: if any(unicode(keyword, "utf-8") in user_input.lower() for keyword in keywords_keep): if not len(self.recipient_options) == 0: send =self.sp.askYesOrNoQuestion(line_send, speech.TAGS[4], noisy=self.asr) if send: self.sendPicture() take_another = self.sp.askYesOrNoQuestion(line_another, speech.TAGS[11], noisy=self.asr) not_understood = False elif any(unicode(keyword, "utf-8") in user_input.lower() for keyword in keywords_del): pic = self.path_take % caressestools.DEF_IMG_APP pic = pic + self.pic_file_name + "." + self.extension self.delPicture(pic) take_another = self.sp.askYesOrNoQuestion(line_another, speech.TAGS[11], noisy=self.asr) not_understood = False else: self.choice = mlt.MultiPageChoiceManager(caressestools.Settings.robotIP.encode('utf-8')) self.sp.say(self.sp.script[speech.ADDITIONAL][speech.MISSED_ANSWER][self.language].encode('utf-8'), speech.TAGS[0]) self.sp.monolog(self.__class__.__name__, "7", tag=speech.TAGS[4]) if self.sp._input==2: self.sp.gothread = True thr = threading.Thread(name="getinput", target=self.sp.getOptionsFromSmartphone, args=[options_keep_del]) thr.start() user_input = self.choice.giveChoiceMultiPage(choice_keep_delete, options_keep_del) self.sp.gothread=False user_input = [unicode(user_input[0], "utf-8"), user_input[1]] self.choice.kill() self.sp.checkIfKilledDuringMcm(self.choice, user_input) user_input = user_input[0] caressestools.showImg(self.session, caressestools.TABLET_IMG_EXECUTION) if not self.is_stopped: self.sp.replyAffirmative() self.sp.askYesOrNoQuestion( self.sp.script[self.__class__.__name__]["evaluation"]["0"][self.language].encode('utf-8'), speech.TAGS[3], noisy=self.asr) self.sp.monolog(self.__class__.__name__, "1", group="evaluation", tag=speech.TAGS[1])