Continuing with the Proportional algorithm for following lines. Smooth and stable this is the first part of the PID.

**# 176**- 01 Nov 2015
- 5:01

### Previous episodes:

### English

Previously we started implementing a program for following a line with a proportional algorithm and the program should work like this.

But in the last video we finished with a program that was doing something like this.

Obviously the program is not working and we should improve our proportional algorithm to follow the line very smoothly.

The problem is in the program and the way we calculate the values for motorR (motor Right) and for motorL (motor Left). What we are doing is the following. We subtract 40 and we get the value of motorR and we subtract from 40 and we get for motorL. As you saw the robot should move on the edge between the white and the black and for this let's imagine what will happen. For motorL and motorR. For motorR we'll constantly have the following value 70-40 and it will be equal to 30

and for motorL the value will be constantly 40-70

equal to -30 and this is the case for when we are over white. Let's zoom a little more. When we are over white this will be the values for the 2 motors and this will make a very sharp turn, the whole robot. Then when we are over black, let's say that the value actually 15 and 40-15 will be 25 and this will be for motorL and for motorR we'll have 15-40 and this will be equal to -25 and this is a loop that continues forever and that's why you saw the whole robot just jiggling in one place and not moving forward. What we should add to our program is a constant speed and we want this constant speed to be 15 so we have a constant speed of 15 and then we add the proportion to this constant speed. Let's do this in the program. I'll have to change the blocks. First I'll change this block to make it an advanced block and the formula for it will be а (the value detected by the sensor) (a-40) +15 and and for motorL we'll have the same formula but it will be (40-a)+15.

Let's run the program and see how it works.

As you can see the robot is now following the line. Finding and then following the line and again, I'll start it from a larger angle.

So we basically have a working program. In the next video we'll improve this program by adding a constant and this constant will direct how fast we find the line.

Currently it takes 2-3 seconds to find the line.

Of course, you can download the program below the video and the instructions to building this robot. In the next video we'll improve it to make it find the line faster.