Line following algorithms nxt robot
Having a matched pair of sensors will make it much simpler to create programs without having to compensate for differences in sensor readings.
This is the simplest of the two sensor line followers and it is also one of the fastest while still staying reliable. The algorithm for this is very straight forward:. This method can work very well, it is reasonably fast, it can handle a gap or break in the line as it will just continue forward when neither sensor see a line and with two sensors it can be used to read the green shortcut markers. All the problems with a single sensor robot have been resolved. There are some other methods which can be used to get smoother line following, these included stepped, steering and proportional.
You could adjust the program to have five steps by breaking the turn left and turn right into two levels of turn. A couple of approaches you can use are shown below:. Using a stepped approach will allow for smaller corrections when adjusting for the robot just needs to straighten up. The Steering method is like the Stepped method but with many more steps.
If you need it to turn sharper, you can multiply the differential by a turn factor to increase the turning values. Based on the example readings with the range of 10 to 50, the differential can range from to If we multiply this by a turn factor of 2. This final value can be used as the input to the block. The Proportional method also uses the differential value with a turn factor and then uses formulas to calculate the motor power to send to each motor.
An example starting point for your formulas could be the following algorithm based on the differential with turn factor range of to The factors and formulas can be adjusted to change the power values.
For example, multiplying the differential by a value of 1. X can make the maximum turning circle sharper. A solution that produces a much better solution is the Fuzzy Logic approach presented earlier.
However, only a few students at the primary school level are able to understand and program this algorithm. If the block receives a steering value of zero, the robot goes straight on.
For positive values, it will turn to one side and for negative values to the other side. We want the robot to go straight on when it is exactly on the edge of the black line. Thus, the value the sensor reads when on the edge needs to be subtracted from the current sensor value. Most of the time, the different sensor readings between the black line and the white surface are relatively small. The produced steering is not enough to keep the robot on the line.
To solve that problem, we amplify the value obtained from the subtraction with a constant factor. The best value needs to be found through experimentation.