TODOPIC

Microcontroladores PIC => dsPIC => Mensaje iniciado por: Hexapic en 17 de Julio de 2012, 07:29:37

Título: PID robot tracción diferencial con dspic
Publicado por: Hexapic en 17 de Julio de 2012, 07:29:37
Hola, tengo una duda conceptual que no se como enfocar. Estoy con un robot con tracción diferencial (2 motores, en plan robots seguidores de linea). Dispongo de un sensor magnético que me da una tensión cuando lee una linea magnética y la intenció es que si la linea se aleja del centro del sensor los motores corrijan la trayectoria para seguir la linea. Si detecta linea en el lado del sensor derecho este me da valores positivos y si detecta linea en el lado izquierdo da valores negativos.
Mi idea es programar una velocidad del robot, si quiero que este valla recto VMI (Velocidad motor izquierdo) = VMD (Velocidad motor izquierdo) = VP (Velocidad programada), esto sucede cuando el valor del sensor es 0. Pero si me alejo de 0 reducir la velocidad de uno de los motores para compensar que el sensor vuelva a 0. Es decir que si detecto valores de sensor positivos, linea en el lado derecho del sensor,reducir VMI y si detecto valores negativos del sensor reducir VMD. He pensado que para no perder la linea VMI y VMD pueden variar de 0 a VP.

Para esto
VMI = VP - VCorreccionI
VMD = VP - VCorreccionD

Vcorreción tiene valores de 0 (si no tiene que corregir velocidad), hasta VP si debe corregir velocidad debido a que la linea se aleja del sensor

El control de los motores está controlado un PID con un dspic.

Para esto utilizo la libreria de PID de los dspic
ce019-PID.zip (http://embeddedcodesource.com/developer/microchip_technology/ce019__pid_for_closedloop_systems)

Código: [Seleccionar]
#include <dsp.h>

/*
Variable Declaration required for each PID controller in your application
*/
/* Declare a PID Data Structure named, fooPID */
tPID fooPID;
/* The fooPID data structure contains a pointer to derived coefficients in X-space and */
/* pointer to controler state (history) samples in Y-space. So declare variables for the */
/* derived coefficients and the controller history samples */
fractional abcCoefficient[3] __attribute__ ((section (".xbss, bss, xmemory")));
fractional controlHistory[3] __attribute__ ((section (".ybss, bss, ymemory")));
/* The abcCoefficients referenced by the fooPID data structure */
/* are derived from the gain coefficients, Kp, Ki and Kd */
/* So, declare Kp, Ki and Kd in an array */
fractional kCoeffs[] = {0,0,0};

/*
Main function demonstrating the use of PID(), PIDInit() and PIDCoeffCalc()
functions from DSP library in MPLAB C30 v3.00 and higher
*/
int main (void)
{
/*
Step 1: Initialize the PID data structure, fooPID
*/
        fooPID.abcCoefficients = &abcCoefficient[0];    /*Set up pointer to derived coefficients */
        fooPID.controlHistory = &controlHistory[0];     /*Set up pointer to controller history samples */
        PIDInit(&fooPID);                               /*Clear the controler history and the controller output */
kCoeffs[0] = Q15(0.7);                       // Imagino que aqui le decimos Kp=0.7,Ki=0.2,Kd=0.07
kCoeffs[1] = Q15(0.2);
kCoeffs[2] = Q15(0.07);
        PIDCoeffCalc(&kCoeffs[0], &fooPID);             /*Derive the a,b, & c coefficients from the Kp, Ki & Kd */

/*
Step 2: Use the PID Controller
*/
        fooPID.controlReference = Q15(0.74) ;           /*Set the Reference Input for your controller */ 
        fooPID.measuredOutput = Q15(0.453) ;            /*Typically the measuredOutput variable is a plant response*/
                                                        /*measured from an A/D input or a sensor. */
                                                        /*In this example we manually set it to some value for */
                                                        /*demonstration but the user should note that this value will */
                                                        /*keep changing in a real application*/
        while (1)                                       /*We use a while(1) loop here for demonstration purposes.*/
        {                                               /*Typically, the PID calculation may be triggered off a timer*/
                                                        /*or A/D interrupt */

                PID(&fooPID);                           /*Call the PID controller using the new measured input */
                                                        /*The user may place a breakpoint on "PID(&fooPID)", halt the debugger,*/
                                                        /*tweak the measuredOutput variable within the watch window */
                                                        /*and then run the debugger again */
        }

}


Y aquí es donde me pierdo. Como puedo utilizar un PID para que intente llevar la lectura del valor del sensor magnético a 0. No entiendo el concepto de controlReference y measuredOutput.

No se si me abre explicado con la suficiente claridad.

Saludos cordiales
Hexapic !!