#include <QTRSensors.h>
const int PWMA = 9;
const int AIN2 = 8;
const int AIN1 = 7;
const int PWMB = 3;
const int BIN2 = 4;
const int BIN1 = 5;
const int STANDBY = 6;
const int LED = 13;
int P = 0;
int I = 0;
int D = 0;
int LAST = 0;
float vel;
int VelMax = 83;
float Kp = 0.0901;
int Kd = 1.0;
int Ki = 0.00105;
#define NUM_SENSORS 8
#define NUM_SAMPLES_PER_SENSOR 1
#define EMITTER_PIN 11
QTRSensorsAnalog qtra((unsigned char[]) {A7, A6, A5, A4, A3, A2, A1, A0}, NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
unsigned int position = 0;
void loop() {
qtra.read(sensorValues);
position = qtra.readLine(sensorValues, QTR_EMITTERS_ON, 0);
P = position - 3500;
D = P - LAST;
I = P + LAST;
vel = (P * Kp) + (D * Kd) + (I * Ki);
}
Código copiado al
portapapeles.