Showing posts with label line follower. Show all posts
Showing posts with label line follower. Show all posts

Sunday, 29 December 2019

EV3 Line Follower With Obstacle Avoidance

In this post, we have implemented a Line Follower, which has the ability to avoid obstacle placed on the line. The Line Follower is an inner edge follower implemented using PID control algorithm. We expect the Line Follower should keep following a threshold value of light. This threshold, is calculated by averaging the Black and White light value of the surface. We have also calculated the Proportional, Integral and Derivative gain of PID algorithm which keeps the robot on the black line. The program works with an IR Beacon which allows us to control the speed of the robot by applying 0 power (to stop), 20% power, 35% power and 45% power. Each of the power values, need different set of PID gains. While following the line, if the ultrasonic sensor detects an obstacle at a distance of 20cm, it takes a turn of 38 degrees with the help of Gyro sensor. The robot then goes forward for 3.5 seconds in 38 degrees direction. Then the robot take a turn of 90 degrees and moves forward, until it finds the black line. It starts moving on the line again. A small video clip showing the performance of the robot is shown below. Also, we have attached the LeJOS program which simulates this behavior of the robot. However, there are few limitations for this program. They are listed below.

  • Currently the program is not enough generic. That means, it does not take into account the readings that the gyro sensor gives, after having one complete round across the oval shaped black line. If the robot takes a complete turn and approaches the same object again, we do not guarantee that this program will function well. We are still working on it. 
  • We have not yet experimented with multiple objects placed on the oval shaped line. We are assuming that the program should work, in case if multiple objects are in a single straight line. 

NOTES: 
  • It would beneficial if you go through the following article, before going through the program. It will explain to you the PID Controller and Line Following concept in detail.
  • The gyro sensor returns positive values of the angle in degrees when it turns clockwise and it returns negative values when it turns anti-clockwise, based on gyro sensor mounting over the robot. We are moving the robot 38 degrees (we came up with this angle measure purely empirically) to move it away from the obstacle. We are making the robot move ahead for 3.5 seconds and then turning it 90 degrees in the other direction to make it meet the line again. We realized that by moving it in 90 degrees, the robot touches the obstacle at some point. Which is not right! In order for this not to happen, we should turn the robot less than 90 degrees and let it meet the line somewhat ahead of the obstacle.
  • The LimitAngle variable is set to 320 + 38 at the end of the loop. This is because with each of the completion around the oval shaped figure drawn with the black line, the angle returned by gyro sensor keeps on increasing by 360 degrees. So, in case we want the robot to go for another round and come across the same obstacle again, the program should work! However, as we mentioned above, we have not tested the program to face the obstacle again after completing the oval path.  



Tuesday, 17 April 2018

EV3 Track3r Line Follower

This is a post for EV3 Track3r line follower. Track3r has an attached color sensor which helps the track3r to follow the black line on the white surface. For the track3r to function, calibration of white and black color has to be done (which is not captured in this video.) The actual algorithm to follow the line is influenced by Jacek Fedorynski's Line Follower NXC program. The LeJOS (Java) program has one class EV3LF. This class initializes the color sensor and calibrates the sensor for Black and White values. This class has the algorithm to follow the line - given the calibrated black and white values and the light intensity at any given point in time.

The detail process of calibrating Black and White values is as follows. We can hear two beeps and the robot waits for press and release of ESCAPE button. While the robot is waiting, we have to manually adjust the color sensor such that the red light emitted by the color sensor will be focused over the white surface. Then press and release the ESCAPE button. This is the instant when the robot will fetch a sample from the color sensor. This sample will act as the threshold value for white color, which will be printed on the screen. 

Then, we can hear two beeps again and the robot waits for press and release of ESCAPE button. While the robot is waiting, we have to manually adjust the color sensor such that the red light emitted by the color sensor will be focused over the black line. Then press and release the ESCAPE button. This is the instant when the robot will fetch a sample from the color sensor. This sample will act as the threshold value for black color, which will be printed on the screen. 

We then initialize the motors B and C which will drive the robot forward. We power the large motors such that the power of each motor is a function of average light ((white + black)/2), instantaneous value of light (color[0]), white threshold and black threshold. We use this power to drive the motors forward. Let's analyze the formulae to calculate the power for the two large motors in detail. 






  • The polarity of the second term is opposite for both the motors to calculate the speed requirements (as indicated by the RED circles). Due to the opposite polarity, the cSpeed and bSpeed function in opposite manner. That means, when cSpeed is positive, bSpeed is negative and vice-versa. Hence when the robot is on the black surface, it gets pushed on to white surface and when the robot is on white surface, it gets pushed on to black surface. Thus the robot moves in a zig-zag manner along the line. However, since the zig-zag movement is very subtle, it appears to be smooth. 
  • The defaultPower is set to a constant value, which can be tuned based on the speed requirements.
  • The multiplyingFactor is set to a constant value, which can be tuned such that cSpeed and bSpeed will function in opposite manner.