Everyone needs a Misty who can deliver fresh soft drinks!
Last updated
In this project, Misty will be programmed to listen to our favourite drink, and thanks to the NLP understanding it, go straight to the fridge and ask to have it in her amazing tin holder arm.
The first step to create a customized NLP conversation is to program our very unique context.
For the moment this is possible only with Blockly.
In your Misty Studio, click on Programming and then Blockly. From there open Misty's NLP Blockly section and create this context:
Then click on 'Run' and let Misty learn about your drinks choice.
In the Python code, after initializing the variables it's time to build the conversation, the states, the actions and how the flow will go from one to the other.
from mistyPy.Robot import Robotfrom mistyPy.Events import Eventsimport timemisty =Robot("YOUR-ROBOT-IP-ADDRESS")misty.change_led(0, 0, 255)misty.move_head(0, 0, 0)misty.display_image("e_DefaultContent.jpg")#create conversationmisty.create_conversation(name="DeliveryConv", startingState="StartDelivery", overwrite=True)#create statesmisty.create_state(name="StartDelivery", speak="What can I get you to drink?", contexts="['DeliveryContext']", listen=True, noMatchSpeech="Could you please repeat that?", repeatMaxCount=3, startAction="listen", overwrite=True)misty.create_state(name="DeliveryCoca-cola", speak="Affirmative! One Coca-Cola, delivered with robotic precision.", listen=False, noMatchSpeech="could you please repeat that?", repeatMaxCount=3, startAction="ActionCoca-cola", overwrite=True)misty.create_state(name="DeliveryFanta", speak="Excellent choice! Fanta it is! I'll whiz over with that right away.", listen=False, noMatchSpeech="could you please repeat that?", repeatMaxCount=3, startAction="ActionFanta", overwrite=True)misty.create_state(name="DeliverySprite", speak="One Sprite, coming up! No lemon, no lime, just Sprite!", listen=False, noMatchSpeech="could you please repeat that?", repeatMaxCount=3, startAction="ActionSprite", overwrite=True)misty.create_state(name="DeliveryBeer", speak="You got it! One beer, perfectly chilled and ready to enjoy.", listen=False, noMatchSpeech="could you please repeat that?", repeatMaxCount=3, startAction="ActionBeer", overwrite=True)#map statesmisty.map_state(conversation="DeliveryConv", state="StartDelivery", trigger="SpeechHeard", nextState="DeliveryCoca-cola", triggerFilter="coca-cola", reEntry=False, overwrite=True)misty.map_state(conversation="DeliveryConv", state="StartDelivery", trigger="SpeechHeard", nextState="DeliveryFanta", triggerFilter="fanta", reEntry=False, overwrite=True)misty.map_state(conversation="DeliveryConv", state="StartDelivery", trigger="SpeechHeard", nextState="DeliverySprite", triggerFilter="sprite", reEntry=False, overwrite=True)misty.map_state(conversation="DeliveryConv", state="StartDelivery", trigger="SpeechHeard", nextState="DeliveryBeer", triggerFilter="beer", reEntry=False, overwrite=True)#create actionsmisty.create_action(name="ActionCoca-cola", script="LED:255,0,0;IMAGE:coca-cola.png;ARMS:80,40,1000;HEAD:0,0,0,1000;", overwrite=True)misty.create_action(name="ActionFanta", script="LED:255,165,0;IMAGE:fanta.jpg;ARMS:80,40,1000;HEAD:0,0,0,1000;", overwrite=True)misty.create_action(name="ActionSprite", script="LED:0,255,0;IMAGE:sprite.jpg;ARMS:80,40,1000;HEAD:0,0,0,1000;", overwrite=True)misty.create_action(name="ActionBeer", script="LED:255,255,0;IMAGE:beer.jpg;ARMS:80,40,1000;HEAD:0,0,0,1000;", overwrite=True)defpath_to_the_kitchen(): misty.drive_time(0, 50, 4500) time.sleep(5) misty.drive_time(40, 0, 8000) time.sleep(9) misty.drive_time(0, 50, 4500) time.sleep(5) misty.drive_time(40, 0, 10000) time.sleep(11) misty.drive_time(0, -50, 4500) time.sleep(5) misty.drive_time(40, 0, 6000) time.sleep(7) misty.drive_time(0, -50, 4500) time.sleep(5) misty.drive_time(0, 0, 2000) time.sleep(2)defgo_back(): misty.drive_time(0, 50, 4500) time.sleep(5) misty.drive_time(40, 0, 6000) time.sleep(7) misty.drive_time(0, 50, 4500) time.sleep(5) misty.drive_time(40, 0, 10000) time.sleep(11) misty.drive_time(0, -50, 4500) time.sleep(5) misty.drive_time(40, 0, 8000) time.sleep(9) misty.drive_time(0, -50, 4500) time.sleep(5) misty.drive_time(0, 0, 2000) time.sleep(2)defKey_Phrase_Recognized(data):print(data) misty.change_led(0, 255, 0) misty.play_audio("s_PhraseHello.wav") time.sleep(4) misty.start_conversation("DeliveryConv") time.sleep(12)path_to_the_kitchen() misty.move_head(-35, 0, 0) misty.speak("Hey, is there anyone that can put this drink in my arm?") time.sleep(3)go_back()misty.register_event(event_name='KPR_event', event_type=Events.KeyPhraseRecognized, callback_function=Key_Phrase_Recognized, keep_alive=True)misty.keep_alive()
We have also created two functions that represent the path to the fridge in the kitchen and the path to go back to the desk of the user who first asked for Misty's delivery service.
It's possible to trigger the whole system only after saying: "hey Misty!" and she will start listening to your request.
It's also important to import the images that Misty will display to ask for the soft drink like: