MODKIT-Line Following


#1

Greetings,
Is it possible to write a program to follow a line using MODKIT or do you need ROBOT C to do so?
Thank you and have a great day!
Chris Prout


#2

Yes, this is definitely possible. Attached is a rough idea of what you need to do. Make sure the colour sensor is set to greyscale mode. In Modkit, this basically returns a percentage value where 100 is white and 0 is black. In practice, your values won’t go right the way to 0 or 100.
The program tracks the right hand edge of the line - if the percentage value is greater than the white threshold, it has strayed too far off the line into the white and so the robot turns left. If the percentage is less than the black threshold, it has gone too far over the black line and needs to turn right. If the percentage is between the two thresholds, the robot is half on the line and half off it (following the edge) and so can go straight forward.

5ec512173212c77eabeb231093df2d86.png


#3

Thanks for the help! It works fine when turning to the right, but loses its way when the line turns to the left. Suggestions?

e03825640544f44265386c22abde4a51.JPG


#4

Is it working in principle? i.e on my robots, this program will linetrack the right hand edge of the line. Therefore if you put the robot all on the white, it should turn left. If you put the robot on something black, it should turn right.
I notice your line is blue, this will have a higher threshold to the black lines of the IQ field that I used to test so I guess it won’t see the blue line as black.

To calibrate it, you can expand the program. under the brain, make a when start and then a foever loop. Inside the forever loop, print the colour sensor % to the screen, add a 0.2 second wait and then clear the screen. When you put the robot on the line, you can see what value is your “dark” and calibrate the black threshold a few % higher than this value.

Hope this helps!


#5

Here’s our code and a video of its behavior.

Line Following Code.jpg


#6

#7

OK, makes sense. What is happening is that the robot is detecting the white just fine, the white areas are massive so it has plenty of time to do this. However, it moves very quickly over the blue line and back onto the white the other side, which makes your robot think it has fallen off the left of the line and therefore turn right.
Couple of things you can do here.

  1. use a black line instead of blue so that the contrast between light and dark is greater
  2. double the thickness of the black line so that the robot has more time to detect it as it sweeps over the line
  3. slow the robot down a bit
  4. “calibrate” the threshold for the line using the technique in my previous post if you have not already done so

#8

Crprout,

Another more reliable solution is to use 2 color sensors (spaced about 1 to 1.5 tape thickness apart). Program the bot to drive straight if they are both seeing white, then if the left one detects blue; turn left, and if the right one detects blue; turn right. This way there will be no confusion on the correct way to turn when the line is detected. This should also allow the bot to re-find the line as it drive up to it, however there may be a problem if it approaches the line perpendicularly, as both senses may see blue at the same time, then it matters how you programming is written (I suggest you make turning one way be dominant, and if that dominant way sensor is over its threshold, the other is disabled).

Hope this helps.

Paul


#9

Hello,

I can see the code above for following the black line. But, I have trouble determine what block it goes in. Does it go in the drivetrain block or the brain. Also, what blocks to I place in the color sensor?


#10

It would be in the drivetrain. You wouldn’t need anything in the colour sensor tab for the above example.


#11

I am trying this at home on my kitchen floor which is a grey tile (various colors) and then I tried again in my sitting room which is hardwood floors (brown). On the kitchen grey floor, it seems to be looking for a line and goes forward at times, but on the hardwood, it just goes in circles.


#12

You may need to adjust the thresholds, different surfaces have different reflectivity and thus provide varying brigthness readings.


#13

A very good thing to help with this is to have the brain display the current grayscale reading to the screen. Makes it very easy to see what’s up.


#14

We put 3 while loops inside a forever loop. Each while loop either 1) checks left in 10 degree increments (up to 120 degrees) 2) checks rights… or 3) goes straight ahead. I also sped things up by having a ‘return to center quickly’ code block if it gives up searching left to bring it back to center quickly before searching right.


#15

Is there anyone who can show me a Modkit program to go straight using the gyro? Or anything really? I have tried several different things and none of them work. And yes, we have a disk in between the black thing and the tires to keep them straight. I just need a program to make our robot not veer to the right while running autonomously.


#16

That follow the black line program looks great. But, I would need to see the Modkit code to see how to do it.


#17

Please help!!! Our state tournament is March 3rd. I just need any type of program to get the robot to go straight. Our robot tends to veer to the right. I prefer to use the gyro. But, I have no idea of how to do this.


#18

Are you making extra work for yourself with the gyro? I would first take a close look at the drivetrain and find why it’s veering. Are the tires scrubbing on the frame? Are the tires worn? You could swap left/right tires and see if it reverses the veer, and if so, then mix/match till it goes away.

Or maybe compensate for the veer using a minor speed adjustment in the code.


#19

We actually placed plates between the drivetrain and the wheels to make it go straighter. It just seems to me that since the gyro acts pretty precise when making turns, it would be great to make it go straight. I just don’t know how to program it with modkit.
VEX 3C.jpg


#20

My experience w/ gyro is mixed. It also tends to wander some…