-
Notifications
You must be signed in to change notification settings - Fork 44
Line Following Challenges
This set of challenges involves programming your robot to follow a line using the color sensor. Later challenges adds in obstacles to avoid and junctions to navigate. Most of the challenges have no end point, so just drive until your robot falls off the table. Don't worry; it won't break. 😊
An additional meta-challenge to attempt, would be to write a single program that can complete all of the challenges (except "Junctions 1"). This means that you can only press "Run" at the start of each challenge, without making any changes to your program.
These challenges covers the basics of line following. You can complete them using either a single color sensor or a double color sensor robot, but a single sensor robot is recommended if this is your first time doing line following.
Some materials you can refer to for line following http://www.aposteriori.com.sg/wp-content/uploads/2019/07/Single-Line-Follower.pdf
Note that when using a real robot, you must conduct tests to determine the range of the reflected light intensity (...or perform calibration if available) as it will depend on the sensor as well as the surface being measured.
To cross a gap while line following, you'll need to use a robot with two color sensors, one on each side of the line. You'll need to use the difference between the left and right sensor to control your turn. Beyond that, it works largely the same as a single sensor line follower.
The actual crossing of the gap requires no special handling, but getting the robot to straighten out sufficiently before leaving the line can be challenging especially when the straight segment is short and the gap is large (...try "Gaps 2"). You may need to apply some tricks to cross all the gaps in "Gaps 2"...
Here we start with some simple obstacle avoidance. The simplest approach is to use your ultrasonic sensor to detect the obstacle, then just drive around it with a fixed sequence of turns and move. This isn't all that reliable, especially if your robot is moving fast. If you have already done the Gyro challenges, you can use that to improve your obstacle avoidance program, but that isn't the only way. Think about what else you can do!
Sometimes, one side of the obstacle is blocked (eg. by a wall). These two challenges requires you to detect these obstructions and go by the other way. Depending on where you detect the obstacle (eg. on the first turn or after the second turn), you may need to backtrack more or less. One way to handle this is to use a variable to keep track of how many turns you have made before detecting the obstacle, but there are other ways too...
The obstructed side is randomize on reset.
In the previous obstacles challenges, the obstacle is always the same size and the line always exits on the opposite side. Not so for this challenge.
To handle obstacles of differing size, you'll need some way of detecting the obstacle size. One way is to use a side facing ultrasonic sensor and move until you are passed the obstacle. A GearsBot can have a near unlimited number of sensors, but a real robot will face limitations there. Try thinking about other ways which doesn't require the use of many sensors.
Detecting if you have rejoined the line pass the obstacle can be easily handled using the color sensor.
This challenge tests your robot's ability to navigate to any arbitrary point while line following. This is used extensively in the World Robots Olympiad games. To handle the junctions, you should first prepare...
- Double sensor line following function
- Single sensor (Left) line following function
- Single sensor (Right) line following function
- Left turn function
- Right turn function
- U-Turn function
If you have been doing the previous challenges, you should already have most of these ready.
Next, modify the line following functions to stop on junctions. For example, the double sensor function should stop when both sensors are reading a low value (ie. both sensors are seeing black). With these functions ready, navigating to any point on the map should be a simple matter of chaining a sequence of functions together.
- Pick a random point (eg. "D")
- Program your robot to go there and stop
- Pick a series of random points (eg. "C, L, A, Q, J,")
- Program your robot to go to each end point in turn
- Beep at each point and stop at the last
If your functions are well prepared, these two tasks should be trivial. Repeat task 2 a few times (...with a new series of random points), until you are able to consistently succeed on the first attempt.
This time, the direction of turn at each junction is marked with a green square. Open up the challenge in Gears for an illustrated guide on how to interpret the green squares.
Colors can be tricky to detect. The RGB values can differ greatly depending on the shade of green used, and the position of the color sensor (eg. halfway between green and black) can have a large impact as well. If the color is distinct enough, a simple set of conditions can be sufficient to detect it. Example...
# Pseudo Code. Don't copy this.
IF red < 50 AND green > 150 AND blue < 50; THEN
TURN()
END IF
But in many cases, it is better to convert the RGB (Red, Green, Blue) values into HSV (Hue, Saturation, Value). See https://en.wikipedia.org/wiki/HSL_and_HSV for an explanation of HSV and the algorithm to convert from RGB to HSV. If you're programming in Python, the Ev3dev API provides built in conversion into HSV (See https://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/stable/sensors.html for details).
Python References