Difference between revisions of "Microduio Single dimension PID adjustment"
(Created page with "{{Language | Microduino 单维度PID调整}} {| style="width: 800px;" |- | ==Objective== From this tutorial, you can learn the PID and using the processing oscillogram to unde...") |
|||
(4 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 | + | 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: | ||
− | + | ||
[[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 | + | Step 1: Download Processing2.0 Beta 7 IDE software. |
− | |||
− | |||
− | Step | + | Step 2: Download Arduino official library—PID Library and PID Front-End using Processing.org. |
− | Step | + | 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 | + | Step 5: Uncompress the Processing official library—ControlP5 to the folder \modes\java\libraries which under the processing install directory. |
− | Step | + | Step 6: Uncompress Arduino PID_FrontEnd_v03.zip to anywhere |
− | Step | + | Step 7: Open the PID FrontEnd ArduinoSampleCode.pde in Arduino IDE, then compile it and download to Microduino |
− | In program, pay attention to following | + | 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 | + | 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 | + | Step 9: Set up hardware, as follows: |
[[File:Microduino单维度调整连接图.jpg|600px|center|thumb]] | [[File:Microduino单维度调整连接图.jpg|600px|center|thumb]] | ||
− | Step | + | 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 | + | 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 | + | 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 | + | When the input up to 100, even more than 100, the output will into a minimum. |
==Video== | ==Video== | ||
− | + | ||
|} | |} |
Latest revision as of 10:25, 28 September 2016
Language: | English • 中文 |
---|
ObjectiveFrom 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 PrinciplePID 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:
Schematic
ProgramRefer to PID_FrontEnd_v03
DebugStep 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: 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 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 10: Run arduino program firstly, then run processing, you can see following picture:
ResultIn 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 |