descargar 192.97 Kb.
|
Proyecto Control P+I+D Objetivo.- Basado en este proyecto construir prototipo de regulación de velocidad de motor empleando encoder óptico como sensor de velocidad, y realizar su calibración de parámetros de los modos de control (Sintonización). « Arduino Uno Keeps Header Offset Improving the Beginner’s PID – Sample Time » Improving the Beginner’s PID – Introduction In conjunction with the release of the new Arduino PID Library I’ve decided to release this series of posts. The last library, while solid, didn’t really come with any code explanation. This time around the plan is to explain in great detail why the code is the way it is. I’m hoping this will be of use to two groups of people:
It’s going to be a tough slog, but I think I found a not-too-painful way to explain my code. I’m going to start with what I call “The Beginner’s PID.” I’ll then improve it step-by-step until we’re left with an efficient, robust pid algorithm. The Beginner’s PID Here’s the PID equation as everyone first learns it: ![]() This leads pretty much everyone to write the following PID controller:
Compute() is called either regularly or irregularly, and it works pretty well. This series isn’t about “works pretty well” though. If we’re going to turn this code into something on par with industrial PID controllers, we’ll have to address a few things:
Once we’ve addressed all these issues, we’ll have a solid PID algorithm. We’ll also, not coincidentally, have the code that’s being used in the lastest version of the Arduino PID Library. So whether you’re trying to write your own algorithm, or trying to understand what’s going on inside the PID library, I hope this helps you out. Let’s get started. Next >> UPDATE: In all the code examples I’m using doubles. On the Arduino, a double is the same as a float (single precision.) True double precision is WAY overkill for PID. If the language you’re using does true double precision, I’d recommend changing all doubles to floats. ……………………. http://www.arduino.cc/playground/Code/PIDLibrary PID Library /******************************************************** * PID Basic Example * Reading analog input 0 to control analog PWM output 3 ********************************************************/ #include //Define Variables we'll be connecting to double Setpoint, Input, Output; //Specify the links and initial tuning parameters PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT); void setup() { //initialize the variables we're linked to Input = analogRead(0); Setpoint = 100; //turn the PID on myPID.SetMode(AUTOMATIC); } void loop() { Input = analogRead(0); myPID.Compute(); analogWrite(3,Output); } ………………… PID Library /******************************************************** * PID Adaptive Tuning Example * One of the benefits of the PID library is that you can * change the tuning parameters at any time. this can be * helpful if we want the controller to be agressive at some * times, and conservative at others. in the example below * we set the controller to use Conservative Tuning Parameters * when we're near setpoint and more agressive Tuning * Parameters when we're farther away. ********************************************************/ #include //Define Variables we'll be connecting to double Setpoint, Input, Output; //Define the aggressive and conservative Tuning Parameters double aggKp=4, aggKi=0.2, aggKd=1; double consKp=1, consKi=0.05, consKd=0.25; //Specify the links and initial tuning parameters PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT); void setup() { //initialize the variables we're linked to Input = analogRead(0); Setpoint = 100; //turn the PID on myPID.SetMode(AUTOMATIC); } void loop() { Input = analogRead(0); double gap = abs(Setpoint-Input); //distance away from setpoint if(gap<10) { //we're close to setpoint, use conservative tuning parameters myPID.SetTunings(consKp, consKi, consKd); } else { //we're far from setpoint, use aggressive tuning parameters myPID.SetTunings(aggKp, aggKi, aggKd); } myPID.Compute(); analogWrite(3,Output); } ![]() Como ya sabrán la mayoría de los que leen este blog a diario, el algoritmo PID (o Proporcional Integral Derivativo), es un elemento bastante usado en sistemas autómatas (de una manera u otra), en los cuales este algoritmo cobra bastante importancia en las funciones de re-alimentación, además de provocar que la curva de respuesta sea mucho mas suave que si usamos un sistema alternativo. La idea es haceros un poco de resumen sobre el panorama de librerías ya diseñadas que nos permitan crear un control PID sencillo (relativamente), sin tener que programarlo desde 0. Arduino no se queda atrás! El PID tiene una fórmula, ecuación, expresión, que nos permite calcular los parámetros de salida, a partir de unos dados, básicamente es esta: ![]() Y ahora, vayámonos con la lib de arduino! ARDUINO PID LIBRARY Cita de wikipedia "Un PID (Proporcional Integral Derivativo) es un mecanismo de control por realimentación que calcula la desviación o error entre un valor medido y el valor que se quiere obtener, para aplicar una acción correctora que ajuste el proceso." Funciones PID() Compute() SetMode() SetOutputLimits() SetTunings() SetSampleTime() SetControllerDirection() Ejemplo básico: view plaincopy to clipboardprint?
/******************************************************** * PID Basic Example * Reading analog input 0 to control analog PWM output 3 ********************************************************/ #include //Define Variables we'll be connecting to double Setpoint, Input, Output; //Specify the links and initial tuning parameters PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT); void setup() { //initialize the variables we're linked to Input = analogRead(0); Setpoint = 100; //turn the PID on myPID.SetMode(AUTOMATIC); } void loop() { Input = analogRead(0); myPID.Compute(); analogWrite(3,Output); } Enlaces Descarga la última versión Página de ejemplos Página oficial en background de Arduino (Con 2 ejemplos mas!) Explicacíon de la librería y el PID por el autor de dicha libreria ----------------- Programa de ejemplo de control PID en VB6 Publicado por Oscar Gonzalez en Programación el 08/02/2011 (18:50) Etiquetas: programa, ejemplo, pid, vb6, quadcopter . 3 comentarios ![]() Si estás desarrollando un quadcopter pero te encuentras ya con el "problema" de la calibración del control PID estás de suerte. He encontrado un interesante enlace al código fuente de un pequeño programa hecho en Visual Basic 6 que muestra en todo su esplendor cómo funciona un control PID. Un PID (Proporcional Integral Derivativo) es un mecanismo de control por realimentación que calcula la desviación o error entre un valor medido y el valor que se quiere obtener. Es básicamente lo que se utiliza para la estabilización de quadcopters, hexacopters etc. Para entender cómo funciona y sobre todo cómo reacciona cambiando sus parámetros de control, la aplicación simula un tanque con una entrada de líquido, una salida y un nivel de líquido que queremos mantener. En función del calculo y modificación de las tres variables del PID (Proporcional, Integral y Derivada), podremos ver las distintas respuestas del algoritmo y entenderemos qué hace cada parámetro. Es interesante ver la respuesta del ciclo de llenado/vaciado según vamos modificando las variables y nos puede dar una idea de la respuesta que queremos para nuestro objeto volador. No os perdais el enlace y ya me contareis qué tal! ;) ![]() ![]() ![]() ![]() ![]() ![]() |