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.  



EV3 Limited Wanderer Robot

This post is about a robot, which wanders in a limited area. In this project, we have marked an oval shaped area with a black line. We calibrate the robot with white and black values by making a manual movements on the surface. We then take the threshold (average of black and white values) and expect the robot to turn, when it reaches the threshold. That's the reason, the robot turns 90 degrees, when it reaches half way through the black line. The robot continues the behavior of making turns after finding a black line and keeps itself within the oval. A small clip showing the behavior of robot is shared below. You can also find the LeJOS program, which simulates this behavior, shared below.

In this LeJOS program, we have a single class called LtdWanderer. In its main method, this class initializes the large regulated motors on port B and C. It also initializes the two sensors color sensor and gyro sensor attached to port S4 and S2. The color sensor is initialized in Red mode and gyro sensor in Angle mode. The program then stores the calibrated values of light intensity reflected from the black and white surface. The LeJOS API returns the light intensities in the range 0 to 1. We have multiplied them by 100 and calculated the average light intensity of black and white for further programming logic.

The default behavior of the robot is to keep moving forward with a speed of 180 degrees per second. While moving, it also fetches the samples from the color sensor continuously. The robot checks if the light intensity is greater than average light intensity. If yes, the robot is free to wander further because it is on a white surface. However, when the light intensity goes below the average light intensity, the robot concludes that it is on the black boundary, and it make a left turn to be within its limits. 

NOTE: With each turn the LimitAngle variable increases its value by 90 degrees. We ideally should have reset the sensor and measure the angle each time the robot makes a turn, to check if it is equal to 90 degrees. However, we found that the reset function did not work as we were expecting. The angle measured by the Gyro sensor kept on increasing as and when the robot takes a turn. Hence the purpose of the LimitAngle variable. With the LimitAngle variable, we are checking whether the difference between previous turn angle and the current turn angle is equal to 90 degrees. We then stop the robot from making a turn and let it go straight and wander. 

The robot wanders infinitely until ESCAPE button is pressed.