Modelado de un sistema de control para el movimiento de un motor NEMA.

Dependencies:   mbed

Committer:
CCastrop1012
Date:
Fri Sep 03 05:13:46 2021 +0000
Revision:
0:f46e78766b9c
Modelo de sistema de control para un motor.

Who changed what in which revision?

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