Project 2: Line following bot

By | April 29, 2013

Release Candidate
Very hard to keep it steady as voltage increases. That’s the best speed/stability result I got so far. Now using 3 sensors.
The video below has it running at about 6V.


Test 1
With differential steering


This is the project in a very early stage with a regular RC toy steering mechanism.

Using 2 IR sensors to detect change in color and correct direction. It’s pretty rough right now and it overshoots all the time. Not the best hardware… No word about software (don’t want to blame myself 🙂 )

Bare steering logic (RC toy version)

[code language=”cpp”]
void loop() {

valLeft = analogRead(clrLeft);
valRight = analogRead(clrRight);
Serial.print(valLeft);
Serial.print(“-“);
Serial.print(valRight);
error = valRight – valLeft;
Serial.print(“-“);
Serial.print(error);

if (valLeft < 940 && valRight < 940) // Definitely not over the black tape { if (lostTime == 0) { lostTime = millis(); } else { if (millis() > lostTime + 1000) // Lost for too long
{
moving = false;
analogWrite(mtrFwdPin,0); // Stop
lostTime = millis();
}
}
Serial.print(“-Lost:”);
Serial.print(lostTime);
Serial.print(“-ms:”);
Serial.print(millis());

}
else
{
lostTime = 0;
moveForward(130);

// It seems like PID algorithm is the way to go
// (when I get my motor for differential steering)
// Below a poor math man’s algorithm for a regular RC car steering mechanism
if (abs(error) > errorTarget)
{
if (error > 0)
{
digitalWrite(right,LOW);
digitalWrite(left,HIGH);

dir = “—<<-----"; } else { digitalWrite(left,LOW); digitalWrite(right,HIGH); dir = "----->>—“;
}

if (abs(error) < 8) { errorTarget = 60; // If it returned to the center allow for more tolerance } else { errorTarget = 7; // If it's off track seeks the best position (center) } } else { dir = "[--------]"; digitalWrite(left,LOW); digitalWrite(right,LOW); } } Serial.print("-"); Serial.print(dir); Serial.println(""); }void moveForward(int cSpeed) { if (moving) return; moving = true;analogWrite(mtrBkwPin,0); analogWrite(mtrFwdPin,250); //Break inertia delay(200);analogWrite(mtrFwdPin,cSpeed); // digitalWrite(mtrFwdPin,HIGH);}[/code]

One thought on “Project 2: Line following bot

Leave a Reply

Your email address will not be published. Required fields are marked *