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
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
Rich (BB code):
#include<htc.h>
__CONFIG(0x2F0A);
void delay(unsigned char time)
{
unsigned char pause;
while(time>0)
{
pause =255;
while(pause--);
time--;
}
}
void go_straight();
void turn_right();
void turn_left();
void turn180();
#define left RB6
#define centre RB7
#define right RB5
#define motor PORTD
int turn=0;
void main()
{
TRISB=0xFF;
TRISD=0x00;
PORTB=0x00;
RBPU=1;// disabling pull up resistors
unsigned char x=0,y=0;
while(1)
{
if(centre==1 && left==0 && right==0)
{
motor=0x90;
}
if(centre==0 && left==0 && right==0)
motor=0xA0;
if(centre==1 && left==1 && right==1)
{
y++;
if(y==3)
{
motor=0x80;
do
{
motor=0x80;
}while(!(centre==1 && left==0 && right==0));
}
motor=0x00;
else
{
motor=0x90;
delay(100);
}
} //end of main
void turn180() //one time use
{
//180 deg turn
while(turn!=17)
{
motor=0xA0;
delay(5000);
motor=0x00;
turn++;
}
motor=0x00;
}
void go_straight()
{
int c=1;
while(c==1)
{
if(centre==1 && left==0 && right==0)
{ c=1;
motor=0x90;
}
else{c=0; motor=0x00;}
}
//motor=0x00;
}
void turn_right()
{
while(1)
{
motor=0xA0;
if(centre==1 && left==0 && right==0)
break;
}
motor=0x00;
}
void turn_left()
{
motor=0x50;
if(centre==1 && left==0 && right==0)
motor=0x00;
}
Last edited by a moderator: