So …
before I was not use the “readline” but, QTR_read, and yes it worked … with the function readLine, I hoped to get a value of all sensors, Why not get?
another question, I already explained this question before, but got no concrete answer …
pololu.com/docs/0J19/3
# if (sensors[0] > 750 && sensors[1] > 750 && sensors[2] > 750)
# {
# // do something. Maybe this means we're at the edge of a course or about to fall off a table,
# // in which case, we might want to stop moving, back up, and turn around.
# return;
# }
this code fragment is for what exactly?, what I understood (and I put in my code) is that the sensors the sensors that I put this piece of code that are “must be seeing black” because they are the I wish to see the line, and only when they are to see the black line engines are on the maximum speed, ie only when the sensors see the black line there is no error, you see?, I am right or wrong about my thinking?, if you’re wrong can correct me?
img339.imageshack.us/i/dsc09373r.jpg/
#include <PololuQTRSensors.h>
PololuQTRSensorsRC qtr((unsigned char[]) {9,8,7,6,5,4,3,2}, 8);
int motor_right = 9;
int motor_left = 10;
//variaveis auxiliares.
int ltarguetval = 0;// valor a desejar no motor left.
int rtarguetval = 0;// valor a desejar no motor right.
int lnowval = 0; // valor actual no motor left.
int rnowval = 0; // valor actual no motor right.
void setup(){
Serial.begin(9600);
pinMode (motor_right, OUTPUT);
pinMode (motor_left, OUTPUT);
int i;
for (i = 0; i < 250; i++)
{
qtr.calibrate();
delay(20);
}
}
void loop(){
unsigned int sensors [8];
int position = qtr.readLine(sensors);
int error = position -1000;
int lastError = 0;
int maxspeed = 130;
double KP = 0.1;
int KD = 5;
int motorspeed = KP * error + KD * (error - lastError);
lastError = error;
Serial.print (qtr.readLine (sensors));
delay(500);
if(sensors[3] > 750 && sensors[4] > 750)
{
return;
}
if (error = 0){
rtarguetval = (int)maxspeed;
ltarguetval = (int) maxspeed;
}
else if (error < 0 ){
rtarguetval = (int)motorspeed;
error = lastError;
}
else if ( error > 0){
ltarguetval = (int)motorspeed;
error = lastError;
}
}
I leave here a picture of my circuit, but and its programming code (does not work, engines or she moves), the integrated I am using to control the DC motors is the L293D, and I want to do is the code: when two sensors are using to see the black line (sensor 3 and 4) both engines turning at full speed, if that does not happen, one of the engines will slow (or very little, depending on the error) so that the robot can make the turn in a “perfect”.
if I can help I would be very grateful.