5. Lesson 5 - Personal Yacht

Introduction

Gyrocompass

Did you know that most of the modern ships and bigger boats have a gyroscope sensor on board? How do you think it looks like? How big is it?

content picture

These ship devices are called gyrocompasses. Their purpose is to show where is North - just like a compass - but they are more accurate and are not influenced by metal or magnet objects. The gyrocompasses are not huge devices, but they are much larger than our sensors. They are about 50 centimeters wide and about 1,2 meters high, though the purpose of the size is to make it easier to work with. Today gyrocompasses are used along with different systems, such as GPS, to locate the exact position of a ship.

Construction and Theory

After building the robot, close the box to keep the desk clear.

  1. Gather all the parts from the desk and put them back in the box.
  2. Close the box and move it aside so it's out of your way.

Programming and Theory

Gyro sensor - Switch

We already know how to use the gyro sensor with wait block, now its time to learn how to use it with Switch.

The Gyro sensor, like every other sensor, has its own setting in the Switch.

Unlike the wait block, where there are two options, here we have only a compare mode. If you place the mouse over it, you will see two sub-modes. 

  •  Angle - the robot compares with a certain value, by default 90, the number of degrees the sensor has rotated. The block checks if the comparison is true and executes the relevant commands according to the result.content picture

  • Rate -  the robot compares with a certain value, by default 90, the rate of change in the rotations measured by the sensor - i.e. how many degrees per second the sensor rotates. The block checks if the comparison is true and executes the relevant commands according to the result. content picture

 

The last setting we need to pay attention to is the port to which the sensor is connected. By default it's 2, but if we have to, we can change it to any port from 1 to 4.

content picture

Important part of the programming of the gyro sensor is that when we run a program or start port view, it starts measuring degrees from 0. Clockwise rotation is measured as positive and counterclockwise as negative degrees. Just like with the rotation sensor that follows the same logic.

Unlike the degrees, the rate is always 0, until it turns. When it stops turning, it goes to 0 again.

Keeping a straight line using a gyro sensor.

The gyro sensor indicates the angle of the turn the robot made. We certainly can use this to create a robot that could perfectly follow a direction, right? Now we'll show you the easiest way to do it.

This program is exactly the same as following a line with one color sensor. The idea is to move straight, when we're in the right direction (the gyro sensor shows 0 degrees), and to turn, when the gyro is not showing 0 in order to get back to the right direction.

content picture

However, this would be complicated. In general the program represents a series of constant turns, also known as "duck walking". The back line from the line following task will be replaced by the imaginary line that we want to follow. The target value will be 0, but we can modify it for the angle needed. The algorithm is as follows:

  • If the gyro sensor shows less than 0 degrees, we turn towards 0 degrees - in this case we turn right.

content picture

  • If the gyro sensor shows more than 0 degrees, we turn towards 0 degrees again. In this case we turn left.

content picture

And we're ready! We have a program with which our robot will always follow the same direction, even if we try to push it away from its path.

Like in line following, this program could be done with both switch and wait blocks.

This is the simplest algorithm for following a direction, but it's not the smoothest. Fortunately, line following is exactly the same task as direction following. Therefore, you could check the tutorials for line following with 3 or more states or proportional line following. The logic is exactly the same.

Three or more state programs

So far we have created programs that have two outcomes. For that purpose, we have used a switch block. We set some condition and based on its outcome we either do one action or other. Now, we will take a look at how we can program the robot to have 3 or more different responses to the environment.

Let us take the example with the 3-state line following with the following setup:

So, if we put just a switch block that compares whether the value read by the color sensor is less than 27: 

the robot will not know what to do in case the value is greater than 27. If the value is less than 27, it is obvious that the robot should turn right. However, in that case, when the value isn't less than 27, the robot has to either go straight forward or turn left. If the value is less than 43, the robot should go straight, but if it is greater, then it should turn left. How can the robot decide what to do?

The same way it has made the decision to turn right - with another switch block. If we put another switch block comparing the value to 37, we will have our issue resolved. Due to the fact that the second switch is evaluated only if the first one is false, when comparing to 43 we know that the value is greater or equal to 20.

content picture

The use of switch inside another switch is called nested switch.

Tasks to finish a class

  1. Take pictures and make videos of your robots
  2. Disassemble and arrange the robot
  3. 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.
  4. Turn off all programs on your computer
  5. Exit FLLCasts  
  6. Shut down your computer
  7. Put your chair under the desk.