2

Author Topic: Line follower code  (Read 3377 times)

0 Members and 1 Guest are viewing this topic.

Offline saba_rish91Topic starter

  • Jr. Member
  • **
  • Posts: 25
  • Helpful? 0
Line follower code
« on: August 23, 2012, 11:20:05 AM »
Hi,

I built a line following robot and it didn't come out well. Can someone upload the code of line follower with and without PID control for reference? (Preferably Arduino code)


Thanks in Advance.
Strike when the iron is hot!

Offline dunz

  • Beginner
  • *
  • Posts: 3
  • Helpful? 1
Re: Line follower code
« Reply #1 on: August 25, 2012, 06:33:59 PM »
I'll share my linefollow-code with and without PD-control

With PD-control
Without PD-control

Offline saba_rish91Topic starter

  • Jr. Member
  • **
  • Posts: 25
  • Helpful? 0
Re: Line follower code
« Reply #2 on: August 25, 2012, 08:54:39 PM »
I'll share my linefollow-code with and without PD-control

With PD-control
Without PD-control


Thanks a lot!
Strike when the iron is hot!

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 269
  • Helpful? 12
Re: Line follower code
« Reply #3 on: August 27, 2012, 10:37:16 AM »
How many sensors do you have and what kind are they? It makes a big difference.
Code: [Select]
// taskControl
// This task runs in parallel to taskBalance.  This task monitors
// the optical and ultrasonic sensors and sets the global variables motorControlDrive
// and motorControlSteer.  Both of these values are in degrees/second.
//
task taskControl()
{
  Follows(main);

  char pfData[8];


  while(true) {
 
     LightSignal = SensorNormalized(LIGHT_SENSE);
     LightSignalPrev = LightSignalBar;
     // calculate filtered value of light signal for Deriv. control.
     LightSignalBar = FCTRACKING*LightSignal + (1.0-FCTRACKING)* LightSignalBar;
     
     // derivitive of light signal
     LightSignalDeriv = KDTRACKING*(LightSignalBar - LightSignalPrev);
     LightSignalErr =  (LightSignal - LIGHT_TARGET);
     LightSignalInt +=  KITRACKING*LightSignalErr;
     
      NumOut(50, LCD_LINE6, LightSignal);
     
    // change over to use ultrasonic sensor for object detection
    // stop when object detected - later on we can add u turn after timeout
    // JMK
     ObjectDistance = SensorUS(ULTRASONIC_SENSOR);

    if (ObjectDistance < MIN_DISTANCE) {
    // stop here.
        motorControlDrive = 0;
        motorControlSteer = 0;
         }
       else {
    // Set control Drive and Steer.  These are in motor degree/second
    // KPTRACKING  proportional gain for line following mode
    // KITRACKING  Integral gain for line following mode
    // KDTRACKING  Derivitive gain for line following mode - currently set = 0
    // FCTRACKING  filter constant for derivitive gain


    motorControlDrive = NOM_SPEED;
    motorControlSteer = (KPTRACKING * LightSignalErr )+ LightSignalDeriv + LightSignalInt
                         ;
    // Turn left if the intensity is too low, right if it is too high.
         }



    //Wait(CONTROL_WAIT);
  }
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

 


Get Your Ad Here