a1tD0000003mEHwIAM

Course: Graphical and Python programming using NAO
1: Hello World

  • 9-12 grade
  • Intermediate

Lesson Description:

In this lesson, students will learn basic concepts of programming: 

  1. Programming function
  2. Input / Output
  3. Variable / Parameters
To illustrate these concepts we will program the NAO robot to talk!

Objective:
Apply basic programming concepts to make NAO speak using :
The graphical interface ( beginners) and Python ( advanced). 


 

Standards Covered

CCSS.ELA-LITERACY.RST.11-12.10

By the end of grade 12, read and comprehend science/technical texts in the grades 11-CCR text complexity band independently and proficiently.

CCSS.ELA-LITERACY.RST.11-12.3

Follow precisely a complex multistep procedure when carrying out experiments, taking measurements, or performing technical tasks; analyze the specific results based on explanations in the text.

CCSS.ELA-LITERACY.RST.11-12.8

Evaluate the hypotheses, data, analysis, and conclusions in a science or technical text, verifying the data when possible and corroborating or challenging conclusions with other sources of information.

CCSS.ELA-LITERACY.RST.11-12.9

Synthesize information from a range of sources (e.g., texts, experiments, simulations) into a coherent understanding of a process, phenomenon, or concept, resolving conflicting information when possible.

CCSS.ELA-LITERACY.RST.9-10.3

Follow precisely a complex multistep procedure when carrying out experiments, taking measurements, or performing technical tasks, attending to special cases or exceptions defined in the text.

NGSS Practice 1

Asking questions and defining problems

NGSS Practice 6

Constructing explanations and designing solutions

image description

Lesson Modules


Teaching Tips:

Lesson Plan
Hello World
 
 
Objective:  In this module, students will learn:

  • What's a function and its Choregraphe equivalent: a box
  • What's an input and output
  • What's a parameter to a programming function?
  • What's a variable

Key Vocabulary:  Choregraphe, Say Box, Parameter, Variable, Function Method, Input, Output

 
Materials Needed:  Choregraphe, NAO robot, Internet Connection (wired or wireless)
 

Introduction to programming

We will introduce the basic programming concepts using the NAO robot to illustrate them

The concepts are:

  1. Function
  2. Input/ Output
  3. Variable and Parameter

By the end of this lesson, you will be able to make your robot say something. 

Step 1: The definitions 

  • In programming, a function is a named section of a program that performs a specific task. In this sense, a function is a type of procedure or routine. 
    • Based on the definition above, can you think of functions in your life ? Give an example. 
  • An input is a piece of data message sent to a function. An output is a piece of data returned by the function.   
    • Can you think of an input and output in your life?
  • variable is a value that can change, depending on conditions or on information passed to the program.
    • What's the variable in our example?

Teaching Tips:

This lesson is an introduction to the concept of Input and Output. This is the first concept that is taught in an Introduction to Computer Science course.

Question : what's the Output of our code or behavior? 

Answer: The output is the robot saying " Hello ".

 Advanced tips ( Python) or refer to module 5:

(Draw or insert slide on modules and API)

self.tts = ALProxy('ALTextToSpeech')

 self.tts.post.say(str(sentence))

Generic concept and form of an Input and Output

Output = Function (Input)

 

Basic Task: Say "Hello"
 
Next, we will program the NAO to say “Hello.” The NAO uses a text-to-speech engine to convert text into sound, which is output through the speakers.
 
  1. In Choregraphe, look at the “Box List” to the left. Navigate to Audio -> Voice, then drag and drop a “Say” box to the central area. This central area is called the workspace, and contains the commands that the robot executes.

  2. To execute the “Say” box, we must connect it to the program “flow”. Click on the small arrow to the left of the workspace, and drag a line to the arrow on the left of the “Say” box. The boxes will be executed sequentially in the order that they are connected. The last box should connect to global stop [x] on the right hand side of the work area.
  3. Finally, click the green “Play” button next to the “Connect” button. The NAO should say “Hello.”

Teaching Tips:

This lesson is an introduction to the concepts of Input and Output. This is the first concept that is taught in an Introduction to Computer Science.

A question you can ask your students to start a discussion:

Outside of programming or robot world, what's an input and what's an output? Tip : example a discussion: you can listen( take an input) and answer ( giving your output), and your brain is the function! 

In our code or behavior what's the input ( Hello World) , what's the output ( robot speaking) what's the function ( the code and the box "Say") ? 


 Advanced tips ( Python) or refer to module 5:

(Draw or insert slide on modules and API)

self.tts = ALProxy('ALTextToSpeech')

 self.tts.post.say(str(sentence))

Generic concept and form of an Input and Output

Output = Function (Input)

Intermediate Task: Say Anything!
 
We will learn how to change the words the NAO says to “Hello world.”
 

1. Beginning with the results of the previous task, double-click on the “Say” box.



 
2. A “Localized Text", will appear connected to a “Say Text” box. To return to the previous screen, click “root” on the upper box hierarchy “breadcrumb trail”.




3. Replace the “Hello” in the text box with “Hello World!”.


 

4. Click the play button, and listen to what the NAO says.

5. Try experimenting with different words and phrases.


Teaching Tips:

In order to personalize your code, you can modify the way the robot talks. This is helpful when you want to differentiate between characters in a story.

You can talk about the pitch of the voice (usually lower represents more male and higher more female) and the speed of the speech.  

A question to spark a discussion with students:

How would you make your robot sound more like you (a male or female human)?

 

Intermediate Task: Voice Acting

This module introduces the concept of Variable and Parameters
 
The NAO can speak faster, slower, lower or higher, depending on two parameters, “Voice Shaping” and “Speed”.
 
1. Click on the wrench in the bottom left corner of the “Say” box. 


 

2. The window below will appear:


 

3. Move the two sliders to a different position and click OK. Press the play button for the NAO to speak again.

4. What changed? Try experimenting with different values for each of the sliders. What do the two parameters control?
 


Teaching Tips:

 

Advanced Task: Speak with Python
 
In addition to dragging and dropping boxes in Choregraphe, the NAO can be programmed using several programming languages including C++ and Python. We will be using Python for our exercise. Documentation about programming in C++ is available online.
 
We will begin with a simple programming exercise in Python. We will have the robot say “Hello World” exactly as we did before with the Choregraphe Say box. We will do this by creating our own box in Choregraphe that executes our python code.
 
1. First, open an empty workspace in Choregraphe by creating a new project.


2. Right-click on the workspace, and choose “Create a new box” from the menu.




3. A dialog will appear. In the “Name” box, enter “Python Say”, and in the tooltip box, enter a description of what your box will do. Do not change any of the other options. 




4. Click the “Edit” button in the “Image” section. A new dialog box will appear. 




5. Click the first “Browse” button and select the image “say.png”. This image will be displayed in the newly created box.


6. Click “OK” on both of the dialog windows. Your new box will appear in the workspace with the icon you selected. 


 

7. Double click on the box to open the Script Editor. The Script Editor shows the Python code that is executed by your box.




8. Look for the line that says “def onInput_onStart(self):”. This line is the definition for a function (or method) named onInput_onStart. A function is a procedure which can be called elsewhere in the code. In this particular case, the onInput_onStart method is called when the box begins executing, and the indented code below this line is called. We will modify the code below this line to make the robot speak. 


9. Replacepass in the onInput_onStart method with the following two lines of code, as in the picture below:
     ttsProxy = ALProxy(“ALTextToSpeech”)
     ttsProxy.say(“Hello world!”)
 



Note that in Python, the amount of whitespace (spaces and tabs) at the beginning of a line matter. Be sure to put the exact same combination of tabs and spaces on both of these lines (double the amount of whitespace of the line beginning with def).

The first line creates an object that gives us access to the robot’s text-to-speech capabilities. This object is assigned to the variable
ttsProxy. We can access this object later through the name ttsProxy.

The second line calls a different function,
say, belonging to the object we just created. This function takes an argument, “Hello world!”. “Hello world!” is a string, or a sequence of characters, denoted by the double quote marks. The robot will speak the string that was passed to the say method aloud.


10 Close the script editor window, and link your Python box to the start arrow. 

11. Connect to the robot and press the play button. The robot should say “Hello world!” aloud. 
 


Teaching Tips:


Additional Exercises
 

  1. Have the NAO introduce itself and greet the class.
  2. Have the NAO play the parts of multiple characters in a play by using different voices for each character.
  3. Have the NAO sing the alphabet by varying the voice shaping and pitch that it pronounces each letter with.

 
 
 


Teaching Tips:

Solutions
 
Basic:

  1. How can you tell if the robot is charging?
    The light on the charger should be red.

     
  2. How should you place the robot when turning it on?
    Sitting upright with its feet flat on the floor.

     
  3. How should the robot be held?
    With both hands around its chest.

     
  4. How is the order the Choregraphe boxes execute determined?
    They execute in the order they are connected with arrows.

 
Intermediate:

  1. What does the voice shaping parameter for the Say box control?
    The tone and pitch of the voice.

     
  2. What does the speed parameter for the Say box control?
    How slow or fast the robot speaks.

 
Advanced:

  1. Name two programming languages that can be used on the NAO.
    C++ and Python.

     
  2. How can the NAO be programmed in Python using Choregraphe?
    Right-click to create a new box, set the name, description and picture, and click ok. Double-click on the box to edit the python code.

     
  3. What is a variable?
    A symbolic name assigned to a value which can be modified.

     
  4. What is a function or method in programming?
    A section of code that performs an operation, and can be called by name elsewhere in the code.

     
  5. What is a function argument?
    An input to a function, which can be used within.

     
  6. Do the number of spaces and tabs matter in python?
    Yes, the spacing at the beginning of a line denotes scope.

Questions
 
Basic:

How can you tell if the robot is charging?

How should you place the robot when turning it on?

How should the robot be held?

How is the order that- the Choregraphe boxes execute determined?

 
Intermediate:

What does the voice shaping parameter for the Say box control?

What does the speed parameter for the Say box control?

 
Advanced:

Name two programming languages that can be used on the NAO.

How can the NAO be programmed in Python using Choregraphe?

What is a variable?

What is a function or method in programming?

What is a function argument?

Do the number of spaces and tabs matter in python?