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!
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.
Thanks for the help! It works fine when turning to the right, but loses its way when the line turns to the left. Suggestions?
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!
Here’s our code and a video of its behavior.
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.
- use a black line instead of blue so that the contrast between light and dark is greater
- double the thickness of the black line so that the robot has more time to detect it as it sweeps over the line
- slow the robot down a bit
- “calibrate” the threshold for the line using the technique in my previous post if you have not already done so
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.
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?
It would be in the drivetrain. You wouldn’t need anything in the colour sensor tab for the above example.
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.
You may need to adjust the thresholds, different surfaces have different reflectivity and thus provide varying brigthness readings.
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.
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.
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.
That follow the black line program looks great. But, I would need to see the Modkit code to see how to do it.
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.
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.
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.
My experience w/ gyro is mixed. It also tends to wander some…