hi everyone,
I bought a QTR8A and read Pololu QTR Sensor Functions int the pololu_avr_library.pdf. i am using pic18f452 in my project . there are some code example about PID.
int lastError = 0;
void loop()
{
unsigned int sensors[3];
int position = qtr_read_line(sensors, QTR_EMITTERS_ON);
int error = position - 1000;
int motorSpeed = KP * error + KD * (error - lastError);
lastError = error;
int m1Speed = M1 + motorSpeed;
int m2Speed = M2 - motorSpeed;
if (m1Speed < 0)
m1Speed = 0;
if (m2Speed < 0)
m2Speed = 0;
}
here my questions:
1-i am using 8 sensors. therefore, are this lines of the code true?
unsigned int sensors[8];
int error = position - 3500;
and how can error variable to be int? int can be 0-255 ??? (i am using compiler ccs c.)
2-int position = qtr_read_line(sensors, QTR_EMITTERS_ON);
i think this line means formula is
0*value0 + 1000*value1 + 2000*value2 + ...
--------------------------------------------
value0 + value1 + value2 + ...
is it true and i cant understand this formula??