Presentation is loading. Please wait.

Presentation is loading. Please wait.

Make Decisions.

Similar presentations


Presentation on theme: "Make Decisions."— Presentation transcript:

1 Make Decisions

2 Learning Outcomes Understand IR Sensor
Program Edison to detect obstacles and avoid them Control LED’s or generate sound if an obstacle detected Learn the concept of the logic If Statement

3

4 Why IR sensor

5 What is IR sensor IR- Infrared Light : invisible to human eyes
Examples of invisible Lights : Radio Waves X-rays Microwave

6 Did you know? Although humans cannot see IR, some animals can. These animals use infrared to see their prey in all kinds of light, and weather conditions. Some snakes can see the body heat of their victims. This allows them to catch their prey. Piranha fish live in murky water and use IR to locate their prey. Mosquitoes use infrared to find the blood-rich parts of their prey.

7 IR sensor An infrared sensor measures infrared (IR) light radiating heat from objects in its field of view.

8 (1) No obstacle is in front of the sensor.
IR Sensor (1) No obstacle is in front of the sensor. (2) There is an obstacle.

9 Did you know? This is how we see:
A torch shines light into dark places. When the light hits an object, some of the light bounces back to your eyes (sensors) so that you can see the object. If the object is further away, it is harder to see because less light bounces back to your eyes.

10 IR sensors in Edison Note
Edison is equipped with two obstacle sensors so it can detect obstacles in its path and avoid them. Edison emits infrared light from two, light-emitting diodes (LEDs), one on the left and one on the right. In between the two LEDs is an IR sensor. The sensor detects when IR is reflected from an obstacle. If the IR is reflected from the left LED, the obstacle is on the left. If the IR is reflected from the right LED, the obstacle is on the right. With these sensors, Edison can avoid collisions The obstacles need to be the same height (3.5 cm/1.5 in), or taller than Edison, for it to see them. Left light sensor Left infrared sensor Left red LED Right light sensor Right infrared sensor Right red LED

11 IF Statement Activity 1– Page 67 #-------------Setup----------------
import Ed Ed.EdisonVersion = Ed.V2 Ed.DistanceUnits = Ed.CM Ed.Tempo = Ed.TEMPO_MEDIUM # Your code below Ed.ObstacleDetectionBeam(Ed.ON) while True: if Ed.ReadObstacleDetection()== Ed.OBSTACLE_AHEAD: Ed.PlayBeep()

12 Python Comparison Operators
Description == Equal to != Not Equal to Greater than Less than >= Greater than and equal to <= Less than and equal to

13 Four Cases for Obstacles:
IR sensors in Edison Obstacles Four Cases for Obstacles: Obstacle ahead Obstacle to the left Obstacle to the right No obstacle is detected

14 Activity 2– Page 69

15 IF – else Statement Activity 3– Page 70 Ed.LeftLed(Ed.ON)
Ed.RightLed(Ed.ON) else: Ed.LeftLed(Ed.OFF) Ed.RightLed(Ed.OFF)

16 Multiple IF – else Statement
Activity 4– Page 71

17 IF – elif - else Statement
Page 72 while True: Obs = Ed.ReadObstacleDetection() # Read the obstacle sensor if Obs == Ed.OBSTACLE_AHEAD: # Check if the obstacle is ahead # If yes, then do case 1 elif Obs == Ed.OBSTACLE_RIGHT: # If not, check if it is on right # If yes, then do case 2 elif Obs == Ed.OBSTACLE_LEFT: # If not, check if it is on left # If yes, then do case 3 else: # Otherwise, # do case 4

18 Using Variables Page 73 #-------------Setup---------------- import Ed
Ed.EdisonVersion = Ed.V2 Ed.DistanceUnits = Ed.CM Ed.Tempo = Ed.TEMPO_MEDIUM # Your code below Ed.ObstacleDetectionBeam(Ed.ON) while True: Obs = Ed.ReadObstacleDetection() if Obs == Ed.OBSTACLE_AHEAD: Ed.PlayBeep() Ed.LeftLed(Ed.OFF) Ed.RightLed(Ed.OFF) elif Obs == Ed.OBSTACLE_RIGHT: Ed.RightLed(Ed.ON) elif Obs == Ed.OBSTACLE_LEFT: Ed.LeftLed(Ed.ON) else: Ed.TimeWait(200, Ed.TIME_MILLISECONDS) Using Variables Page 73

19 Group Work Page 74 Read exercise page 74 Discuss in your group
Program your Edison Draw a line for your robot while moving Evaluate the program and test

20 Step – by - Step Page 74 #-------------Setup---------------- import Ed
Ed.EdisonVersion = Ed.V2 Ed.DistanceUnits = Ed.CM Ed.Tempo = Ed.TEMPO_MEDIUM # Your code below Ed.ObstacleDetectionBeam(Ed.ON) while True: Obs = Ed.ReadObstacleDetection() if Obs == Ed.OBSTACLE_AHEAD: Ed.Drive(Ed.BACKWARD_RIGHT, Ed.SPEED_5, Ed.DISTANCE_UNLIMITED) elif Obs == Ed.OBSTACLE_RIGHT: Ed.Drive(Ed.FORWARD_LEFT, Ed.SPEED_5, Ed.DISTANCE_UNLIMITED) elif Obs == Ed.OBSTACLE_LEFT: Ed.Drive(Ed.FORWARD_RIGHT, Ed.SPEED_5, Ed.DISTANCE_UNLIMITED) else: Ed.Drive(Ed.FORWARD, Ed.SPEED_5, Ed.DISTANCE_UNLIMITED) Ed.TimeWait(200, Ed.TIME_MILLISECONDS) Step – by - Step Page 74

21 End-of-unit Assessment

22 #-------------Setup----------------
import Ed Ed.EdisonVersion = Ed.V2 Ed.DistanceUnits = Ed.CM Ed.Tempo = Ed.TEMPO_MEDIUM # Your code below Ed.ObstacleDetectionBeam(Ed.ON) while True: Obs = Ed.ReadObstacleDetection() if Obs == Ed.OBSTACLE_AHEAD: Ed.PlayBeep() Ed.LeftLed(Ed.OFF) Ed.RightLed(Ed.OFF) if Obs == Ed.OBSTACLE_RIGHT: Ed.RightLed(Ed.ON) if Obs == Ed.OBSTACLE_LEFT: Ed.LeftLed(Ed.ON) if Obs == Ed.OBSTACLE_NONE: Ed.TimeWait(200, Ed.TIME_MILLISECONDS)


Download ppt "Make Decisions."

Similar presentations


Ads by Google