Difference between revisions of "Microduio Single dimension PID adjustment"

From Microduino Wiki
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 34: Line 34:
 
When using the PID algorithm, roughly like this. Each sampling period, get the current speed by the speed detection device, input this data to program, voltage is calculated by the program to control the car to get new speed. The next sampling period, input new incoming speed, get a new voltage, then imput new incoming speed, and then get the voltage again, and repeat.
 
When using the PID algorithm, roughly like this. Each sampling period, get the current speed by the speed detection device, input this data to program, voltage is calculated by the program to control the car to get new speed. The next sampling period, input new incoming speed, get a new voltage, then imput new incoming speed, and then get the voltage again, and repeat.
  
The key point of PID algorithm is that how to calculate the output voltage according to the current speed, so that the car can eventually stabilised.
+
The key point of PID algorithm is that how to calculate the output voltage according to the current speed, so that the car can eventually stabilized.
  
 
PID algorithm uses proportion, integral and differential three methods to control. Three methods all have their own corresponding constant that are pconst, iconst, dconst. The three variables need to be adjusted in the experiment.
 
PID algorithm uses proportion, integral and differential three methods to control. Three methods all have their own corresponding constant that are pconst, iconst, dconst. The three variables need to be adjusted in the experiment.
  
 
PID algorithm's mathematical formula, as follows:
 
PID algorithm's mathematical formula, as follows:
用数学公式表达PID算法如下图所示:
+
 
  
 
[[File:PID公式.jpg|600px|center|thumb]]
 
[[File:PID公式.jpg|600px|center|thumb]]
Line 45: Line 45:
  
 
Now we will use the Microduino and processing to finish a PID controller.
 
Now we will use the Microduino and processing to finish a PID controller.
 
  
 
==Schematic==
 
==Schematic==
Line 58: Line 57:
 
==Debug==
 
==Debug==
  
Step 1:Download Processing2.0 Beta 7 IDE software.
+
Step 1: Download Processing2.0 Beta 7 IDE software.
 
 
Step 2:Download Arduino official library—PID Library and PID Front-End using Processing.org.
 
  
Step 3:Downlaod Processing official library—ControlP5 :http://www.sojamo.de/libraries/controlP5/
+
Step 2: Download Arduino official library—PID Library and PID Front-End using Processing.org.
  
Step 4:Uncompress the Arduino official library—PID Library to libraries folder of Arduino IDE
+
Step 3: Downlaod Processing official library—ControlP5: http://www.sojamo.de/libraries/controlP5/
  
If you want to know the PID algorithm's relization in the library, please refer to following link:http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/
+
Step 4: Uncompress the Arduino official library—PID Library to libraries folder of Arduino IDE
  
Step 5:Uncompress the Processing official library—ControlP5 to the folder \modes\java\libraries which under the processing install directory.
+
Step 5: Uncompress the Processing official library—ControlP5 to the folder \modes\java\libraries which under the processing install directory.
  
Step 6:Uncompress Arduino PID_FrontEnd_v03.zip to anywhere
+
Step 6: Uncompress Arduino PID_FrontEnd_v03.zip to anywhere
  
Step 7:Open the PID FrontEnd ArduinoSampleCode.pde in Arduino IDE, then compile it and download to Microduino
+
Step 7: Open the PID FrontEnd ArduinoSampleCode.pde in Arduino IDE, then compile it and download to Microduino
  
In program, pay attention to following issue:
+
In program, pay attention to following issue:
  
 
[[File:SetpointInputOutput.jpg|600px|center|thumb]]
 
[[File:SetpointInputOutput.jpg|600px|center|thumb]]
Line 90: Line 87:
 
//In this experiment, we only do a simple PID control. Input Pin is A0, connects to a potentiometer, the output pin is pin3, will be displayed in processing's oscillogram.
 
//In this experiment, we only do a simple PID control. Input Pin is A0, connects to a potentiometer, the output pin is pin3, will be displayed in processing's oscillogram.
  
Step 8:Use the Processing to open PID_FrontEnd_v03.pde
+
Step 8: Use the Processing to open PID_FrontEnd_v03.pde
 
[[File:processing选择正确的com口.jpg|600px|center|thumb]]
 
[[File:processing选择正确的com口.jpg|600px|center|thumb]]
 
Note: myPort = new Serial(this, Serial.list()[1], 9600); and [0] "COM2", [1] "COM7". In a word, need match your COM port.
 
Note: myPort = new Serial(this, Serial.list()[1], 9600); and [0] "COM2", [1] "COM7". In a word, need match your COM port.
  
Step 9:Set up hardware, as follows:
+
Step 9: Set up hardware, as follows:
  
 
[[File:Microduino单维度调整连接图.jpg|600px|center|thumb]]
 
[[File:Microduino单维度调整连接图.jpg|600px|center|thumb]]
  
Step 10:Rutn arduino program firstly, then run processing, you can see following picture:
+
Step 10: Run arduino program firstly, then run processing, you can see following picture:
  
 
[[File:processing的PID波形图.jpg|600px|center|thumb]]
 
[[File:processing的PID波形图.jpg|600px|center|thumb]]
  
  
Step 11:Rotate the potentiometer, observe the waveform of input, setPoint, output.
+
Step 11: Rotate the potentiometer, observe the waveform of input, setPoint, output.
  
  
 
==Result==
 
==Result==
  
In this experiment, setpoint set to 100, when input value is 0, output reachs to 255 in order to meet the setpoint quickly.
+
In this experiment, setpoint set to 100, when input value is 0, output reaches to 255 in order to meet the setpoint quickly.
  
When the input up to 100, even more than 100, the output willinto a minimum.
+
When the input up to 100, even more than 100, the output will into a minimum.
  
 
==Video==
 
==Video==
  
http://v.youku.com/v_show/id_XNzAxMDk4Mjcy.html
+
 
  
  
 
|}
 
|}

Latest revision as of 10:25, 28 September 2016

Language: English  • 中文

Objective

From this tutorial, you can learn the PID and using the processing oscillogram to understand the PID control. This lesson will be lay a foundation for balance car control.

Equipment


PID Principle

PID has an extremely important role in automatic control field, as the earliest practical control technology has been 70 years. In recent years some geeks made some more cool things using this technology, such as: four axis aircraft, self-balancing car and so on.

Firstly, we need understand what is PID? PID means the proportional, integral and derivative. If we expect the controlled object finally tends to a stable result, general PID algorithm can be used.

For example, a car with speed 1 m/s, if we want to change the speed to 5 m/s, need following things:

1. The car drive (Use program to control output voltage, and voltage decided to the drive horsepower) 2. Controlled object (that is the car) 3. Speed detection device (the current speed and the target speed difference is called error). Originally we can give the car a driving force to allow the car to accelerate until it detects the car's speeds up to 5m/s, then removes the driving force.

But there are several issues using this method. As follows: 1. When the car's speed reach to 5 m/s, from the device detected the speed, informed the controller, the controller adjusted the output voltage, this process requires a certain time, during this time, the car's speed may increased a lot.

2. After removed the driving force, external conditions such as friction makes the car's speed change again.

If we use the PID, it can resolves these issues in a certain error.

When using the PID algorithm, roughly like this. Each sampling period, get the current speed by the speed detection device, input this data to program, voltage is calculated by the program to control the car to get new speed. The next sampling period, input new incoming speed, get a new voltage, then imput new incoming speed, and then get the voltage again, and repeat.

The key point of PID algorithm is that how to calculate the output voltage according to the current speed, so that the car can eventually stabilized.

PID algorithm uses proportion, integral and differential three methods to control. Three methods all have their own corresponding constant that are pconst, iconst, dconst. The three variables need to be adjusted in the experiment.

PID algorithm's mathematical formula, as follows:


PID公式.jpg


Now we will use the Microduino and processing to finish a PID controller.

Schematic

Microduino单维度调整原理图.jpg


Program

Refer to PID_FrontEnd_v03


Debug

Step 1: Download Processing2.0 Beta 7 IDE software.

Step 2: Download Arduino official library—PID Library and PID Front-End using Processing.org.

Step 3: Downlaod Processing official library—ControlP5: http://www.sojamo.de/libraries/controlP5/

Step 4: Uncompress the Arduino official library—PID Library to libraries folder of Arduino IDE

Step 5: Uncompress the Processing official library—ControlP5 to the folder \modes\java\libraries which under the processing install directory.

Step 6: Uncompress Arduino PID_FrontEnd_v03.zip to anywhere

Step 7: Open the PID FrontEnd ArduinoSampleCode.pde in Arduino IDE, then compile it and download to Microduino

In program, pay attention to following issue:

SetpointInputOutput.jpg

double Setpoint, Input, Output;

//setpoint is the target value.

//Input is the input value, that is the actual value detected via the sensor, such as, the angle value in self-balancing car.

//Output is the output value, that is the value calculated by PID. In the self-balancing car system, it is the PWM value which uses to control the motor and adjust the angle to 0 degrees.

int inputPin=0, outputPin=3;

//In this experiment, we only do a simple PID control. Input Pin is A0, connects to a potentiometer, the output pin is pin3, will be displayed in processing's oscillogram.

Step 8: Use the Processing to open PID_FrontEnd_v03.pde

Processing选择正确的com口.jpg

Note: myPort = new Serial(this, Serial.list()[1], 9600); and [0] "COM2", [1] "COM7". In a word, need match your COM port.

Step 9: Set up hardware, as follows:

Microduino单维度调整连接图.jpg

Step 10: Run arduino program firstly, then run processing, you can see following picture:

Processing的PID波形图.jpg


Step 11: Rotate the potentiometer, observe the waveform of input, setPoint, output.


Result

In this experiment, setpoint set to 100, when input value is 0, output reaches to 255 in order to meet the setpoint quickly.

When the input up to 100, even more than 100, the output will into a minimum.

Video