Group Head:
Nurali Virani
moc.liamg|eriflanretti#moc.liamg|eriflanretti
09732932672
1st years:
1)Amaleshwar Sinha
2)Dhaval Prajapati
3)Pranav Patwardhan
4)Chinmay honrao
Documentation:
Components Used:
AVR Development board -1
TSOP Proximity sensors - 3
Stepper Motors - unipolar,12V,160mA -2
Stepper Wheels - 2
Wooden Stepper base with 2 ball castors
Microcontroller:
Atmega16L
Sensor Placement
one on each of left, front and right side of the bot
Algorithm:
Defined 3 modes of motion of the bot. Forward-1, left-3, right-2.
initially the bot starts with mode 1.
According to the algorithm, the bot starts from the leftmost part of the arena, mode is initially 1. Then when it encounters a wall in the front, it turns right and starts searching for the door, mode is set to 2. When it encounters the door, it takes a complete 90 turn and mode is set to 1. When it encounters the wall in the front again, it turns right by 90 and the mode is set to 2. The algo has kept the bot with a default to turn right whenever it encounters a wall in front. If it sees a dead-end, it should take a u-turn and start searching for the door on the right side.
There is an assumption that all the three sensors can never be high together.
One array called s[2] is defined, for 3 sensors.
s[i] =1 for high, 0 for low.
s[0]=left sensor
s[1] = front sensor
s[2] = right sensor
A mode variable is kept with the previously mentioned description.
The PSEUDO CODE
int s[2]; int mode =1; if(s[0]==0 && s[1]==0 && s[2]==0) { if(mode==1) {//forward motion} if(mode==2) {//complete left, set mode=1} if(mode==3) {//complete right,set mode=1} } if(s[0]==1 && s[1]==0 && s[2]==0) { //forward motion } if(s[0]==0 && s[1]==1 && s[2]==0) { if(mode==1){//complete right, set mode=2} if(mode==2){//complete left, set mode=1} if(mode==3){//complete right, set mode = 1} } if(s[0]==0 && s[1]==0 && s[2]==1) { //forward motion } if(s[0]==1 && s[1]==1 && s[2]==0) { if(mode==1){//complete right, set mode = 2} if(mode==2){//turn around, set mode = 3} } if(s[0]==0 && s[1]==1 && s[2]==1) { if(mode==1){complete left, set mode = 3} if(mode==3){//turn around, set mode = 2} } if(s[0]==1 && s[1]==0 && s[2]==1) { //forward motion }
Bot code:
#include <avr/io.h> #include<avr/interrupt.h> #define BIT(x) (1 << (x)) #define CHECKBIT(x,b) (x&b) //Checks bit status #define SETBIT(x,b) x|=b; //Sets the particular bit #define CLEARBIT(x,b) x&=~b; //Sets the particular bit #define TOGGLEBIT(x,b) x^=b; //Toggles the particular bit unsigned char value,hvalue,t=0,s=0; unsigned char halfB[8] = {8,9,1,5,4,6,2,10}; unsigned char fullB[4] ={1,4,2,8}; unsigned char halfD[8] = {8,9,1,5,4,6,2,10}; unsigned char fullD[4] ={128,32,64,16}; unsigned char h=0,f=0; unsigned int speed; void WaitMs(unsigned int ms); void init(); void forward(unsigned int steps); void backward(unsigned int steps); void zero_left(unsigned int steps); void zero_right(unsigned int steps); void main(void) { int i=0; init(); int s[2]; int mode =1; speed=200; ADCSRA = _BV(ADEN) | _BV(ADPS2); //Enable ADC with prescaler=16 while(1){ if(CHECKBIT(PIND,BIT(2))){} else{ while(1){ for(i=0;i<3;i++) { // Select pin ADC[0..3] using MUX ADMUX = _BV(ADLAR) + i; //Start conversion ADCSRA |= _BV(ADSC); // wait until converstion completed while (ADCSRA & _BV(ADSC) ) {} if(ADCH > 128 ){ s[i]=0; } //if value at the pin is greater than compare value else s[i]=1; } if(s[0]==0 && s[1]==0 && s[2]==0) { if(mode==1) {forward(1);}//forward motion} if(mode==2) {forward(40);zero_right(85);mode=1;forward(200);}//complete left, set mode=1} if(mode==3) {forward(40);zero_left(85);mode=1;forward(200);}//complete right,set mode=1} } else if(s[0]==1 && s[1]==0 && s[2]==0) { forward(1); //forward motion } else if(s[0]==0 && s[1]==1 && s[2]==0) { if(mode==1){zero_left(85); mode=2;}//complete right, set mode=2} if(mode==2){zero_right(85); mode=1;}//complete left, set mode=1} if(mode==3){zero_left(85); mode=1;}//complete right, set mode = 1} } else if(s[0]==0 && s[1]==0 && s[2]==1) { forward(1);//forward motion } else if(s[0]==1 && s[1]==1 && s[2]==0) { if(mode==1){zero_left(85); mode=2;}//complete right, set mode = 2} if(mode==2){zero_left(169);mode=3;}//turn around, set mode = 3} } else if(s[0]==0 && s[1]==1 && s[2]==1) { if(mode==1){zero_right(85); mode=3;}//complete left, set mode = 3} if(mode==3){zero_right(169);mode=2;}//turn around, set mode = 2} } else if(s[0]==1 && s[1]==0 && s[2]==1) { forward(1);//forward motion } } } } } //Rotate the stepper counter-clockwise in half Stepping mode void forward(unsigned int steps) { unsigned int j=0; for(j=0;j<steps;j++) { f++; h++; if(f>3) f=0; if(h>3) h=0; PORTB=fullB[f]; PORTD=fullD[h]; WaitMs(speed); } } //Rotate the stepper clockwise in half Stepping mode void backward(unsigned int steps) { unsigned int j=0; for(j=0;j<steps;j++) { f--; h--; if(f==255) f=3; if(h==255) h=3; PORTB=fullB[f]; PORTD=fullD[h]; WaitMs(speed); } } //Rotate the stepper counter-clockwise in full stepping mode void zero_right(unsigned int steps) { unsigned int j=0; for(j=0;j<steps;j++) { f--; h++; if(f==255) f=3; if(h>3) h=0; PORTD=fullD[f]; PORTB=fullB[h]; WaitMs(speed); } } //Rotate the stepper clockwise in full stepping mode void zero_left(unsigned int steps) { unsigned int j=0; for(j=0;j<steps;j++) { f++; h--; if(h==255) h=3; if(f>3) f=0; PORTD=fullD[f]; PORTB=fullB[h]; WaitMs(speed); } } /* waits (pauses) for ms milliseconds (assumes clock at 16MHz) */ void WaitMs(unsigned int ms) { int i; while (ms-- > 0) { /* 16380 (16k) clock cycles for 1ms; each time through loop is 5 cycles (for loop control + nop) */ for (i = 0; i < 327; ++i) asm("nop"); } } void init() { CLEARBIT(DDRD,BIT(2)) SETBIT(PORTD,BIT(2)) DDRD=0xF0; DDRB=0xFF; DDRC=0xFF; }
Problems Faced:
Low torque steppers: The first pair of stepper motors we encountered were of extremely low torque, they didn't move the bot at all.
The next set of steppers is the current one which has the rating 12V and 160 mA. This provided just enough torque for the bot to move. I would suggest using a motor with a much higher torque.





