In this first part we stop at an algorithm that is the base for following lines and explains the basic idea for the proportion. A must watch if you want to understand the robot at its behaviour. At the end the program still wont work so check out Part 2 and Part 3 for the final steps.
- 30 Oct 2015
This algorithm for following lines is called Proportional. It proportionally rotates the motors depending on how far from the line the robot is. If the robot is right above the line the proportion between the two motor is equals and they just continue forward. But as the robot looses the line, the algorithm would return it as quickly as possible proportionally to how far away the robot is.
We have marked the video as Advanced because it uses more complex programming abstracts like Variables, Threads and Math Calculations.
In this video we would implement an algorithm for following a line that's called a proportional algorithm. It uses the color sensor and in this video we'll use one of the color sensors. It's a very smooth algorithm for following lines. It works like this.
Finds the line and follows it. Let's see how we can implement this program.
The basic idea of a proportional algorithm is that you move the different motors with different speeds depending on how far away the sensor is from the line. For example, in this program we would use the sensor located on port 1.
If we have our line over here, we know that if our robot is away from the line, like in this situation,
then motor A moves faster than motor D.
If the sensor is near the line then motor A moves slower. It's a different proportion and this algorithm follows the edge between the line and the field. You move the different motors with different speed depending on how near the sensor is to the edge. When the sensor is on the edge you actually move both motors with the same speed. That's the basic idea for proportion. If you are too far away from the line, you need to return very fast and if you are very near to the line you need to just move the robot slightly and then continue forward. The program looks like this. We need to control 2 of the motors and we need to control motor D and we need to move it forward and we need to control motor A. These are the 2 motors that we need to control and we had one sensor, this sensor is located on port 1, it's a color sensor. We want to measure the reflected light, not the color but the reflected light because this is a proportional algorithm. How do we control these motors?
We use the block for detecting the reflected light then we must calculate what should the power of motor A be and what should the power of motor D be.
How do we do this? First we have motor D and in our robot, if you imagine it, in our robot motor D is the left motor. If we have our robot and this here is the front, we have the sensor here and we have one of the motors here and we have the other motor here. As the robot moves forward we have the following numbers. This is the sensor on port 1 and this is motor A and this is motor D and this here is the line, that we are following. We are following the edge of this line, it's all black and we are following the edge of this line. Motor A, motor D. So motor A is our right motor and motor D is our left motor and that's important. How does the proportional algorithm works? We detect with the color sensor and we do this in a loop
and we take the value of the color sensor. This is more advanced program and it will include some variables and some threads but stay with me. Detect the value and then we do a calculation with this value and the calculation is the following.
If we place our robot over the black line so now it's over the black line
and currently this is the value detected by our robot.
We are over black and the sensor detects 16%. If we move the robot over the table which is in our case something like white. We detect a value of 68%. So black is 16 and white is 68.
The value between 68 and 16 is around 40. We can use this as a threshold value. We detect the value of the sensor and we subtract 40, that