The PID algorithm uses three constants, Kp,KI and Kd to function. They are shorthand notations for proportionality, integral and differential constants respectively. These three constants have to be set by you after testing, and define how good your control works.
Now let’s look at how to develop a simple PID control algorithm.
Use the Arduino function analogread() to retrieve sensor values. You’ll need an array to store these variables. Use Serial.print() to display these sensor values and observe them through the serial monitor in the Arduino IDE.
If you’re using five sensors connected at analog pins 0-4, your code would look somewhat like this:
Burn this code onto the Arduino and place your bot over a sample track you’ve made. Move it across the line and observe the sensor readings. The reading will be a number between 0 and 1023. Find out what reading comes up for white and black, and any other colors you may want.
Important – The sensors connected from analog pins 0-4 should be in order from left to right. If you’re using 5 sensors, the leftmost should be connected to pin 0, the middle one connected to pin 2, and the rightmost one to pin 4.
Source: Read GuideToBuildAutoRobots
Now let’s look at how to develop a simple PID control algorithm.
Use the Arduino function analogread() to retrieve sensor values. You’ll need an array to store these variables. Use Serial.print() to display these sensor values and observe them through the serial monitor in the Arduino IDE.
If you’re using five sensors connected at analog pins 0-4, your code would look somewhat like this:
void setup() {
Serial.begin(9600); //Necessary to set up Serial port}
void loop() {
Serial.print(analogRead(0));
Serial.print(' ');
Serial.print(analogRead(1));
Serial.print(' ');
Serial.print(analogRead(2));
Serial.print(' ');
Serial.print(analogRead(3));
Serial.print(' ');
Serial.print(analogRead(4));
Serial.println(' ');
delay(1500); //Set the number to change frequency of readings
}
Burn this code onto the Arduino and place your bot over a sample track you’ve made. Move it across the line and observe the sensor readings. The reading will be a number between 0 and 1023. Find out what reading comes up for white and black, and any other colors you may want.
Important – The sensors connected from analog pins 0-4 should be in order from left to right. If you’re using 5 sensors, the leftmost should be connected to pin 0, the middle one connected to pin 2, and the rightmost one to pin 4.
Source: Read GuideToBuildAutoRobots
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.