Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Need a help!line follower robot code


#1

Hello,I am took a code for ZUMO Line Follower robot from your site and I need some help.How can I remake your code in order to follow the WHITE lines?
HERE THIS CODE:

#include <QTRSensors.h>
#include <ZumoReflectanceSensorArray.h>
#include <ZumoMotors.h>
#include <ZumoBuzzer.h>
#include <Pushbutton.h>


ZumoBuzzer buzzer;
ZumoReflectanceSensorArray reflectanceSensors;
ZumoMotors motors;
Pushbutton button(ZUMO_BUTTON);
int lastError = 0;

const int MAX_SPEED = 400;


void setup()
{
  buzzer.play(">g32>>c32");

  reflectanceSensors.init();

  button.waitForButton();

  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  delay(1000);
  int i;
  for(i = 0; i < 80; i++)
  {
    if ((i > 10 && i <= 30) || (i > 50 && i <= 70))
      motors.setSpeeds(-200, 200);
    else
      motors.setSpeeds(200, -200);
    reflectanceSensors.calibrate();

    delay(20);
  }
  motors.setSpeeds(0,0);

  digitalWrite(13, LOW);
  buzzer.play(">g32>>c32");

  button.waitForButton();

  buzzer.play("L16 cdegreg4");
  while(buzzer.isPlaying());
}

void loop()
{
  unsigned int sensors[6];
  int position = reflectanceSensors.readLine(sensors);
  int error = position - 2500;

  int speedDifference = error / 4 + 6 * (error - lastError);

  lastError = error;

  int m1Speed = MAX_SPEED + speedDifference;
  int m2Speed = MAX_SPEED - speedDifference;
  if (m1Speed < 0)
    m1Speed = 0;
  if (m2Speed < 0)
    m2Speed = 0;
  if (m1Speed > MAX_SPEED)
    m1Speed = MAX_SPEED;
  if (m2Speed > MAX_SPEED)
    m2Speed = MAX_SPEED;

  motors.setSpeeds(m1Speed, m2Speed);
}

PID based line follower
#2

Hello.

To get your QTR sensors to detect a reflective surface surrounded by a darker surface (e.g. a white line on a black surface), you need to set the optional whiteLine argument to 1 when you call the readLine() method. The whiteLine argument is 0 by default to detect dark lines (e.g. black lines) surrounded by reflective (e.g. white) surfaces, but you can set it to 1 to invert what the method detects. To do this, you can rewrite

int position = reflectanceSensors.readLine(sensors);

as

int position = reflectanceSensors.readLine(sensors, QTR_EMITTERS_ON, 1);

-Jon


Qtr-8rc white line detection problem