# Line tracking with just two sensors

My robotics team at school tends not to be very strong in the autonomous portion of the competitions.
But this year they wanted to change that so they asked me to program their autonomous mainly because no one knew how
So I’m supposed to create a line tracking program
but a problem i came across is that we could only find 2 out of 3 sensors

How should i use what i have to make the program?
How far apart should the two sensors be?
And i was thinking about using an ultrasonic sensor to tell it to stop but we don’t have it yet. So do i use shaft encoders to tell it to stop after so many rotations?

Um i cant think of anything else rite now
Thanks for any help

well, for the part about only two tracking sensors, it’ll be tough, but do-able. how about you space the two as if they were the left and right, with space for the center, but you don’t have the sensor for the center. so, with the left and right, start with the line in the middle of the two sensors. then, when it starts, if one of the sensors detects the line, it moves in the direction opposite the side it was detected on. sorry for no code, but i am a novice programmer myself.

i havent figured out how to get the line between the two sensors that accurately

my team was going to score at the 15in goal and then move to line and follow it to the 9
but that means we cant place our robot on the line

Well to start with I’ll help you with the actual line tracking portion. The theory behind using tracking the line with 2 sensors is that if you see the line with the left sensor then the robot should turn left and if you see it with the right sensor then you need to turn a little left.

The setup:
-On your robot you will need to have the two sensors spaced appart so that the line should pass between them with only a little bit of space on either side. There should be about 1/4in of space between the ground and the sensor.

More Theory:
-In order to program you need to understand what the robot should do when a certain sensor sees the line. So…
**
The LEFT* Sensor:**
-IF the left sensor sees the line what does that mean? That means that the robot is turning to the right and is going to cross the line without any correction. So the robot should turn a little to the left to avoid crossing the line.

The RIGHT Sensor:
-Same thing as the left sensor. If the right sensor sees the line then the robot it turning to the left so it needs to correct it’s direction by turning a little right.

So now the actual code:
-What follows is psuedo code so it should help you guide you through the programming.

while(1)
{
LeftMotor(on)//turn both motors on
RightMotor(on)
Lsense=Input(LeftSensor)// get a value from the left sensor
Rsense=Input(RightSensor)// get a value from the right sensor
If(Lsense>100)//If you see the line with the left sensor
{
LeftMotor(off)//turn left by turning the left motor off
wait(50)//wait .5s for the to give time for the turn
}
ElseIf(Rsense>100)//If you see the line with the Right sensor
{
RightMotor(off)//turn Right by turning the Right motor off
wait(50)//wait .5s for the to give time for the turn
}
//then repeat it’s a while loop, until you don’t want it to repeat anymore.
}

Good Luck,

*left and right looking from the back of the robot.

Theres something i dont get

im not sure but i looked at some other person’s code
and it seems to me that when they turn the motor speeds are something plus a variable
and i havent been able to figure out where the variable’s value is acquired

do i need to worry about that?

thanks

first of all we need to know what program your using.
robotc? easyc? what?
they all have different usages and settings.

I can’t look at the code but I think I know what you are asking. When I said to turn the motors off to turn you can also change direction by speeding up the motor. If you want to speed up the motor it can’t be running at full speed to start with. The basic idea is that you need to slow down one side or speed up the other side to turn.

oh sorry im using easyc

yay my club found the other line tracker and ultra sound thanks guys