Week 3 – 2019 – Oliver

This week I made a new line-follower program with 2 sensors. This program doesn’t need to wiggle to stay on the black line. It uses the amount of reflected light to tell which direction to turn. The program is shown below:

My new line-following code (click on this image to make it bigger)

James and I started making the code for our hint-finder part of the line follower. If the sensors are on neither white nor black, they must be on green or silver. The robot automatically veers onto the hint, meaning one sensor is on green and the other on black. The difference between the right and left sensor is about 10, so we can use math blocks to work it out:

Sensor 1 (10) - Sensor 2 (20) = -10
The ABS of -10 is 10, so the output is 10.

ABS stands for ABSolute value, which removes the negative sign. The result is the difference between the two numbers. However, if the robot finds silver then both sensors will be on it. Therefore the sensors will receive about the same value, with an exception of 2 or 3. The absolute value of silver will then be lower than 3, which will trigger the can-finding program.

The table below explains the amount of light reflected from silver or green hints for each sensor:

    Reflected Light        |  
---------------------------|---------------------------- 
Left Sensor | Right Sensor | Difference (Absolute Value)
-------------------------------------------------------- 
80% (Silver)| 79% (Silver) | result = ABS (80 - 79) = 1  (Silver; Stop)
10% (Black) | 20% (Green)  | result = ABS(10 - 20) = 10  (Green;  Hint)

This screenshot is my hint-detector test code, which will show “GREEN” on the screen on a hint or “SILVER” if on silver.

This is my hint-detector test code. (click on this image to make it bigger)

But, of course, to incorporate this into my code would require a MyBlock. For the MyBlock to work effectively with the code, I needed to remove the loop and turn the if/or statement into a logic output statement, which you can make from the MyBlock menus like shown below:

This is how to set up a MyBlock for logic statements.

Finally, I placed the finished MyBlock in my line following code. When the colour sensors are both on silver, such as when it reaches the end of the line and the start of the can finder part, it cuts out of the loop and will lead to the can finding algorithm. I am yet to make a program to turn at the green hints, so I will come to that next week.

The semi-finished hint-finder MyBlock. I will add to this in future weeks.

Useless fact of the week: The closest fraction to pi is 22/7! Check on the calculator if you don’t believe me! (22 ÷ 7 = 3.14285714286 and π = 3.1415926535)