Search Engine Submission - AddMe TRUE-BUS: Oktober 2009

Selasa, 06 Oktober 2009

PID ALGORITHM


PID ALGORITHM
Set position = 0 for run forward and set PWM L= R = constant
Set position = -5 and that robot restrains for turn left have to set left medium slow or medium decrease and set right medium fast or medium increase .
Position =-5 for run L is medium decrease and R is medium increase.
Else hand, Set position = 5 and that robot restrains for turn right have to set left medium fast or medium increase and set right medium slow or medium decrease .
Position = 5 for run L is medium increase and R is medium decrease.

Set position =-10 and that robot restrains for turn left have to set left very slow and set right very fast.
Position =-10 for run L is very slow and R is very fast.
Else hand, Set position = 10 and that robot restrains for turn right have to set left very fast and set right very slow.
Position = 10 for run L is very fast and R is very slow.

Position =-15 to left and position =15 to right, set in memory SRAM after build left motor backward and right motor forward on condition turn left. And for turn right is opposite this condition.

PIDsensors(){
switch(sensor){
case 0b01000000: position=-10; break;

case 0b00110000: position=-5; break;
case 0b00011000: position=0; break;
case 0b00001100: position=5; break;

case 0b00000010: position=10; break;
}
int proportional = ((int)position); // The "proportional" term should be 0 when we are on the line.
int derivative = proportional - last_ proportional; // Compute the derivative
integral += proportional; //integral (sum) of the position.
last_proportional = proportional; // Remember the last position.
P=kp*proportional;
I=Ki*integral;
D=Kd*derivative;
// Compute the difference between the two motor power settings, m1 - m2. If this is a positive number //the robot will turn to the right. If it is a negative number, the robot will turn to the left, and the //magnitude of the number determines the sharpness of the turn.
Power=P+I+D;
L=max + power;
R=max - power;
Set _motors(L,R);
}


While(1){
Read _sensors(); // Get the position of the line.
PIDsensors(); // get PWM value for motors
}


-          BELAJAR MIKROKONTROLLER : HOME
-          MEMBUAT DOWNLOADER USB SENDIRI
-          DASAR SIMULASI PROTEUS 7
-          CODEVISION AVR / CVAVR
-          MIKROKONTROLER
-          BILANGAN HEXADESIMAL
-          BILANGAN DIGITAL
-          PID ALGORITM / ALGORITMA PID
MEMBUAT ROBOT LINE FOLLOWER

Senin, 05 Oktober 2009

LINE FOLLOWER IS EASY TO MAKE

LINE FOLLOWER IS EASY TO MAKE

Specification:
Microcontroller ATmega16 with 16 kbyte flash, 512 byte EEPROM and 1kbyte SRAM or ATmega8535 with 8 kbyte flash, 512 byte EEPROM and 1 kbyte SRAM have 8 channel 10 bit A/D converter
12 Mhz or 16 Mhz crystal ( the ATmega experience is good on 16 Mhz )
4 push on are connected on PD 4-7 as input pull-up
LCD LM016 2x16 display characters is connected on PB as output set to LCD configuration are there too.

Pin LCD number 15 is connected to VCC or 5 volt and number 16 is connected to PORTB 3 as output set on high.
LED LCD on if PORTB.3 = 0
LED LCD off if else it
Photodiodes and infrareds are connected with PINA as ADC.
ADC value are gotten from reading photodiode as H/L on white/black on track. A/D converters are activated too with thick ADC ENABLE and USE 8 bit then chose clock to 750 Khz and ADC reference (V.ref ) on AVCC or AREF pin, therefore AVCC and AREF is connected with power high logic.
Read_ADC(); is already to use.
Reading sensor:
You have to insert a ADC variable to reverence of reading sensors 8 bit an example X variable. Cause x use 8 bit so you must set to unsigned char.
Unsigned char x;
Being easy and simple take this var on array.
Unsigned char x[8];
Building the C codes

n=0;
While (n==8){
n++;
sample=read_adc[n];
if (sample<255){ l="sample;}">0){
H=sample;}
x[n]=(((H[n]-L[n])/2)+L[n]);
delay_ms(10);}


Then saving ADC ref value on EEPROM or on SRAM
The values keep better in EEPROM than SRAM because with just 1 time to looks for reference ADC values and not necessary any time here to update values ADC reverence.
Making bit or scan sensors bit manipulation
n=0;
While(n==8){
n++;
If (read adc(n)>x[n]){sensor=sensor+2n;}
delay _us(50);}
sprint(buff,”<%x>”,sensor)
lcd_gotoxy(0,1);lcd_puts(buff);

Motor drivers is connected on PORTD 0-3. Motor drivers contain of two H-bridge transistor set in IC ld298 or make yourself this H-bridge from FET / TR. You must necessary to chose FET / TR so it works not better expected. Chose the FET or TR with low resistance , that can constrain current leave to motors.
The motors can run CW or CCW from generating PWM on timer set. Generating PWM can use time 0 / 2 interrupt overflow or time 1 16 bit too.
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{/*xcount++;
if (xcount<=lpwm) //on gedex blog ( gedex PID ) enki=1; //6 pin include ENABLE L&R else enki=0; if (xcount<=rpwm) enka=1; else enka=0; TCNT0=0xFF;*/ counter++; if (counter>=L){ //good performance
Lback=1;} //4 pin without ENABLE
else{ Lback=0;}
if (counter>=R){
Rback=1;}
else{ Rback=0;}
OCR0=0xff;}

H bridge FET driver search on this ( using keywords ).
ISP PROGRAMER.
PORTC is unused , you can configure to other control function such as sensors affix with comparator, wheel encoder, sensors ON/OFF control with super bright led can allowed you want.
-

-          BELAJAR MIKROKONTROLLER : HOME
-          MEMBUAT DOWNLOADER USB SENDIRI
-          DASAR SIMULASI PROTEUS 7
-          CODEVISION AVR / CVAVR
-          MIKROKONTROLER
-          BILANGAN HEXADESIMAL
-          BILANGAN DIGITAL
-          PID ALGORITM / ALGORITMA PID
MEMBUAT ROBOT LINE FOLLOWER