Hello, I get this error when I try to compile the code.
My idea was to build a Line-Follower and Obstacle Avoider at the same time.
I have to do this for a assignment at High-school and I can't solve this problem!
#include <QTRSensors.h>
#include <Ultrasonic.h>
#define KP 0.35
#define KD 7
#define M1_MAX_SPEED 200
#define M2_MAX_SPEED 200
#define M1_DEFAULT_SPEED 165
#define M2_DEFAULT_SPEED 165
#define MIDDLE_SENSOR A2, A3
#define NUM_SENSORS 6 // number of sensors used
#define TIMEOUT 2500 // waits for 2500 us for sensor outputs to go low
#define EMITTER_PIN 2 // emitter is controlled by digital pin 2
#define DEBUG 1 // set to 1 if serial debug output needed
#define rightMotor1 7
#define rightMotor2 8
#define rightMotorPWM 6
#define leftMotor1 10
#define leftMotor2 9
#define leftMotorPWM 5
#define motorPower 7
#define pino_trigger 13
#define pino_echo 12
QTRSensorsRC qtrrc((unsigned char[]) { A0, A1, A2, A3, A4, A5} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];void manual_calibration() {
int i;
for (i = 0; i < 250; i++) // the calibration will take a few seconds
{
qtrrc.calibrate(QTR_EMITTERS_ON);
delay(100);
}
if (DEBUG) { // if true, generate sensor dats via serial output
Serial.begin(9600);
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMinimumOn[i]);
Serial.print(' ');
}
Serial.println();
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMaximumOn[i]);
Serial.print(' ');
}
Serial.println();
Serial.println();
}
}void setup()
{
pinMode(rightMotor1, OUTPUT);
pinMode(rightMotor2, OUTPUT);
pinMode(rightMotorPWM, OUTPUT);
pinMode(leftMotor1, OUTPUT);
pinMode(leftMotor2, OUTPUT);
pinMode(leftMotorPWM, OUTPUT);
pinMode(motorPower, OUTPUT);
manual_calibration();
}
int lastError = 0;
int last_proportional = 0;
int integral = 0;void loop()
{
long duration, cm;pinMode(pino_trigger, OUTPUT);
digitalWrite(pino_trigger, LOW);
delayMicroseconds(2);
digitalWrite(pino_trigger, HIGH);
delayMicroseconds(10);
digitalWrite(pino_trigger, LOW);pinMode(pino_echo, INPUT);
duration = pulseIn(pino_echo, HIGH);
cm = microsecondsToCentimeters(duration);if (cm < 8) {
}
else {
unsigned int sensors[6];
int position = qtrrc.readLine(sensors);
int error = position - 2500;
int motorSpeed = KP * error + KD * (error - lastError);
lastError = error;
int rightMotorSpeed = M2_DEFAULT_SPEED + motorSpeed;
int leftMotorSpeed = M1_DEFAULT_SPEED - motorSpeed;
if (rightMotorSpeed > M1_MAX_SPEED ) rightMotorSpeed = M1_MAX_SPEED; // limit top speed
if (leftMotorSpeed > M2_MAX_SPEED ) leftMotorSpeed = M2_MAX_SPEED; // limit top speed
if (rightMotorSpeed < 0) rightMotorSpeed = 0; // keep motor above 0
if (leftMotorSpeed < 0) leftMotorSpeed = 0; // keep motor speed above 0
{
digitalWrite(motorPower, HIGH);
digitalWrite(rightMotor1, HIGH);
digitalWrite(rightMotor2, LOW);
analogWrite(rightMotorPWM, rightMotorSpeed);
digitalWrite(motorPower, HIGH);
digitalWrite(leftMotor1, HIGH);
digitalWrite(leftMotor2, LOW);
analogWrite(leftMotorPWM, leftMotorSpeed);
}