Uso de la clase Motor para el control de velocidad de un motor continuo con encoder.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Motor.h Source File

Motor.h

00001 #ifndef Motor_H
00002 #define Motor_H
00003 #include "mbed.h"
00004  /* **************************************************************************
00005  
00006 @CCastrop
00007 cristiank.castrop@ecci.edu.co
00008 
00009     L1      Terminal A del motor
00010     L2      Terminal B del motor
00011     SpeedPin Pin de salida PWM
00012     
00013  
00014 ******************************************************************************/
00015 
00016 
00017 class MotorContinuo {
00018   public:
00019     /// Constructores para Motores Continuos
00020     MotorContinuo(PinName _L1, PinName _L2, PinName _speedPin, PinName _encodin, PinName _PosInicial, int _EncodPulses);
00021     
00022     void Forward();     // Da un sentido de giro al motor
00023     void Back();        // Genera un sentido de giro contrario al de Forward
00024     void Stop();        // Detiene el motor dejando el movimiento libre
00025     void StopT();       // Detiene el motor truncando o enclavando el movimiento(Lo mantiene quieto).
00026     void SpeedDuty(int v);   // Varia la velocidad de giro del motor de 0 a 100%
00027     void SpinLength_ms(float t);  // Duración del giro en ms
00028     void SpinLength(float t);  // Duración del giro
00029     
00030   private:
00031 
00032     DigitalOut L1;
00033     DigitalOut L2;
00034     PwmOut     speedPin;
00035     DigitalIn  encodin;
00036     DigitalIn  PosInicial;
00037     int EncodPulses;
00038 
00039 
00040     
00041 
00042 };
00043 
00044 
00045 class MotorDiscreto {
00046   public:
00047     /// Constructores para Motores Continuos
00048     MotorDiscreto(PinName _Dir, PinName _Step, int _NPasos, PinName _encodin, PinName _PosInicial, int _EncodPulses);
00049     MotorDiscreto(void);    
00050     void Forward();                 // Da un sentido de giro al motor
00051     void Back();                    // Genera un sentido de giro contrario al de Forward
00052     void Stop();                    // Detiene el motor dejando el movimiento libre. Pin Enable = 0
00053     void StopT();                   // Detiene el motor truncando o enclavando el movimiento(Lo mantiene quieto).
00054     void StepFreq(int n);           // Configura la Velocidad en Número(n) de pasos por segundos. Es decir la Frecuencia de paso.
00055     void RunStep(long n);          // Se mueve el motor la cantidad de pasos ingresada
00056     void Run(float t);              // Gira el motor durante el tiempo ingresado, si es 0 indefinidamente hasta llamada a Stop().
00057     void RunRound(int n);           // Girar n vueltas
00058     void Ustep(int resolucion, PinName M0, PinName M1, PinName M2);
00059                                     // Configura los pasos a 1/2, 1/4, 1/8, 1/16, 1/32
00060     
00061                                     
00062     long StepOnHold;                // Pasos faltantes por ejecutar
00063     long StepsBySecond;             // Pasos por segundo
00064     
00065   private:
00066     
00067     void moveMotor(void);
00068     
00069     DigitalOut Dir;
00070     DigitalOut Step;
00071     int        NPasos;
00072     DigitalIn  encodin;
00073     DigitalIn  PosInicial;
00074     int        EncodPulses;
00075     
00076     DigitalOut* EnablePin;
00077     DigitalOut* M0;
00078     DigitalOut* M1;
00079     DigitalOut* M2;
00080     
00081     Ticker Move;                /// Timer de interrupcion
00082     float TStep;                /// periodo del paso TStep = 1/StepsBySecond;
00083     
00084     int entradas;               /// registra cada 2 ingresos a la interrupcion
00085 
00086 };
00087 #endif
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102