Line Following

Share your awesome Ringo behaviors here!
User avatar
sil
Posts: 39
Joined: Thu Oct 01, 2015 1:04 am

Line Following

Postby sil » Wed Feb 03, 2016 8:23 pm

I got inspired recently to play with the line following capabilities of Ringo and exploring his sensors. I avoiding looking at the example code until I had my own working code and both essentially do the same basic motion. I tested both on a couple of tracks made with black electricians tape and found mine would complete more laps reliably. Its a good learning exercise to go through and learn how and why Ringo behaves (or not).

I'm moving on to other ideas of racing with Ringos and thought I should post my line following code. This I'm confident is robust to work. There is room for tweaking speed for your own tracks and find your own improvements. Hope this help someone out there, I'm just learning like many of you.


Code: Select all

/*

sil-line_follow_03
Line Follow by Steve Bolton
if you base your code on mine please leave my name in place and share on the plumgeek forum for others to learn from.


A simple but robust line follow code runs well on an oval circuit using black electricians tape on a white topped desk.
Its meant to run on a surface straddling a line made of black tape though it can work with a 15mm line of black paint.
it runs straight but if it drifts the eyes detect the line and it readjusts.
Work best on a 50cm wide circular track, hard corners are a problem


*/

#include "RingoHardware.h"

/* set up hardware */
void setup(){
  HardwareBegin();        //initialize Ringo's brain to work with his circuitry
  PlayStartChirp();       //Play startup chirp and blink eyes
  SwitchMotorsToSerial(); //Call "SwitchMotorsToSerial()" before using Serial.print functions as motors & serial share a line
  SwitchButtonToPixels();
  RestartTimer();
  delay(2000);         // 2 sec delay before start
}

/* declare variables */
int leftOn, leftOff, rightOn, rightOff, rearOn, rearOff; int leftDiff,rightDiff, rearDiff; int speedleft, speedright;

void loop(){

 digitalWrite(Source_Select, LOW);  //select underside light sensors

 digitalWrite(Edge_Lights, HIGH);   //turn on IR light sources
 delayMicroseconds(500);            //let sensors stabilise

 leftOn = analogRead(LightSense_Left);
 rightOn = analogRead(LightSense_Right);  rearOn = analogRead(LightSense_Rear);
  SetAllPixelsRGB(0, 0, 0); //all lights off


 //set default speed of 50
speedleft = 50;
speedright = 50;

Motors(speedleft, speedright);

 // use Motors() to turn using multiplier

      if (leftOn < 250)
      {
      SetPixelRGB( 5, 0, 50, 0);
        Motors(speedleft, speedright*3);
      }
      if (rightOn < 250)
      {
      SetPixelRGB( 4, 0, 50, 0);
        Motors(speedleft*3, speedright);
      }
      if (rearOn < 250)
      {
      SetPixelRGB( 0, 0, 50, 0);
      }
}


Return to “Ringo Code Share”

Who is online

Users browsing this forum: No registered users and 1 guest