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

Dependencies:   mbed

Committer:
CCastrop1012
Date:
Fri Sep 03 05:04:12 2021 +0000
Revision:
0:75421f27540e
Uso de la clase Motor para control de velocidad de motor continuo con encoder.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CCastrop1012 0:75421f27540e 1 #ifndef Motor_H
CCastrop1012 0:75421f27540e 2 #define Motor_H
CCastrop1012 0:75421f27540e 3 #include "mbed.h"
CCastrop1012 0:75421f27540e 4 /* **************************************************************************
CCastrop1012 0:75421f27540e 5
CCastrop1012 0:75421f27540e 6 @CCastrop
CCastrop1012 0:75421f27540e 7 cristiank.castrop@ecci.edu.co
CCastrop1012 0:75421f27540e 8
CCastrop1012 0:75421f27540e 9 L1 Terminal A del motor
CCastrop1012 0:75421f27540e 10 L2 Terminal B del motor
CCastrop1012 0:75421f27540e 11 SpeedPin Pin de salida PWM
CCastrop1012 0:75421f27540e 12
CCastrop1012 0:75421f27540e 13
CCastrop1012 0:75421f27540e 14 ******************************************************************************/
CCastrop1012 0:75421f27540e 15
CCastrop1012 0:75421f27540e 16
CCastrop1012 0:75421f27540e 17 class MotorContinuo {
CCastrop1012 0:75421f27540e 18 public:
CCastrop1012 0:75421f27540e 19 /// Constructores para Motores Continuos
CCastrop1012 0:75421f27540e 20 MotorContinuo(PinName _L1, PinName _L2, PinName _speedPin, PinName _encodin, PinName _PosInicial, int _EncodPulses);
CCastrop1012 0:75421f27540e 21
CCastrop1012 0:75421f27540e 22 void Forward(); // Da un sentido de giro al motor
CCastrop1012 0:75421f27540e 23 void Back(); // Genera un sentido de giro contrario al de Forward
CCastrop1012 0:75421f27540e 24 void Stop(); // Detiene el motor dejando el movimiento libre
CCastrop1012 0:75421f27540e 25 void StopT(); // Detiene el motor truncando o enclavando el movimiento(Lo mantiene quieto).
CCastrop1012 0:75421f27540e 26 void SpeedDuty(int v); // Varia la velocidad de giro del motor de 0 a 100%
CCastrop1012 0:75421f27540e 27 void SpinLength_ms(float t); // Duración del giro en ms
CCastrop1012 0:75421f27540e 28 void SpinLength(float t); // Duración del giro
CCastrop1012 0:75421f27540e 29
CCastrop1012 0:75421f27540e 30 private:
CCastrop1012 0:75421f27540e 31
CCastrop1012 0:75421f27540e 32 DigitalOut L1;
CCastrop1012 0:75421f27540e 33 DigitalOut L2;
CCastrop1012 0:75421f27540e 34 PwmOut speedPin;
CCastrop1012 0:75421f27540e 35 DigitalIn encodin;
CCastrop1012 0:75421f27540e 36 DigitalIn PosInicial;
CCastrop1012 0:75421f27540e 37 int EncodPulses;
CCastrop1012 0:75421f27540e 38
CCastrop1012 0:75421f27540e 39
CCastrop1012 0:75421f27540e 40
CCastrop1012 0:75421f27540e 41
CCastrop1012 0:75421f27540e 42 };
CCastrop1012 0:75421f27540e 43
CCastrop1012 0:75421f27540e 44
CCastrop1012 0:75421f27540e 45 class MotorDiscreto {
CCastrop1012 0:75421f27540e 46 public:
CCastrop1012 0:75421f27540e 47 /// Constructores para Motores Continuos
CCastrop1012 0:75421f27540e 48 MotorDiscreto(PinName _Dir, PinName _Step, int _NPasos, PinName _encodin, PinName _PosInicial, int _EncodPulses);
CCastrop1012 0:75421f27540e 49 MotorDiscreto(void);
CCastrop1012 0:75421f27540e 50 void Forward(); // Da un sentido de giro al motor
CCastrop1012 0:75421f27540e 51 void Back(); // Genera un sentido de giro contrario al de Forward
CCastrop1012 0:75421f27540e 52 void Stop(); // Detiene el motor dejando el movimiento libre. Pin Enable = 0
CCastrop1012 0:75421f27540e 53 void StopT(); // Detiene el motor truncando o enclavando el movimiento(Lo mantiene quieto).
CCastrop1012 0:75421f27540e 54 void StepFreq(int n); // Configura la Velocidad en Número(n) de pasos por segundos. Es decir la Frecuencia de paso.
CCastrop1012 0:75421f27540e 55 void RunStep(long n); // Se mueve el motor la cantidad de pasos ingresada
CCastrop1012 0:75421f27540e 56 void Run(float t); // Gira el motor durante el tiempo ingresado, si es 0 indefinidamente hasta llamada a Stop().
CCastrop1012 0:75421f27540e 57 void RunRound(int n); // Girar n vueltas
CCastrop1012 0:75421f27540e 58 void Ustep(int resolucion, PinName M0, PinName M1, PinName M2);
CCastrop1012 0:75421f27540e 59 // Configura los pasos a 1/2, 1/4, 1/8, 1/16, 1/32
CCastrop1012 0:75421f27540e 60
CCastrop1012 0:75421f27540e 61
CCastrop1012 0:75421f27540e 62 long StepOnHold; // Pasos faltantes por ejecutar
CCastrop1012 0:75421f27540e 63 long StepsBySecond; // Pasos por segundo
CCastrop1012 0:75421f27540e 64
CCastrop1012 0:75421f27540e 65 private:
CCastrop1012 0:75421f27540e 66
CCastrop1012 0:75421f27540e 67 void moveMotor(void);
CCastrop1012 0:75421f27540e 68
CCastrop1012 0:75421f27540e 69 DigitalOut Dir;
CCastrop1012 0:75421f27540e 70 DigitalOut Step;
CCastrop1012 0:75421f27540e 71 int NPasos;
CCastrop1012 0:75421f27540e 72 DigitalIn encodin;
CCastrop1012 0:75421f27540e 73 DigitalIn PosInicial;
CCastrop1012 0:75421f27540e 74 int EncodPulses;
CCastrop1012 0:75421f27540e 75
CCastrop1012 0:75421f27540e 76 DigitalOut* EnablePin;
CCastrop1012 0:75421f27540e 77 DigitalOut* M0;
CCastrop1012 0:75421f27540e 78 DigitalOut* M1;
CCastrop1012 0:75421f27540e 79 DigitalOut* M2;
CCastrop1012 0:75421f27540e 80
CCastrop1012 0:75421f27540e 81 Ticker Move; /// Timer de interrupcion
CCastrop1012 0:75421f27540e 82 float TStep; /// periodo del paso TStep = 1/StepsBySecond;
CCastrop1012 0:75421f27540e 83
CCastrop1012 0:75421f27540e 84 int entradas; /// registra cada 2 ingresos a la interrupcion
CCastrop1012 0:75421f27540e 85
CCastrop1012 0:75421f27540e 86 };
CCastrop1012 0:75421f27540e 87 #endif
CCastrop1012 0:75421f27540e 88
CCastrop1012 0:75421f27540e 89
CCastrop1012 0:75421f27540e 90
CCastrop1012 0:75421f27540e 91
CCastrop1012 0:75421f27540e 92
CCastrop1012 0:75421f27540e 93
CCastrop1012 0:75421f27540e 94
CCastrop1012 0:75421f27540e 95
CCastrop1012 0:75421f27540e 96
CCastrop1012 0:75421f27540e 97
CCastrop1012 0:75421f27540e 98
CCastrop1012 0:75421f27540e 99
CCastrop1012 0:75421f27540e 100
CCastrop1012 0:75421f27540e 101
CCastrop1012 0:75421f27540e 102