Daha fazla
- Sistem Özellikleri
- Excalibur g770 İ7 9750H GTX 1050 16 gb ram 500 gb 970 evo plus 1tb toshiba hdwl110
- Cinsiyet
- Erkek
- Meslek
- Öğrenci
Çizgi izleyen robotumuz çizgiyi takip etmiyor.
C++:
// kodu çalıştırmadan önce QTR Kütüphanesini bilgisayarınıza yükleyiniz.
#include <QTRSensors.h>
#define sagtabanhiz 100 // sağ motor hızı: 0 ile 255 arası ayarlanabilir.
#define soltabanhiz 100 // sol motor hızı : 0 ile 255 arası ayarlanabilir.
#define sagmotoryon 12
#define sagmotorpwmpin 3
#define solmotoryon 13
#define solmotorpwmpin 11
#define mz80 10
unsigned long zaman=0;
QTRSensorsRC qtrrc((unsigned char[]) { A5, A4, A3, A2, A1 , A0, 2, 4} ,8, 2000, QTR_NO_EMITTER_PIN);
unsigned int sensorValues[8];
void setup()
{
pinMode(sagmotoryon, OUTPUT);
pinMode(sagmotorpwmpin, OUTPUT);
pinMode(solmotoryon, OUTPUT);
pinMode(solmotorpwmpin, OUTPUT);
pinMode(mz80, INPUT);
int i;
digitalWrite(3,LOW);
digitalWrite(11,LOW);
digitalWrite(mz80,HIGH);
for (int i = 0; i < 200; i++)
{
if ( 0 <= i && i < 5 ) hafifsagadon();
if ( 5 <= i && i < 15 ) hafifsoladon();
if ( 15 <= i && i < 25 ) hafifsagadon();
if ( 25 <= i && i < 35 ) hafifsoladon();
if ( 35 <= i && i < 45 ) hafifsagadon();
if ( 45 <= i && i < 55 ) hafifsoladon();
if ( 55 <= i && i < 65 ) hafifsagadon();
if ( 65 <= i && i < 75 ) hafifsoladon();
if ( 75 <= i && i < 85 ) hafifsagadon();
if ( 85 <= i && i < 90 ) hafifsoladon();
if ( i >= 90 ) {frenle(); delay(8);}
qtrrc.calibrate();
delay(4);
}
delay(800);
Serial.begin(9600);
}
int sonhata = 0;
float Kp = 0.6;//0.15 PID AYARLARIDIR . Detaylı kullanım için PID kontrolünü araştırın.
float Kd = 1;//1.5 PID AYARLARIDIR . Detaylı kullanım için PID kontrolünü araştırın.
int sagmotorpwm = 0;
int solmotorpwm = 0;
void loop()
{
unsigned int sensorValues[8];
unsigned int position = qtrrc.readLine(sensorValues,1);
int hata = position-3500;
//Serial.println(hata);
/*Serial.print(sagmotorpwm);
Serial.print(" - ");
Serial.println(solmotorpwm);*/
if((hata>1600&&hata<2400))
{
Kp = 0.95;//0.15
Kd = 1.8;//1.5
motorkontrol(-200,-200);
delay(100);
zaman=millis();
}
else if(millis()<zaman+2000)
{
Kp = 0.95;//0.15
Kd = 1.8;//1.5
}
else
{
Kp = 0.45;//0.15
Kd = 1.8;//1.5
}
while (digitalRead(mz80)==LOW) {motorkontrol(0,0);}
int duzeltmehizi = Kp * hata + Kd*(hata - sonhata);
sonhata = hata;
sagmotorpwm = sagtabanhiz - duzeltmehizi ;
solmotorpwm = soltabanhiz + duzeltmehizi ;
sagmotorpwm = constrain(sagmotorpwm, -100, 110); ///// Burada motorlara uygulanacak PWM değerlerine sınırlandırma getirilmiştir.
solmotorpwm = constrain(solmotorpwm, -100, 110);
motorkontrol(sagmotorpwm,solmotorpwm);
}
void motorkontrol(int sagmotorpwm, int solmotorpwm){
if(sagmotorpwm<=0) {
sagmotorpwm=abs(sagmotorpwm);
digitalWrite(sagmotoryon, HIGH);
analogWrite(sagmotorpwmpin, sagmotorpwm);
}
else {
digitalWrite(sagmotoryon, LOW);
analogWrite(sagmotorpwmpin, sagmotorpwm);
}
if(solmotorpwm<=0) {
solmotorpwm=abs(solmotorpwm);
digitalWrite(solmotoryon, HIGH);
analogWrite(solmotorpwmpin, solmotorpwm);
}
else {
digitalWrite(solmotoryon, LOW);
analogWrite(solmotorpwmpin, solmotorpwm);
}
}
void frenle(){motorkontrol(0,0);}
void hafifsagadon(){motorkontrol(-50,50);}
void hafifsoladon(){motorkontrol(50,-50);}
Son düzenleyen: Moderatör: