Hi this I have made an arduino line follower. using An arduino dumilave. A 5 ir sensor array. A 12v and 850ma battery and 300 rpm motors.I am unable to find Kp Ki Kd values and my robot is not at all following the line. This is my code. Pls some one help
const int motor3Pin = 3;
const int motor1Pin = 10;
const int motor2Pin = 6;
const int motor4Pin = 11;
int right_speed = 0;
int left_speed = 0;
long sensors[] = {0,0,0,0,0};
long sensors_average = 0;
int sensors_sum = 0;
int posn; //position
int proportional = 0;
long integral = 0;
int derivative = 0;
int last_proportional = 0;
float Kp = 2; // Havent decided the values yet
float Ki = 2;
float Kd = 2;
int error_value = 0;
int max_speed = 200;
int set_point = 1987;//the posn on the center of line, I have to decide the value yet
Do you KNOW that the robot is reading the sensors correctly?
Reading the 5 sensors, adding up the values, and determining an average will tell you nothing about where the line is. I think you are barking up the wrong tree. As a matter of fact, I don't think you are even barking in the right forest.
Seems to me there must have been 10,000 roboticists who have made line-following robots that
never even heard the term PID. Why not try doing it the simple way [differential sensor readings]
FIRST, like everyone else.
Hey my senors are reading correctly and i can differentiate between the set point and other positions. I have built line followers first and they were successful. Now i want to make a high speed and accurate line follower so i have chosen the pid algorithm.
OP: could you repost your code please, not using "format for forum" (or whatever it is called), but simply copying the contents of your IDE window, and pasting the result between tags?
That way, we'll avoid the nonsense of
void read_sensors () {
for (int i = 0; i < 5; i++) {
sensors = analogRead(i);
sensors_average += sensors * i * 1000;
sensors_sum += int(sensors);
}
}
const int motor3Pin = 3;
const int motor1Pin = 10;
const int motor2Pin = 6;
const int motor4Pin = 11;
int right_speed = 0;
int left_speed = 0;
long sensors[] = {0,0,0,0,0};
long sensors_average = 0;
int sensors_sum = 0;
int posn; //position
int proportional = 0;
long integral = 0;
int derivative = 0;
int last_proportional = 0;
float Kp = 2; // Havent decided the values yet
float Ki = 2;
float Kd = 2;
int error_value = 0;
int max_speed = 200;
int set_point = 1987;//the posn on the center of line, I have to decide the value yet
Is your calculation of posn returning sensible values based on what is in front of your sensors? I guess you're trying to calculate where the 'hot spot' is.
You don't seem to be providing any control over the timing of your PID algorithm. The derivative and integral elements are with respect to time, and I don't see anything to provide a consistent sample rate. Is there some reason you aren't just using the PID library?