Tutorial - Creating dialog boxes

Modified on Mon, 09 May 2022 at 03:11 PM


This tutorial starts like the Using Dialog topic in Choregraphe tutorial, then goes deeper in masytering Dialog boxes and QiChat scripting.



CONTENT



Hello World

  • Start Choregraphe.
  • Drag the Speech > Speech Settings > Set Language box on the grey area.
  • Click the parameter button and set the language as English.

  • Right click the grey area and choose, in the contextual menu, Create a new Box > Dialog....

  • Click the Add a new topic button, then type a name without spaces, for example: HelloWorld.
  • Click the Add button, then the OK button.

  • Create links as below.

    

  • In the Project content, double click the HelloWorld_enu.top file.
  • The Script editor appears.

  • Type those rules:


u:(Hello) Hello, young Padawan

u:(Good morning) Let's start a wonderful day




Testing on a simulated robot


  • Make sure you are connected on a virtual robot.
  • Click the Play button.
  • In the Dialog panel, enter “Hello” and press Enter.
  • You can see the result both in Dialog panel and in the Robot view.




Testing on a real robot


  • Make sure you are connected on a real robot.
  • Click the Play button.
  • Wait for the signal indicating that the robot is listening:
    • A “bip” sound is played and
    • Eye LEDs become Blue and turn.
  • Say “Hello” :
    • The robot says “hello young padavan”.
    • You can also see the result both in Dialog panel and in the Robot view.




"Hi", "Hello"... in one rule

To make your first rule a little bit more complex, enrich your script:


u:([hi hello wassup]) hello young padawan

u:(["tell me" "give me"] your name) of course, my name is NAO





Connecting QiChat script and animations


  • Add these new rules:

u:(["can you" please] sit down {now}) ok i sit down $sit=1

u:(["can you" please] stand up {now}) ok i stand up $standup=1


    

  • Add two outputs to the Hello world box.
  • one called “sit”,
  • one called “standup”.

Note: here we use Bang type, an easy way to propagate an event.

  • Add two Programming > Time > Wait boxes and connect them to the outputs you have created. 
  • Add and connect a Movement > Posture > Sit Down and a Movement > Posture > Stand Up boxes.




Jumping from one topic to another


  • In a new Project, add an Speech > Speech Settings > Set Language box.
  • Create two different Dialog topic boxes, called Food and Sport with the following content:
topic: ~Food()
language: English 
u:(let's talk about food) OK, guess what I like 
u:^private(do you like fish) yes and sea food too
u:^private(do you like meat) no, I don't
topic: ~Sport()
language: English 
u:(let's talk about sport) OK, guess what sport I like 
u:^private(do you like tennis) no, I can't play tennis
u:^private(do you like yoga) yes, would you like to do yoga with me?
  • Link the tree boxes as follows:


  • Test it.
  • To jump from a topic to another and give it the focus, use the one of their user rules:
  • In our example : “Let’s talk about food” or “Let’s talk about sport”.
  • Once a topic (food or sport) has the focus:
    • all its private user rules are activated,
    • while the private user rules of the other topic are not.



Advanced tips

Sending QiChat variable through box output

Be aware: in QiChat, a variable has no defined type.

Workaround:

  • Use a Bang Output if you are just looking for sending a signal to another box.
  • Use a Dynamic Output, if you want to use the value of the variable in another box; then cast it into the type you want in your box script:
def onInput_dyn(self, p):
    try: 
       p = int(p)
    except ValueError:
       # If p is a string you may have an exception.
       pass

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article