Why use use two Color Sensors?
If you have followed the tutorials so far, you will have added a Color Sensor to your robot, and successfully programmed it to follow a line – good work! This would enable you to enter a Robot in the Tasmanian RoboCup Junior Rescue Championships that are held about August each year.
Robot Rescue runs in the Rescue event are timed, with robots that are faster having an advantage over slower robots. Some people think that line-following Robots using two Color Sensors are a little faster than one-Color-Sensor line-following robots. Let us experiment and see if that idea is true!
NOTE: LEGO only includes one Color Sensor in each Education or Home EV3 set. When we are in a classroom, we can “borrow” the Color Sensors in other sets to allow us to experiment with two color sensors attached to one robot. If you have a need to purchase additional Color Sensors, we suggest you approach the LEGO suppliers in your country, or, failing that, try one of the International web sites such as https://www.brickowl.com/catalog/lego-parts or https://www.bricklink.com/v2/main.page (we have no connection with these sites and receive no financial feedback from these sites).
Programming your robot when it has two Color Sensors.
When you have added a second Color Sensor, your robot may look something like the robots shown below.
Photo 1. Both Color Sensors on WHITE.
Photo 2. LEFT Sensor on BLACK, RIGHT on WHITE.
Photo 3. RIGHT Sensor on BLACK, LEFT on WHITE.
Photo 4. Both Color Sensors on BLACK.
Programming Method 1
It has been suggested that we could program a Robot so that each of the Color Sensors work to keep the robot away from the line by just using the one-Color-sensor program twice in a row, with the motors reversed, as shown below:-
Try replacing our previous Line-Following code (see diagram below) with the code above.
Does using this two-sensor code allow our Robot to follow a line more quickly than our previous robot, which used one Color sensor? If it is better, how much faster is it? If it is not better, why is this not a useful program?
HINT: To work out why it is behaving in the way it is behaving, follow through the code to see what happens in the cases of photos 1:, 2: and 3: on the previous page; (we can ignore photo 4: for a while). When you feel you have tested Programming Method 1 and understand how this program works, experiment by replacing the Programming Method 1 code with the Programming Method 2 code below. Is the result better or worse?
Programming Method 2
In this case we should think carefully what we want our robot to do when it comes across the circumstances shown in photos 1:, 2: and 3: (ignore photo 4: at this stage).
One way of coding this diagram is shown below. Try replacing your previous line following code with your version of code that could be similar to the code shown below.
Is your Robot better or worse? Can you work out what the program above does if both sensors see black (photo 4)? Also, this program is not the only way to represent the previous red outlined diagram – can you think of a different way? How would your program be different to the program above?
• You could try varying the width between the Color Sensors – what difference does this make – does your robot go around corners more easily, or does it have more problems?
• You could try varying the distance the Color Sensors are ahead of your driving wheels – what difference does it make if the sensors are a long way ahead, or even closer than you originally had them – does your robot go around corners more easily, or does it have more problems?
• The Australian competition RoboCup Rescue mat has small green squares as well as black and white. What do you want your Robot to do when it finds these green squares? How could you teach your Robot to do what you want it to do?
Lots of alternatives to have fun with – experiment, and see what you can find out! ?