Carrito Seguidor de Línea Arduino
0:51
exit status 1
Compilation error: #include expects "FILENAME" or <FILENAME>
Cpp
#include <QTRSensors.h>
Cpp
#include "QTRSensors.h"
#include.Cpp
#include <QTRSensors.h> // Asegúrate de que la librería está instalada #define NUM_SENSORS 8 uint8_t sensorPins[NUM_SENSORS] = {A0, A1, A2, A3, A4, A5, A6, A7}; QTRSensors qtr; unsigned int sensorValues[NUM_SENSORS]; #define LEFT_MOTOR_PWM 3 #define LEFT_MOTOR_IN1 4 #define LEFT_MOTOR_IN2 5 #define RIGHT_MOTOR_PWM 6 #define RIGHT_MOTOR_IN1 7 #define RIGHT_MOTOR_IN2 8 int baseSpeed = 180; int maxSpeed = 255; double Kp = 0.15; double Ki = 0.0; double Kd = 0.5; double lastError = 0; double integral = 0; void setup() { Serial.begin(9600); pinMode(LEFT_MOTOR_PWM, OUTPUT); pinMode(LEFT_MOTOR_IN1, OUTPUT); pinMode(LEFT_MOTOR_IN2, OUTPUT); pinMode(RIGHT_MOTOR_PWM, OUTPUT); pinMode(RIGHT_MOTOR_IN1, OUTPUT); pinMode(RIGHT_MOTOR_IN2, OUTPUT); qtr.setTypeRC(); qtr.setSensorPins(sensorPins, NUM_SENSORS); delay(500); for (int i = 0; i < 400; i++) { qtr.calibrate(); delay(5); } } void loop() { unsigned int position = qtr.readLine(sensorValues); int centerPosition = ((NUM_SENSORS - 1) * 1000) / 2; int error = position - centerPosition; integral += error; double derivative = error - lastError; int correction = Kp * error + Ki * integral + Kd * derivative; lastError = error; int leftSpeed = baseSpeed + correction; int rightSpeed = baseSpeed - correction; leftSpeed = constrain(leftSpeed, 0, maxSpeed); rightSpeed = constrain(rightSpeed, 0, maxSpeed); Serial.print("Posicion: "); Serial.print(position); Serial.print(" Error: "); Serial.print(error); Serial.print(" Correccion: "); Serial.println(correction); setMotor(LEFT_MOTOR_PWM, LEFT_MOTOR_IN1, LEFT_MOTOR_IN2, leftSpeed); setMotor(RIGHT_MOTOR_PWM, RIGHT_MOTOR_IN1, RIGHT_MOTOR_IN2, rightSpeed); delay(10); } void setMotor(int pwmPin, int in1Pin, int in2Pin, int speed) { if (speed >= 0) { digitalWrite(in1Pin, HIGH); digitalWrite(in2Pin, LOW); analogWrite(pwmPin, speed); } else { digitalWrite(in1Pin, LOW); digitalWrite(in2Pin, HIGH); analogWrite(pwmPin, -speed); } }
#include.Ready to work
Welcome 👋
Flux helps you build PCBs faster with an AI teammate!
Create your account to collaborate, stay updated, fork your own version, and get instant answers from our AI agent.