Calypso Module 5: Say/Play/Express,
and "Once Is Enough"

Learning Goal: In this module you will make Cozmo speak, play sounds, and express emotions. You'll also learn a new idiom, "Once Is Enough".

Getting Cozmo to Speak

Cozmo can speak to you if you tell him what to say. You do this with the "say" tile, as in the rule below. When you select a "say" tile from the menu, a window pops up where you can type what you want Cozmo to say. Let's try it out. Start a new program in Calypso and program Cozmo to say your name:


Run the program and you'll hear Cozmo saying your name over and over. That's because rules in Calypso run repeatedly, whenever they can (the Second Law). Since the WHEN part of our speech rule is empty, the rule can always run.

When you put the pencil on a "say" tile, the editor shows you what the tile will say. While the pencil is on the tile you can press the yellow "Y" button (or press "Y" on the keyboard) to edit the text. Change the tile to say "<your name> is my friend" and run the program again.

Notice that when Cozmo speaks, the text is displayed in a speech bubble in the world map.

The Once Is Enough Idiom

If we only want Cozmo to speak once, we can use the "Once Is Enough" idiom, shown below:

The "once" tile is satisfied the first time an action is successfully performed since the rule started running. When the "once" tile has been satisfied, the action will not be repeated. Let's try it:


Run the program and notice that as soon as Cozmo speaks, the "once" tile receives a green check mark indicating that it has been satisfied. The action cannot be taken again; that's why the DO side of the rule is dimmed.


Playing Sounds

The "play" tile can be used to play a sound. (The sound comes out of the computer speaker rather than Cozmo, but this may change in the future.) Calypso comes with a set of built-in sound files to choose from. You can also add new sound files of your own.

When you create a new "play" tile, a file browser window pops up, allowing you to choose which sound file to play. If you later put the pencil on the "play" tile, the editor will show you the file name. You can change sound files by putting the pencil on the "play" tile and pressing the yellow "Y" button or the letter "Y" on the keyboard.

Let's try writing a rule to play the "beeprobo" sound:


Just as with "say", because this rule has no "once" tile its action will be performed every time the rule runs.

Playing on Command

Let's use the gamepad to control when Cozmo plays the sound:


Now whenever you press and release the green A button (or hit the "A" key on the keyboard), Cozmo will pay the sound once. But if you keep the button pressed, Cozmo will play the sound over and over. If we only want him to play the sound once for each time the button is pressed, we can use the Once Is Enough idiom. Let's see how this works:


Run this program and look at the rule in the world map display. It's initially dimmed because "WHEN gamepad A-button" is not true. Now press and hold the A-button, and you'll see that the entire rule becomes highlighted and the sound is played. But then the "once" tile becomes satisfied and the DO part of the rule cannot repeat, so a check mark appears on the "once" tile and the DO part is dimmed. The WHEN part is still highlighted because you're still holding down the A button. So the rule "can run", and it is running, but its action is failing.

Now release the A button and see what happens. The WHEN part is dimmed, showing that the rule can no longer run. But when this happens, the green check mark also disappears from the "once" tile. So the next time you press the A button and the rule runs again, the DO action will not fail: Cozmo will play the sound file -- but only once. Try it and see.

Expressing Emotion

Cozmo can express emotions using the "express" tile. He has six emotions: happy, sad, puzzled, frustrated, playful, and energetic. Let's see what a puzzled Cozmo looks like:


Whenever you press the green A button, Cozmo acts puzzled. Notice that his sounds and gestures vary a little bit each time.

Reacting To A Face

Cozmo's vision system can recognize faces as well as cubes. Let's make Cozmo show happiness when he sees a face, and act energetic when he sees a cube. Enter these rules:


Now let's try out the program:

  1. Hide all the cubes.

  2. Run the program, pick up Cozmo, and hold him so he can see your face. Check the image in the camera viewer to be sure he can see you clearly; if the image is too bright or too dark he may have difficulty. Is Cozmo happy to see you?

  3. Hide your face with your hand, then take your hand away. What does Cozmo do?

  4. Put Cozmo down and show him a cube. Does the second rule run?

  5. Hide the cube so Cozmo can't see it. Notice that the cube is still present in the world map, although its position may no longer be correct. But because the cube is still present on the map, the first rule's WHEN part is still true, and the rule can run. Thus, the "once" tile remains satisfied and Cozmo will not act energetic again.

  6. Show Cozmo the same cube again and notice that although its position updates on the world map when he sees the cube, this does not reset the "once" tile. The "express energetic once" action is still failing because the rule never stopped running.

Reacting To A Cube Coming Into View

If we want Cozmo to only pay attention to cubes that are currently in his camera frame, we can tell him to look for cubes that are "in-frame". He will then ignore any cubes that are beside or behind him, or any cubes that are ahead of him on the world map but not actually visible to his camera. Try this rule:


Now if you place your hand in front of the cube to hide it from Cozmo, it remains on the world map but "see cube in-frame" becomes false because he doesn't actually see it. So the rule cannot run, and the "once" tile gets reset. Take your hand away again and the rule will run, and Cozmo will act energetic. Then the "once" tile will become satisfied and Cozmo will go quiet again. Try it and see.

Review and Discovery

Do the Module 5 Review and Discovery activity to review what you've learned.

Next Module

In the next module you'll learn why rules can conflict with each other, and how conflicts are resolved.


Back to Calypso Curriculum overview.


Copyright © 2017 Visionary Machines LLC.