a1tD0000006jxaUIAQ

Course: Introduction to Programming with NAO
7. Events and Touch Sensors

  • 6-9 grade
  • Beginner

Lesson Description:

Lesson Description:
In this lesson, students will practice event-based programming by programming NAO to tell a story when one of his touch sensors is triggered. 

Objectives

  • Create an event-based program
  • Identify and create programming events
  • Make NAO tell the story when a touch event has been triggered

image description

Lesson Modules


Teaching Tips:

Find the Choregraphe sample program that corresponds to this lesson.
Run the sample program.


Answers:
NAO has the following sensors:
Tactile sensors on the head (3)
Touch button in the chest (1)
Tactile sensors on each hand (left-side, top, right-side) (6)
Bumpers, one on each foot (2)
Cameras (2) that are like human sight
Microphones (4) which are like human hearing
Gyroscope
Infra-red sensors

The following are the touch sensors:
Tactile sensors on the head (3)
Touch button in the chest (1)
Tactile sensors on each hand (left-side, top, right-side) (6)
Bumpers, one on each foot (2)

The most effective touch sensor for the kill switch event is the foot bumper.
It can be triggered either by the user in case of an emergency or by the robot in case it reaches an obstacle while walking.

Other usages for events:
* Start talking only when the robot sees a human face in front of him
* Start / finish a program when a specific touch sensor has been triggered
* Turn the face towards the source of a sound to check what's going on using a camera for example.
* Stop walking if the sonar sensors or the infra red sensors have detected an obstacle
* try to stabilize if the gyroscope has detected a fall

Listen to Nao tell his story then answer the questions.

What did NAO say before starting the story?

What did NAO say before starting the story?What made NAO start telling the story?

When the flow of the program is affected by events such as user input or sensor output,
it is called Event-Driven Programming (or Event Based Programming).

What sensors NAO has? Use the picture below as a reference.
  • Tactile sensors
  • Speakers
  • Chest button
  • Hands with touch sensors
  • Foot bumpers
  • Microphones
  • Eye LEDs
  • Cameras
  • Sonars and Infra Red
  • Gyroscope

Gyroscope inside the body which help the NAO know what his balance is like in the same way you know if you are standing, sitting or falling
Infra-red sensors in the eye for invisible light
Touch button in the chest

Which of the sensors are a touch sensor? Use the picture below as a reference.
  • Tactile sensors
  • Speakers
  • Chest button
  • Hands with touch sensors
  • Foot bumpers
  • Microphones
  • Eye LEDs
  • Cameras
  • Sonars and Infra Red
  • Gyroscope



kill switch is a mechanism used to shut down or disable a program.
The purpose of a kill switch is usually act as an emergency stop in case something goes wrong.

It is always a good idea to implement a kill switch functionality triggered by the user at any given point.


Which one of the touch sensors will be most effective to use for the kill switch event?

Other than the kill switch event, what other usages do you think can be for triggering events in a program?


Teaching Tips:

In order for a box to be triggered either by the left bumper or the right bumper, both output ports of the Bumers box should be connected to the 
Left or Right box.

When multiple Bumpers boxes are connected and active, all of them will be triggered when the connected bumper is pressed in the order they have been activated.

Miltiple Say boxes cannot be triggered at the say time since NAO cannot talk different sentences at the same time. In case more than one Say box is triggered at the same time, only one of them will be executed.

Connecting two Bumper boxes one after another will cause only the first bumper box to be triggered the first time the left bumper is pressed.
Only the second time, both bumper sensors will be triggered at the same time. The reason for this behaviour is that the second Bumper box is waiting for the first bumper to be pressed in order to start listening. Only when it is in the listening mode, it can trigger the connected box (Hello). That will happen only when the left bumper is pressed and the sensor is listening (the second time).

In order to trigger only the Hello box the second time the left bumper is pressed (without running the Say box), the first Bumper sensor needs to be deactivated after it is triggered the first time.
For making the program stop listening after the first sensor is triggered, the bottom left port (stop input) should be activated.


All the touch sensor boxes can be found under the Sensing folder.
For any of the touch sensor boxes the robot will keep listening to the sensors even after the touch has been triggered.


How would you create a kill switch?



Hello Box



The Hello box is one of the pre recorded animations.
Triggering this behaviour will make NAO wave. 

Why Stop listening and How to trigger Done listening box?


2 Bumpers 1 have not yet been activated- explain why it didn't work, and the second time?

Connecting sensors boxes sequentially will result a different behaviour the second time the sensors are triggered from the first time.

Use the picture above as a reference and answer the following questions.

How would you connect a box to the Bumpers sensors if you want it to be triggered with every touch of one of the bumpers. Use the screenshot below as a reference.

Assume the following scenario: Two Bumpers boxes activated at the same time. Each left bumper output port is connected to a different box. One of them is connected to a Say box, the other to the Hello box. What happens if a left bumper has been pressed?
  • Only Say will be triggered
  • Only Hello will be triggered
  • Both Say and Hello boxes will be triggered
  • None of the Say or the Hello boxes will be activated

What do you think will happen if the Hello box is replaced by another Say box? and why? What is going to happen the first time the left bumper is triggered?
  • Nothing will happen
  • The Say box is going to be triggered
  • The Hello box is going to be triggered
  • Both Say and Hello boxes will be triggered at the same time
  • First the Say box will be triggered then the Hello box

What is going to happen the second time the left bumper is triggered?
  • Nothing will happen
  • The Say box is going to be triggered
  • The Hello box is going to be triggered
  • Both Say and Hello boxes will be triggered at the same time
  • First the Say box will be triggered then the Hello box



Teaching Tips:

Student Implementation

Have students work on adding a secret combination using sensors to their story in Choregraphe. When they are finished, they should complete the Reflect! activity. Walk around and check that students are on task and making progress with their stories.



Program a secret combination to activate the story telling


Teaching Tips:

Silent Journaling (5 minutes)
Have students fill out the Reflect! activity. They should work silently for a few minutes.

Group Discussion (5 minutes)
After they have journaled, discuss their responses as a group. 



AFTER CLASS

Store Student Files
Put the student files on a thumb drive or store them in some way so that the students can continue working on their project in the next lesson. 

Pack Up Hardware
Pack the robots and computers according to the packing instructions.

REVISE and REFLECT!

Silent Journaling 
Fill out the Reflect! activity. You should work silently for a few minutes.

What is a kill switch?

What is an event driven programming?


Group Discussion 
After you have journaled, discuss your responses with the group. 




AFTER CLASS


Store Your Files
Store your file(s) on a thumb drive or in some way. Follow your teacher's instruction so that you can continue working on your project in the next lesson. 

Pack Up Hardware
Your teacher will pack the robots and computers according to the packing instructions. Follow your teacher's instruction for packing up the hardware.