QiChatbot – Mastering Bookmark ¶
- We will see 2 uses for a bookmark:
- how to go to a specific bookmark,
- how to be notified when a bookmark is reached.
Before stepping in this tutorial, you should:
- Know how to use Android resources.
- Be familiar with the Action notion. For further details, see: Running Actions on Pepper.
- Know how to use the QiChatbot. For further details, see: Listen and reply — QiChatbot.
- Know how to use the Animate action. For further details, see: Mimic an animal — Animate.
Let’s start a new project
- Start a new project, let’s call it BookmarksPepper.
- Robotify it and make sure it implements the QiSDK & the Robot Life Cycle.
For further details, see: Creating a robot application.
Creating a topic file¶
Create a new topic file named mimic_animal.top for the English (en) language.
Add the following content to this file:
topic: ~mimic_animal() proposal: %mimic_proposal Say dog or elephant u1: (dog) OK, I've reached the dog bookmark %dog_mimic u1: (elephant) OK, I've reached the elephant bookmark %elephant_mimic
For more details about the syntax, see QiChat - Syntax.
How to go to a bookmark¶
Chat and a
Bookmark in your
To go to a
Bookmark, use the
Add the following method to your
We are using
AutonomousReactionValidity.IMMEDIATE so that the
Chat goes to the
specified bookmark right away.
Create a Topic from the previously created topic file.
Topic, we then create a
QiChatbot and a
Put the following code in the
Retrieve all the bookmarks of the
Topic and extract the
And execute the
sayProposal method when the
Chat action starts:
Do not forget to remove this listener on
Chat in the
With this code, the robot is configured to say the proposal when the
If you run the application, Pepper will say the proposal.
Reacting to a bookmark¶
In this section, we will see how to react when a bookmark is reached. For that, we will use the BookmarkStatus class.
Store these fields in your
onRobotFocusGained method, get the bookmarks corresponding to the
different user answers and create a
BookmarkStatus for each bookmark:
Set a BookmarkStatus.OnReachedListener on each
that we can react when the corresponding bookmark is reached:
Remove these listeners in the
We now want Pepper to perform an animal animation depending on the user answer.
Import both dog_a001 and elephant_a001 animations using the Animation Browser. They are located in Action > Animals.
Create the following methods to perform animations:
Update the code inside the
BookmarkStatus listeners to execute the
Last, we can run the
Bonus: Adding some sound¶
Take advantage of the
Animate.OnStartedListener to start some sound at the
beginning of the animation, using the MediaPlayer class.
Let’s try it¶
The sources for this tutorial are available on GitHub.
Install and run the application.
For further details, see: Running an application.
Choose “Mastering Bookmarks”.
Pepper says the proposal.
Answer “dog” or “elephant”.
Pepper performs the corresponding animation.
The log trace “<animal> mimic.” is also displayed in the console.
You are now able to use bookmarks in a QiChatbot!