hello !
first off all, ı’m sorry for my bad english
I want to make a robot following white line on a black surface. I use six of QTRx8A
sensors and arduino atmega328
pololu.com/docs/0J19/3 , i read this and functions are written. when I load program my arduino, my robot can follow line very well.
In arduino I used QTR-8a library and its codes. now I want to make a new robot using pic18f2550. but I have some problems :
1- I don’t know how I calibrate the sensors .
I can read sensors as analog and find maximum and minumum values for each sensor. but I don’t know how i find CALIBRATEDMAX AND CALIBRATEDMIN.
2- pololu.com/docs/0J19/3 in this document there is a formula for finding position
0*value0 + 1000*value1 + 2000*value2 + ...
--------------------------------------------
value0 + value1 + value2 + ...
to test this formula I looked at calibrated sensor values using arduino(serial monitor) , and used these values in this formula but I found difference results. my result and result on serial monitor (position) is not equal.
calibrated_max: 899 877 870 879 863 913
calibrated_min : 53 55 46 44 39 47
reading_sensor: 885 855 430 38 43 838
calibrated_sensor : 983 973 464 0 4 913
position =3243 when i calculate the position it is different
so i want to know whether the value(value0, value1…)in the formula is “calibrated_sensor value” !
my codes
#include <PololuQTRSensors.h>
#define NUM_SENSORS 6
#define NUM_SAMPLES_PER_SENSOR 6
#define EMITTER_PIN 12
PololuQTRSensorsAnalog qtra((unsigned char[]) {0, 1, 2, 3, 4, 5},
NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
void setup()
{
delay(500);
int i;
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
for (i = 0; i < 400; i++)
{
qtra.calibrate();
}
digitalWrite(13, LOW);
Serial.begin(9600);
for (i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtra.calibratedMinimumOn[i]);
Serial.print(' ');
}
Serial.println();
for (i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtra.calibratedMaximumOn[i]);
Serial.print(' ');
}
Serial.println();
Serial.println();
delay(1000);
}
void loop()
{
int i;
unsigned int position = qtra.readLine(sensorValues, QTR_EMITTERS_ON,1);
qtra.read(sensorValues, QTR_EMITTERS_ON);
for (i = 0; i < NUM_SENSORS; i++)
{
Serial.print(sensorValues[i]);
Serial.print(' ');
}
Serial.println();
qtra.readCalibrated(sensorValues, QTR_EMITTERS_ON);
for (i = 0; i < NUM_SENSORS; i++)
{
Serial.print(sensorValues[i]);
Serial.print(' ');
}
Serial.println();
Serial.println(position);
delay(250);
}