Mk44
Hectopat
- Katılım
- 10 Mayıs 2022
- Mesajlar
- 103
- Çözümler
- 1
Daha fazla
- Cinsiyet
- Erkek
Merhaba. Aşağıdaki kodda 17 ve 31. satırlarda hata veriyor. Yardımcı olabilirseniz sevinirim.
[CODE lang="cpp" title="Çizgi İzleyen" highlight="17 ve 31"]#include <QTRSensors.h>
#define Kp 0.05 // experiment to determine this, start by something small that just makes your bot follow the line at a slow speed
#define Kd 2
// experiment to determine this, slowly increase the speeds and adjust this value. ( Note: Kp < Kd)
#define rightMaxSpeed 200
#define leftMaxSpeed 200
#define rightBaseSpeed 150
#define leftBaseSpeed 150
#define NUM_SENSORS 8
#define TIMEOUT 2500
#define EMITTER_PIN 2
QTRSensorsAnalog qtra((unsigned char[]) { A0, A1, A2, A3, A4, A5, A6, A7} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
void setup()
{
/* comment this part out for automatic calibration
if ( i < 25 || i >= 75 ) // turn to the left and right to expose the sensors to the brightest and darkest readings that may be encountered
turn_right();
else
turn_left(); */
qtra.calibrate(QTR_EMITTERS_ON);
delay(20);
delay(10000);
/* comment out for serial printing
Serial.begin(9600);
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMinimumOn);
Serial.print(' ');
}
Serial.println();
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMaximumOn);
Serial.print(' ');
}
Serial.println();
Serial.println();
*/
}
int lastError = 0;
void loop()
{
unsigned int sensors[8];
int position = qtra.readLine(sensors);
int error = position - 3500;
int motorSpeed = Kp * error + Kd * (error - lastError);
lastError = error;
int rightMotorSpeed = rightBaseSpeed + motorSpeed;
int leftMotorSpeed = leftBaseSpeed - motorSpeed;
if (rightMotorSpeed > rightMaxSpeed ) rightMotorSpeed = rightMaxSpeed;
if (leftMotorSpeed > leftMaxSpeed ) leftMotorSpeed = leftMaxSpeed;
if (rightMotorSpeed < 0) rightMotorSpeed = 0;
if (leftMotorSpeed < 0) leftMotorSpeed = 0;
}[/CODE]
[CODE lang="cpp" title="Çizgi İzleyen" highlight="17 ve 31"]#include <QTRSensors.h>
#define Kp 0.05 // experiment to determine this, start by something small that just makes your bot follow the line at a slow speed
#define Kd 2
// experiment to determine this, slowly increase the speeds and adjust this value. ( Note: Kp < Kd)
#define rightMaxSpeed 200
#define leftMaxSpeed 200
#define rightBaseSpeed 150
#define leftBaseSpeed 150
#define NUM_SENSORS 8
#define TIMEOUT 2500
#define EMITTER_PIN 2
QTRSensorsAnalog qtra((unsigned char[]) { A0, A1, A2, A3, A4, A5, A6, A7} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
void setup()
{
/* comment this part out for automatic calibration
if ( i < 25 || i >= 75 ) // turn to the left and right to expose the sensors to the brightest and darkest readings that may be encountered
turn_right();
else
turn_left(); */
qtra.calibrate(QTR_EMITTERS_ON);
delay(20);
delay(10000);
/* comment out for serial printing
Serial.begin(9600);
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMinimumOn);
Serial.print(' ');
}
Serial.println();
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMaximumOn);
Serial.print(' ');
}
Serial.println();
Serial.println();
*/
}
int lastError = 0;
void loop()
{
unsigned int sensors[8];
int position = qtra.readLine(sensors);
int error = position - 3500;
int motorSpeed = Kp * error + Kd * (error - lastError);
lastError = error;
int rightMotorSpeed = rightBaseSpeed + motorSpeed;
int leftMotorSpeed = leftBaseSpeed - motorSpeed;
if (rightMotorSpeed > rightMaxSpeed ) rightMotorSpeed = rightMaxSpeed;
if (leftMotorSpeed > leftMaxSpeed ) leftMotorSpeed = leftMaxSpeed;
if (rightMotorSpeed < 0) rightMotorSpeed = 0;
if (leftMotorSpeed < 0) leftMotorSpeed = 0;
}[/CODE]