Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using the sensor Lesson 5.

Similar presentations


Presentation on theme: "Using the sensor Lesson 5."— Presentation transcript:

1 Using the sensor Lesson 5

2 What do you think this program will do?
Starter What do you think this program will do?

3 Objective of the lesson
Use the distance sensor attached to Edbot All of you will: Use a forever block, if block and the distance sensor to make Edbot react if something is close by. Most of you will: Write a program to help Edbot navigate as it moves around the classroom automatically. Some of you will: Create a program that uses sprites and the distance sensor to control how Edbot moves around the classroom.

4 Sensor Edbot has a motion sensor at the side of its head.
This measures distance and allows Edbot to make a decision based on the data it gets from the sensor. This code will check to see if there is anything within 25cm of the sensor. If there is it will bow and wave. A forever loop will keep repeating the loop until the program is stopped.

5 If Statements Start Set Edbot to start position Is something within 25 cm of the sensor? No Yes Bow and wave right arm This will check if there is something close by. If there is it will bow and wave its right arm, otherwise it will keep checking until the program is told to stop.

6 Mathematical Operators
In the Operators category there are a number of operators you can use including >, = and <. Open EdbotBlank.sb2 and save it with the name Navigate.sb2. Write a program that will make Edbot walk around the room avoiding the obstacles. Edbot should always try to walk forwards. However, if the sensor picks something up within 20 cm it should walk backwards, pick a random number between 1 and 3 and then repeat a right turn that number of times.

7 Possible Answer Write a program that will make Edbot walk around the room avoiding the obstacles. Edbot should always try to walk forwards. However, if the sensor picks something up within 20 cm it should walk backwards, pick a random number between 1 and 3 and then repeat a right turn that number of times.

8 A problem with this program
Edbot will try to move forwards. If it spots an obstacle it will move backwards and then turn before moving forwards again. What should happen if there is still an obstacle? Should it still try to walk forwards? We will change this program to use an if…then…else block so that it ONLY moves forward if there is no obstacle in the way.

9 Compare these two programs
Now it will only move forward if there is no obstacle detected. Original code New code

10 Direct Edbot Open the project called L5_Direct.sb2.
There are 4 sprites and a stage to add script to. Add the following script to the correct sprites. Right arrow: when this sprite is clicked turn right. Left arrow: when this sprite is clicked turn left. Up arrow: when this sprite is clicked check to see if the sensor distance is over 20. If it is, walk forwards, otherwise play the “pop” sound. Down arrow: when this sprite is clicked walk backwards. Stage: add a block of script to the stage so that when the green flag is clicked Edbot stands in the initial position. Using your program, see if you can make Edbot walk around a set route. To test the sensor, occasionally put your hand in front of Edbot’s head to see how Edbot reacts.

11 Self-assessment Read the highlighted points and tick those that you feel you have achieved.


Download ppt "Using the sensor Lesson 5."

Similar presentations


Ads by Google