Pages: [1]   Go Down
Author Topic: help with my line guiding robot with 5 ir line tracking sensors plzz  (Read 1251 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

heyy im a srilankan student studying in china and recently started working with arduino i did my first project with line guiding with 3 sensors it works perfect and i advanced it to 5 sensors 3 in the front and 2 first and the last one little back the code is


#define EN1  6
#define EN2  5
#define IN1  7
#define IN2  4

#define FORW 1
#define BACK 0
#define DF_LT_r1 2
#define DF_LT_r 12
#define DF_LT_c 11
#define DF_LT_l 10
#define DF_LT_l1 1


#define MOD_SEL 9



void Motor_Control(int M1_DIR,int M1_EN,int M2_DIR,int M2_EN)
{
  //////////M1////////////////////////
  if(M1_DIR==FORW)
    digitalWrite(IN1,HIGH);
  else
    digitalWrite(IN1,LOW);
  if(M1_EN==0)
    analogWrite(EN1,LOW);
  else
    analogWrite(EN1,M1_EN);
  ///////////M2//////////////////////
  if(M2_DIR==FORW)//M2
    digitalWrite(IN2,HIGH);
  else
    digitalWrite(IN2,LOW);
  if(M2_EN==0)
    analogWrite(EN2,LOW);
  else
    analogWrite(EN2,M2_EN);
}
void setup()
{
}
void loop()
{
  int L_LT,C_LT,R_LT,L1_LT,R1_LT;
  int L_Val,C_Val,R_Val,L1_Val,R1_Val;
  if(LOW == digitalRead(MOD_SEL))

while(1)

    {
         

      L1_LT=digitalRead(DF_LT_r1);
      L_LT=digitalRead(DF_LT_r);
      C_LT=digitalRead(DF_LT_c);
      R_LT=digitalRead(DF_LT_l);
      R1_LT=digitalRead(DF_LT_l1);
      delay(10);
     L1_Val=digitalRead(DF_LT_r1);
     L_Val=digitalRead(DF_LT_r);
      C_Val=digitalRead(DF_LT_c);
      R_Val=digitalRead(DF_LT_l);
     R1_Val=digitalRead(DF_LT_l1);
     
      if(L1_LT==L1_Val&& L_LT==L_Val&&C_LT==C_Val&&R_LT==R_Val&&R1_LT==R1_Val)
     
      {
        if(C_LT==LOW&& L_LT==HIGH && R_LT==HIGH&& L1_LT==HIGH && R1_LT==HIGH)
       
        {
         
          Motor_Control(FORW,150,FORW,150);
         
        } 
       
      else if (L1_LT==HIGH && L_LT==LOW&& C_LT==LOW&& R_LT=LOW&&R1_LT==HIGH)
        {
         
          Motor_Control(BACK,200,FORW,200);
        }
        else if(L1_LT==LOW&& L_LT==HIGH&& C_LT==LOW&& R_LT=HIGH&&R1_LT==LOW)
        {
         
          Motor_Control(FORW,150,FORW,150);
        }


        else if(L_LT==LOW &&(C_LT== HIGH||C_LT==LOW)&& R_LT==HIGH&& L1_LT==HIGH&& R1_LT==HIGH)
        {
         
          Motor_Control(BACK,150,FORW,150);
        }
        else if(R_LT==LOW &&(C_LT== HIGH||C_LT==LOW) &&R1_LT==HIGH && L_LT==HIGH&& L1_LT==HIGH)
        {
         
          Motor_Control(FORW,150,BACK,150);
        }
              else if(L1_LT==LOW &&(L_LT== HIGH||L_LT==LOW)&& R_LT==HIGH&& C_LT==HIGH&& R1_LT==HIGH)
        {
         
          Motor_Control(BACK,200,FORW,200);
        }
        else if(R1_LT==LOW &&(R_LT== HIGH||R_LT==LOW) &&R_LT==HIGH && C_LT==HIGH&& L1_LT==HIGH)
        {
         
          Motor_Control(FORW,200,BACK,200);
        }

        else if(R_LT==HIGH&&C_LT== HIGH&& L_LT==HIGH&& R1_LT== HIGH&& L1_LT==HIGH)
        {
         
          Motor_Control(FORW,100,BACK,100);
          delay(10);
        }
          else  Motor_Control(FORW,0,BACK,0);
        delay(20) ;
      }
    }
    } 
 but

else if (L1_LT==HIGH && L_LT==LOW&& C_LT==LOW&& R_LT=LOW&&R1_LT==HIGH)
        {
         
          Motor_Control(BACK,200,FORW,200);
        }

it gives me a compiling error AS Ivalue required as left operand assignment tried to fix it its going no where your help is highly appreciated please help me fix it  since i ve no one to ask here thankyou!
best regards ,
biman
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25884
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
R_LT=LOW
I'd guess right there.


When posting code, please use a code box by clicking on the # icon on the editor's toolbar, and pasting your code between the tags.
You can (and should) go back to your post, click on "modify", highlight your code, then click on the # icon on the toolbar, then click "save".

Why is "setup" empty?

Your code could be considerably simpler if you took the time to combine the individual bits read into numbers, either using "bitWrite" or mask and shift operations.

Code:
  if(M1_EN==0)
    analogWrite(EN1,LOW);
  else
    analogWrite(EN1,M1_EN);
That's a bit verbose; lose the "if/else" and just write M1_EN to EN1.
« Last Edit: August 05, 2011, 08:26:29 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thankyou so much i didnt notice it !it works now
I ll follow tour advice form now on when posting a code
thank you again!
 its really reliving to know i can get online help as language barrier in beijing is way too intense for a student
 best regards,
Biman
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25884
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still concerned about the emptiness of "setup", particularly with respect to IN1 and IN2
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
im working on the setup, i ll look in to it but buddy there is another small problem when it comes to an intersection i tried to sole it by using this code
Code:
[code]if(C_LT==LOW&&L_LT==HIGH&&R_LT==HIGH&&L1_LT==HIGH&&R1_LT==HIGH||L1_LT==LOW&& L_LT==HIGH&& C_LT==LOW&& R_LT==HIGH&&R1_LT==LOW)
        
        {
          
          Motor_Control(FORW,150,FORW,150);
          
        }
 [/code] but it doesn't work can you help me figure it out if I name the sensors as 12345 well if high is 1 and low is 0 i programmed it like just before the intersection  [11011] go forward or wehn passing the intersection [01010] forward i hope you  get what i wrote
thanks a bunch
« Last Edit: August 05, 2011, 09:06:18 am by biman » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25884
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you read what I wrote about using "bitWrite" earlier?

Did you also read the bit about going back to your original post, clicking "modify" etc ?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i did the modify part ,well bitWise means simplifying the code as the example you gave me right ?I'm new to arduino i ll try to rewrite the code according to your instructions thanks.
did you get my problem in the last post
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25884
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int readSense ()
{
  return digitalRead(DF_LT_r1) << 4 |
         digitalRead(DF_LT_r)  << 3 |
         digitalRead(DF_LT_c)  << 2 |
         digitalRead(DF_LT_l)  << 1 |
         digitalRead(DF_LT_l1);
}

(or possibly vice-versa)

Quote
i did the modify part
So why isn't the code in your original post in a code box?
« Last Edit: August 05, 2011, 09:15:55 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: