Grid follower using PIC16

Discussion in 'The Projects Forum' started by pvithra.18, Sep 14, 2012.

  1. pvithra.18

    Thread Starter New Member

    Sep 14, 2012
    1
    0
    I hav been trying to implement simple gird follower algortihms using pic16, but even thourgh i can make the robot turn left right and 180 withour conditions, when i put up restrictions according to node count the program doesnt work. The robot is not being able to count the node. is there a solution?
    Here is one of my trial codes which asks the bot to move straight till the 3rd node and then turn right. All it does is go straight.Below main i have also described functions for left and right turns altho i havent used them, they are what i would potentially be using if my bot starts to count nodes


    Code ( (Unknown Language)):
    1.  
    2. #include<htc.h>
    3.  
    4. __CONFIG(0x2F0A);
    5. void delay(unsigned char time)
    6. {
    7.     unsigned char pause;
    8.     while(time>0)
    9.     {
    10.         pause =255;
    11.         while(pause--);
    12.         time--;    
    13.     }    
    14. }
    15. void go_straight();
    16. void turn_right();
    17. void turn_left();
    18. void turn180();
    19. #define left RB6
    20. #define centre RB7
    21. #define right RB5
    22. #define motor PORTD
    23.  
    24. int turn=0;
    25.  
    26. void main()
    27. {
    28.  
    29.     TRISB=0xFF;
    30.     TRISD=0x00;
    31.     PORTB=0x00;
    32.     RBPU=1;// disabling pull up resistors
    33.  
    34.     unsigned char x=0,y=0;
    35.    
    36.    
    37.     while(1)
    38. {
    39.    
    40.     if(centre==1 && left==0 && right==0)
    41.     {
    42.         motor=0x90;
    43.     }
    44.     if(centre==0 && left==0 && right==0)
    45.     motor=0xA0;
    46.     if(centre==1 && left==1 && right==1)
    47.     {
    48.         y++;
    49.         if(y==3)
    50.         {
    51.         motor=0x80;
    52.         do
    53.         {
    54.             motor=0x80;
    55.         }while(!(centre==1 && left==0 && right==0));
    56.        
    57.         }
    58.         motor=0x00;
    59.     else
    60.         {
    61.             motor=0x90;
    62.             delay(100);
    63.         }
    64.    
    65.    
    66. }        //end of main
    67.  
    68.                             void turn180() //one time use
    69.                             {
    70.                                
    71.                                 //180 deg turn
    72.                                 while(turn!=17)
    73.                                 {      
    74.                                
    75.                                     motor=0xA0;
    76.                                     delay(5000);
    77.                                     motor=0x00;
    78.                                     turn++;
    79.                                
    80.                                    
    81.                                 }
    82.                                 motor=0x00;
    83.                                    
    84.                             }
    85.        
    86.      
    87.  
    88. void go_straight()
    89. {        
    90.     int c=1;
    91.     while(c==1)
    92. {
    93. if(centre==1 && left==0 && right==0)
    94. {  c=1;
    95.         motor=0x90;
    96. }
    97. else{c=0; motor=0x00;}
    98. }
    99. //motor=0x00;
    100. }
    101.  
    102.        void turn_right()
    103. {
    104. while(1)
    105. {
    106. motor=0xA0;
    107.  
    108. if(centre==1 && left==0 && right==0)
    109. break;
    110. }
    111. motor=0x00;
    112. }
    113.  
    114. void turn_left()
    115. {
    116. motor=0x50;
    117. if(centre==1 && left==0 && right==0)
    118. motor=0x00;
    119. }
    120.  
     
    Last edited by a moderator: Sep 15, 2012
  2. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    please use code tag "#" to enclose you program codes. It would be easier for others to read.
     
  3. upand_at_them

    Active Member

    May 15, 2010
    246
    29
    Go through and reformat your program and you'll see that you have functions embedded in main(). Watch your braces.
     
Loading...