Are you interested in designing a simple animation of robots? If so, you're in the right place! In this blog post, we will show you how to create a fun and interactive game of charades using a built-in box library and the touch sensors of a robot. With just a few simple steps, you can build an engaging game that will entertain both kids and adults alike. So, let's get started and learn how to design a simple animation of a robot for playing charades!
First step
We need to create collections of behaviours that NAO will show us, and we'll try to guess what it is.
1. Open a new project in Choregraphe
File > New project
File > Project properties and set Application title.
Our project will have the title animLibrary.
2. Press the '+' button on the left-hand side and choose the option Create behavior.
We will use ready-made animations available in the Box libraries (if you don't see Box libraries you can click View > Box libraries), so our first behaviour has the name elephant, and we use Elephant animations from:
Animations > Entertainment > Animals > NAO
3. You can create as many behaviors as you want. We will show you how to create one more behavior with the name photographer. NAO will pretend to be a photographer, so it will go around and take pictures.
We will use two actions, TakePicture from Animations > Entertainment > Fun > NAO and Move To from Movement > Navigation > Move To. For the action Move To we can set parameters related to the distance and directions of NAO's move.
Also for the action Move To you can connect both outputs (onArrivalAtDestination and onStoppedBeforeArriving) with the input of the next action. In that case, when NAO will not be able to complete the action, due to for instance an obstacle, it will go to the next action and complete animation.
4. As we have all the behaviors, we can upload the animLibrary project to the robot, so it will remember all programmed actions.
- Open the robot application window: View > Robot application
- Connect to NAO
- Click Package and install the current project to the robot
Second step
Now when we have a collection of animations that NAO will show us, we can create game logic.
1. Open a new project in the Choregraphe application and save it
File > New project
File > Save project as
2. We need to decide how the robot will start the game. There are 2 options: NAO can wait for our voice command, or we can use one of NAO's sensors to give it a signal that we want to start. In this case, let's use a sensor placed in the center of the robot's head (MiddleTactilTouched). When we touch the sensor, NAO is going to ask us if we want to play charades.
3. Time for a short explanation of how NAO's sensors work.
If the sensor is not touched, the signal for NAO is 0. If we touch it, the signal changes to 1. The robot reacts to the signal change, no matter if it changes from 0 to 1 or from 1 to 0.
If we connect the sensor with the action Say (look at screenshot 5), NAO will say two times Do you want to play with me charades? - when we touch and stop touching the sensor (because the signal has changed in both cases).
We can easily improve it so NAO will only respond to changes from 0 to 1.
To change it, you should do the following things:
- Add the Python Script box, and put it between the sensor and the Say action.
- Right-click on the Python Script box input and change the type to Number
- Right-click on the Python Script box output, click on Edit output and rename the output name to play
- Double-click on the Python Script box and modify the function onInput_onStart()
- If the signal is equal to 1, the script will propagate the signal to output play and the next action will be executed.
4. After adding Python Script we can prepare the robot to run the game
- Add the box Goto Posture and set the parameter Name to Stand just in case the robot will be in a different posture.
- Add the box Set Language and choose language - we will choose American English because our interaction with the robot will be in English, but you can select a different language.
5. Now we can create a dialogue with NAO
- Add the box Dialog.
- Create a new dialog topic - click '+' on the left-hand side > Create dialog topic
- Rename the Dialog box in the Inspector tab (if you don't see the Inspector tab, you can click View > Inspector) and link the box with the created topic.
6. We will write a simple chat with the robot.
Open a file related to your topic.
In our case, it is Charades_enu.top.
We will use a proposal rule to trigger a specific robot action. Once one proposal is finished, the next proposal can be started by calling ^nextProposal, or we can repeat the same proposal using ^sameProposal.
If you want to create something more complex or see more examples, we attached documentation of the ALDialog module.
Short description of the code:
7. If you need inspiration, here is our Charades_enu.top file. Feel free to test it and modify according to your needs.
Lines 4 and 6
The NAO has just asked us whether we would like to play charades, so our reaction could be yes or no.
Line 8
To run animation, you can call the function run() with Application ID and Animation name.
You can copy the Application ID when you right-click on your animation library (look at Screenshot 9). Or you can find Application ID in the project properties: open animLibrary project, click File > Project properties and find Application ID (look at Screenshot 1)
8. If you want the robot to talk slower (or faster) than usual, you can add parameter rspd before the proposal. The value is expressed as a percentage, so if you set rspd=50 the speed will be 50% of NAO's normal speaking speed.
Hope you had fun playing with NAO. Check out my previous article.