Following a line with two Hi Technic Color Sensors in EV3

As an extension to the previous video we talk about the Hi Technic Color Sensor again.

  • #99
  • 02 Aug 2015
  • 10:13

In the previous video we discussed the Hi Technic Color Sensor and went over a simple program for following a line with the sensor. This time we are doing the same thing, but with two color sensors.


Note: As of building the video we do not have the sensor. It seems to be out of stock. So we have not actually tested the program, but it is following a working algorithm and should work. 

English

- Previously, we got the question on how we can use the HiTechnic color sensor to follow a line in the EV3 software. We built a simple program after adding the HiTechnic color sensor to our software. Check out the previous video on how we can do this. Now, after we built this program, we got the question of how can we follow a line using two of the HiTechnic sensors, and this is the subject of today's video. Now, the program worked in the following way: It was a simple program for one sensor. It was the HiTechnic color sensor. We don't have the HiTechnic color sensor currently, so we haven't tested this program, but I assume that the block measures a color, and it returns a number, an integer, for different colors, and I also assume that for black it returns 1 and for white it returns 6. So, when we detect black, we stop one of the motors and start the other, and when we detect white, we actually change the motor, so we stop one of the motors and start the other. This is a very simple program for following a line with one color sensor. Now, if you go to the FLL Casts site and you search for "follow", you see a number of programs developed for following lines. First is this episode #1 "How To Align and Follow a Line with Two Light Sensors" and it was a very simple video for the NXT version of Mindstorms. Now, we revised this a couple of months ago in January. It was requested by . It was "How to Follow a Line with Two Light/Color Sensors for EV3". So, this here is another tutorial for following lines. Now I will follow the same principle as in this video #75 to implement following a line with two color sensors, but this time color sensors that are HiTechnic color sensors. Just as a reminder, when we are following lines with two color sensors, the robot would look something like this. We have one of the motors here and this is one of the sensors. This is the other color sensor. And we have the line like this. So whenever we are following a line with two light sensors, let's say that this is Motor A and this is Motor D and this is Color Sensor 1 and this is Color Sensor 2, we move forward. When we detect the line with Color Sensor 1, we must turn the robot. We must turn the robot left, so Motor D is moving forward and Motor A is moving backward. This is when we detect the line with the first sensor, with Sensor 1. The same principle applies for detecting the line with the second sensor, with Sensor 2, if the line is something like this. Then we have to turn the robot in the opposite direction. This continues in a loop until we reach the end of the line. So how does this look in the program? Let's first implement the switch out the color sensor here so I have two color sensors, and I'll remove the loop. First, the robot is moving forward, and If we detect the line with Color Sensor 1, the HiTechnic color sensor, if we detect with Color Sensor 1, then we must turn the robot in the following way: Just delete this. We take the tank and let's say that we have Motor A and Motor D, so these here are the two motors, and we detect the line with the first color sensor. We are over black, so we are turning the robot. How do we turn the robot? We rotate both motors for a number of degrees. No, the tank is not our block. This one here is more clear. So, A and D. Now we rotate, let's say, Motor A backward with -50 as power and Motor D we rotate forward, so we are turning left. We had Motor A here and Motor D here. And we rotate for, let's say, 30 degrees. This is whenever we are over black with the first color sensor. But if the first color sensor detects white, in the case here, then we must check the second color sensor. We have a second color sensor that is connected on Port 2 and we again check the sensor. If we detect that the second color sensor is over black, this is the case when the color sensor returns one and if it is right here, then we must rotate the robot in the opposite direction. Again, Motor A and Motor D, and we rotate Motor D -50, backward, for about 30 degrees. Of course, you can customize the degrees, you can customize the power, you can change them and inspect the solution on the field. Finally, when we have the second color sensor over white, then we must just go forward. There is no need to turn any of the motors. We just go forward with both motors for an unlimited amount of time. It is Motor A and Motor D. Again, with the program, this here is Motor A. This here is Motor D. I'm drawing with the mouse, so excuse me. This here is Sensor 2. So we have Sensor 1, Sensor 2, Motor A, and Motor D. And we have the line like this. When we detect the line with the first color sensor, this one here, then we turn Motor A backward and Motor D forward like this and we align to the line. Then, if we detect the line with the second color sensor, we do the opposite thing. We rotate Motor A forward and Motor D backward. If none of the sensors detects the line, so I assume that we are over white, then we just move forward. And that's the whole program. Now if I add this program in a loop, first I'll switch to flat view so that we can have more space, and now if I add this program in a loop like this, we will have a very simple solution for following a line with two HiTechnic color sensors. Again, I welcome any comments. We don't have the HiTechnic color sensor currently, so we haven't actually tested this program, but I did a number of assumptions and I think that this program works. Of course, the values might be different. If you have other questions and suggestions for a video, share them below in the comments. You can find this program in the comments, and don't forget to join, create an account, and receive notification whenever we build a new video.