Introduction
In the following two lessons you will be the chief prison guard. Rumor has it that a gang of cake robbers is to be moved to your prison and they are planning to escape. In order to avoid a public scandal, the Mayor of the city has decided to invest in a new security system for the prison. Your job is to preserve the good name of your prison and protect the cakes in all pastry shops in the area.
Construction
The prison security system is very good although some prisoners have managed to escape in the past by digging tunnels under the prison.
We mentioned the seismograph in Lesson 2. Does anyone remember what it is and what it is used for?
The seismograph is a device which registers underground shakes which means it can detect if anyone is digging a tunnel. The gyro sensor in this robot will function as a vibration sensor. While seismographs draw the vibrations on paper, the robot will read them and react only if they go beyond a given threshold.
WatchTower, a LEGO Mindstorms EV3 security robot
WatchTower is a pretty self-explanatory robot. It detects intruders by sensing the vibrations they make while walking or digging beneath it. For this purpose, it uses a Gyro sensor, which could be incredibly sensitive under the right circumstances. The Ultrasonic sensor that sits on top of a medium motor starts locating the intruders when the Gyro sensor detects them.
After building the robot, close the box to keep the desk clear.
- Gather all the parts from the desk and put them back in the box.
- Close the box and move it aside so it's out of your way.
Programming and theory
Today we will use the gyro sensor to program the robot to “sense” vibrations if someone is trying to sneak in. Of course, the alarm should be deactivated during the days for visiting prisoners and during guard shifts. After all, prison guards are not our objective.
Gyroscope acceleration
Have you noticed that sometimes the gyroscope sensor does not measure the angle correctly? This is because that is not the thing he was created to measure!
Every time we have used the gyro sensor so far we have measured the angle at which the robot turns. However, today we will make something different. Did you know that the gyro sensor does not actually measure the angle but the change in turn speed (acceleration)? Our robot is smart and it uses the acceleration to calculate the angle it is at. Unfortunately, it does not always calculate the angle correctly but it always calculates the correct angle acceleration. The calculation method is in the Rate mode of the gyro sensor:
The Rate mode can also be found in other blocks using the gyro sensor such as the wait block or the switch block:
Have you seen in moves how hunters lay their ears on the ground and try to determine how far an animal is according to the strength of the sound they hear? Similarly, we have to program the seismograph to signal for any approaching prisoners by registering various sounds.
Sound block - play tone
How can we program a robot to produce a certain sound? Let's first look at how sound is measured and then program the robot to produce sounds:
What is sound?
Anyone who is not aware of this interesting fact will find it difficult to realize it. Nevertheless, sound is vibration. This vibration moves in the air, reaching our ears but it can also move though other materials as well. For example, dolphins communicate in water and we, humans, can hear some of the sounds they make.
Have you heard that male opera signers have deep voices while female opera singers – high voices?
There are two scales for measuring sound. The sound strength is measured in decibels (db) while sound frequency is measured in Herz (Hz). Male voices vary between 85-180 Hz while female voices – between 165-255 Hz. Did you know than dolphins can produce so high-frequency sounds that humans cannot hear them?
In order to program the robot to play a sound with a specific frequency, we should use the sound block from the green palette in the Play Tone mode:
You can spend no more than 25 minutes on the following four tasks. If you want to have time and play on the musical instrument you are going to build, be quick!
If you have programmed all steps correctly, you should hear the same sound with every vibration. The reason is that the sound block CANNOT play a sound with lower frequency than 250 Hz. That is why you have to program it at a higher frequency.
Now we hear a sound with a higher frequency which is trembling but not changing. That is because the difference resulting from the gyro sensor is too little. To make it more distinctive, we should turn the volume up.
That is what you have just done:
- You measure the gyro deviation;
- You multiply the deviation by 20;
- Add 1000 to the result;
- Set the end result as the sound block frequency rate.
This is another algorithm you have created today! Excellent!
Important: it doesn’t matter whether the gyro deviation is 0, 10 or -1000. This algorithm will work with all unknown values!
Skyscrapers
No, our prison is not a sky-scraper but there is a lot we can learn from sky-scrapers. Do you know how difficult it is to build a sky-scraper? Do you know how many calculations have to be made to prevent the building from collapsing? These huge buildings have enormous foundations and become thinner to the top, just like pyramids. This is done as during earthquakes the top of the building is shaking much more heavily than the foundation. To prevent it from falling, the foundation should be stronger than the top. This brings us to the conclusion that a seismograph could work better on a sky-scraper, as vibrations on its top would be stronger. Well, there are no sky-scrapers around, but we have a few beams which we can use to lift the seismograph.
Sumo
Did you know that professional sumo wrestlers are also called rikishi? Let's examine what happens during a sumo wrestling match:
Have you seen how sumo wrestlers hunker down before the match?
If the sumo wrestler remains up, his opponent might easily take him down. When they hunker down, they position their center of mass, closer to the ground.
Does this mean that the sumo wrestler who attacks from a lower position will always win?
No! The sumo wrestler who attacks from a lower position has an advantage but does not always win.
Why?
One of the reasons could be that the size of the defeated wrestler is smaller. Size does matter in sumo wrestling. That is because bigger bodies can take stronger hits without being seriously affected. That is why sumo wrestlers eat a lot.
Does this mean that a sumo wrestler of a smaller size cannot take down a larger sumo wrestler?
Again, no! There are cases when smaller sumo wrestlers defeat larger opponents. Victory in sumo wrestling depends both on weight and on flexibility. Sumo wrestlers’ flexibility allows them to face their opponents without being pushed out of the ring.
You already have a functioning security system. However, tomorrow is the day for visiting prisoners and it’s your day off. Prison guards know how to switch the system on but do not know how to switch it off. Apparently, there will be no day-off for you! Unless! How can you switch the security system on during the night and program it to automatically switch off in the morning?
Conditional Loop
So far you have used the loop block to infinitely repeat your programs. Did you know that a program can be repeated until a condition evaluates to true without having to use the loop interrupt block?
By clicking on any of the ends of the loop block, we select it and we can see its settings in the lower part of the window:
Similarly to the wait block which waits until a command is given, the loop block repeats the blocks in its body until the condition for exiting the loop is met.
What exiting conditions are there? There are five types of cycles in EV3 which differ according to the duration of repeating the cycle body. We can see them if we click on the drop-down menu located on the right of the Control button.
1. Forever – this is the setting by default. If chosen, the cycle body will repeat infinitely. If there are blocks after this cycle, they will never be performed! When we have such a cycle, the robot should be manually stopped by the light grey button.
2. Sensor – when choosing this setting, the body cycle will repeat until any of the sensors detects a certain value. We will focus on that setting in the next levels.
3. Time – when choosing this setting, the cycle will repeat for a definite period of time which is set in seconds.
4. Count – this is one of the settings frequently preferred. It allows us to choose how many times the cycle body will be repeated. To make the robot move in a square we will use this exact setting and will set it to 4.
5. Logic – this setting is more complex and won’t be used at this stage of training.
The following example shows how to set the loop block so that the program is repeated until the motor attached to port A turns more than 90 degrees:
As you can see, the conditional loop block can work with all the sensors you have access to.
Remember that the condition is actually a loop interrupt condition. The loop will execute a block of statements repeatedly, until a given condition evaluates to true. When the condition evaluates to true, the next block in the program will be executed.
Important: the condition will be evaluated only once per repetition (iteration) of the loop, after all blocks of the loop body are executed. If you insert a wait block into the loop, you may witness some unexpected behavior.
There is a switch block in the program which only interrupts the loop. We can set its condition as a condition for the loop block and remove it from the program.
Tasks to finish a class
- Take pictures and make videos of your robots
- Disassemble and arrange the robot
- Arrange your workplace
- It is important to arrange the electronics of the robots on the cover of the box.
- Wind up the programming cable so that it is assembled.
- Put the robot cables next to the electronics.
- Wind up the mouse cable around the mouse.
- Wind up the cable of the laptop charger in a way that your teacher will show you.
- When you turn off the computer, leave it next to the robot box.
- Turn off all programs on your computer
- Exit FLLCasts
- Shut down your computer
- Put your chair under the desk.