🤖Lesson 2 : Build a character
Aim
The aim of this lesson is to introduce you to the concept of building robot characters using Misty's API calls that allow you to enable Misty's speech, as well as display and vocalize expressions. If you have any questions about the APIs in this lesson you can check out the Display and LED and Speech and NLP sections.
Expressions and Speech
Challenge 1: Eyes to the skies
Imagine that Misty is a robot astronaut visiting Mars and she raised her head to look at the stars, suddenly a UFO flies by. Is it a plane, a helicopter, an alien bird? The first step is to decide how you want Misty to express her reaction, by using the misty.display_image
API you can choose which default expressions Misty should show. In this example we chose 'Terror'. You can find a full list of them here: Image files. Now try out combining the display and movement APIs to build the described sequence.
For more information about the display and its parameters, you can check the Display and LEDsection in Misty Python API. The parameter "alpha" represents the opacity of the image.
Misty' has many other display capabilities which you can uncover by typing the keyword "display". If you want her to display a video or text instead of an image, you can use the same arguments within the parameters.
Challenge 2: I spy with my little eye
Great job! You have built your first robot character sequence, but it's still missing an important human element to really bring your character to life. The misty.speak
API works much in the same way as the Speak block in Blockly and shares many of the same parameters. You can choose what Misty will say, in what language and with which pitch. Misty uses US English by default if nothing else is specified. Let's try inserting the API into the sequence and have Misty tell you what she sees.
Challenge 3: Uh oh!
You can also have Misty emphasize her reaction with one of her vocal expressions by using the misty.play_audio
API. You can find all Misty's default audio in Audio files and if you've uploaded audio files on Misty in Blockly, you can use their names in the parameters. How would you customize it?
As shown in the example below, the first parameter is a string, and it contains the name of the file you want to use, the second is a float and it represents the volume.
Language
Challenge 4: Can you speak my language?
What if your robot astronaut ends lands by accident in a different country and suddenly you need Misty to speak a different language? In the Speak Block the language could be selected from a drop-down list, however in Python you will need to set the language as voice parameter with a string of code. You can find the strings for each language in Languages. Let's try having Misty repeat the previous sequence in Italian or in one of your favorite languages.
Chest LED
Challenge 5: Houston we have a problem
To emphasize your robot character's expressions even more you can use the misty.change_led
API to control the Chest LED. For example you can add a yellow alert light to the previous example to emphasize Misty's terror of seeing the UFO. You can also use the misty.transition_led
API to cycle between different colors.
Challenge 6: E.T go home
Remember how Misty created a disco ball effect in Blockly Lessons? We can adapt the same sequence to create a scenario where your robot astronaut gets sucked up by a colorful beam of light from the UFO.
Challenge 7: Compact your code
Inserting values for each of the color parameters and adding new lines of code can be tiresome, this is where importing libraries can be incredibly helpful. By importing the "random" library you can extract a random number in a range from 0 to 255. in this way yo can randomize the color values, save lines of code and space for the sequence.
With a cleaner code and the ability to randomize your values, you can now generate how many colors you want without creating an enormous code. To do this, you will need to create a loop and insert the random.randrange
function inside your misty.change_led
API as shown in the example below. We can select the range and Misty will do the rest. Amazing isn't it?
Up Next 👇
Last updated