Problem with line following robot


i wrote code line following robot , it's weird because right wheel of robot moves backwards , left wheel moves forward when it's supposed go forward. robot moves right , left properly(the wheels move how it's programmed to. i've used 2 infared receivers/transmitter modules. please tell what's wrong! 

look @ code:
code: [select]


int const rs = a0;
int const ls= a3;
#include <afmotor.h>
af_dcmotor r_motor(3);
af_dcmotor l_motor(4);
void setup(){
  serial.begin(9600);
  pinmode(rs, input);
  pinmode(ls, input);
 
}

void loop(){

  bool r_state = digitalread(a0);
  bool l_state = digitalread(a3);
 

      if((r_state == true) && (l_state == true)){
        strght();
      }
       if((r_state == true) && (l_state == false)){
        turn_right();
      }
       if((l_state == true) && (r_state == false)){
        turn_left();
      }
       if(l_state && r_state){
        stop();
      }
 
}

void strght(){
    l_motor.setspeed(200);
    r_motor.setspeed(200);
    r_motor.run(forward);
    l_motor.run(forward);
 
}

void turn_right(){
   
      r_motor.setspeed(200);
      l_motor.setspeed(200);
      r_motor.run(forward);
      l_motor.run(backward);
   }
void turn_left(){

    l_motor.setspeed(200); 
    r_motor.setspeed(200);
    l_motor.run(forward);
    r_motor.run(backward);
}

void stop(){
    l_motor.setspeed(0);
    r_motor.setspeed(0);
    r_motor.run(release);
    l_motor.run(release);
}
 

you both calling strght() , stop() if both buttons read true/high. 

you meant call stop() if both buttons false/low?


Arduino Forum > Using Arduino > Programming Questions > Problem with line following robot


arduino

Comments

Popular posts from this blog

Valutazione Template - Joomla! Forum - community, help and support

SD Datastring Convention

First use of Arduino Uno : avrdude error on Blink uploading