Microduio Single dimension PID adjustment

From Microduino Wikipedia
Jump to: navigation, search
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