Proyecto final de semestre: Se desarrollo un vehículo que recibe comandos por el puerto serial y realiza las siguientes funciones según el comando sea el comando recibido: - Genera distintos tonos por un buzzer. - Controla el movimiento de un carro (con 2 motores) con comandos - Controla el movimiento de un carro (con 2 motores) con Joystick. - Lee y envía el color leido por el puerto serial al PC - Muestra los colores leídos por una pantalla FFT instalada en el vehículo.

Dependencies:   mbed UniGraphic

Committer:
CCastrop1012
Date:
Fri Sep 03 05:26:27 2021 +0000
Revision:
0:3a420fc22672
Proyecto de final de semestre, finalizado y funcional.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CCastrop1012 0:3a420fc22672 1 #ifndef Motor_H
CCastrop1012 0:3a420fc22672 2 #define Motor_H
CCastrop1012 0:3a420fc22672 3 #include "mbed.h"
CCastrop1012 0:3a420fc22672 4 /* **************************************************************************
CCastrop1012 0:3a420fc22672 5
CCastrop1012 0:3a420fc22672 6 @CCastrop
CCastrop1012 0:3a420fc22672 7 cristiank.castrop@ecci.edu.co
CCastrop1012 0:3a420fc22672 8
CCastrop1012 0:3a420fc22672 9 L1 Terminal A del motor
CCastrop1012 0:3a420fc22672 10 L2 Terminal B del motor
CCastrop1012 0:3a420fc22672 11 SpeedPin Pin de salida PWM
CCastrop1012 0:3a420fc22672 12
CCastrop1012 0:3a420fc22672 13 LastVersion: 21 - Abril - 2019 7:45pm
CCastrop1012 0:3a420fc22672 14 ******************************************************************************/
CCastrop1012 0:3a420fc22672 15
CCastrop1012 0:3a420fc22672 16
CCastrop1012 0:3a420fc22672 17 class MotorContinuo {
CCastrop1012 0:3a420fc22672 18 public:
CCastrop1012 0:3a420fc22672 19 /// Constructores para Motores Continuos
CCastrop1012 0:3a420fc22672 20 MotorContinuo(PinName _L1, PinName _L2, PinName _speedPin, PinName _encodin, PinName _PosInicial, int _EncodPulses);
CCastrop1012 0:3a420fc22672 21
CCastrop1012 0:3a420fc22672 22 void Forward(); // Da un sentido de giro al motor
CCastrop1012 0:3a420fc22672 23 void Back(); // Genera un sentido de giro contrario al de Forward
CCastrop1012 0:3a420fc22672 24 void Stop(); // Detiene el motor dejando el movimiento libre
CCastrop1012 0:3a420fc22672 25 void StopT(); // Detiene el motor truncando o enclavando el movimiento(Lo mantiene quieto).
CCastrop1012 0:3a420fc22672 26 void SpeedDuty(int v); // Varia la velocidad de giro del motor de 0 a 100%
CCastrop1012 0:3a420fc22672 27 void SpinLength_ms(float t); // Duración del giro en ms
CCastrop1012 0:3a420fc22672 28 void SpinLength(float t); // Duración del giro
CCastrop1012 0:3a420fc22672 29
CCastrop1012 0:3a420fc22672 30 private:
CCastrop1012 0:3a420fc22672 31
CCastrop1012 0:3a420fc22672 32 DigitalOut L1;
CCastrop1012 0:3a420fc22672 33 DigitalOut L2;
CCastrop1012 0:3a420fc22672 34 PwmOut speedPin;
CCastrop1012 0:3a420fc22672 35 DigitalIn encodin;
CCastrop1012 0:3a420fc22672 36 DigitalIn PosInicial;
CCastrop1012 0:3a420fc22672 37 int EncodPulses;
CCastrop1012 0:3a420fc22672 38
CCastrop1012 0:3a420fc22672 39
CCastrop1012 0:3a420fc22672 40
CCastrop1012 0:3a420fc22672 41
CCastrop1012 0:3a420fc22672 42 };
CCastrop1012 0:3a420fc22672 43
CCastrop1012 0:3a420fc22672 44
CCastrop1012 0:3a420fc22672 45 class MotorDiscreto {
CCastrop1012 0:3a420fc22672 46 public:
CCastrop1012 0:3a420fc22672 47 /// Constructores para Motores Continuos
CCastrop1012 0:3a420fc22672 48 MotorDiscreto(PinName _Dir, PinName _Step, int _NPasos, PinName _encodin, PinName _PosInicial, int _EncodPulses);
CCastrop1012 0:3a420fc22672 49
CCastrop1012 0:3a420fc22672 50 MotorDiscreto(void);
CCastrop1012 0:3a420fc22672 51
CCastrop1012 0:3a420fc22672 52 void Forward(); // Da un sentido de giro al motor
CCastrop1012 0:3a420fc22672 53 void Back(); // Genera un sentido de giro contrario al de Forward
CCastrop1012 0:3a420fc22672 54 void Stop(); // Detiene el motor dejando el movimiento libre. Pin Enable = 0
CCastrop1012 0:3a420fc22672 55 void StopT(); // Detiene el motor truncando o enclavando el movimiento(Lo mantiene quieto).
CCastrop1012 0:3a420fc22672 56 void StepFreq(long n); // Configura la Velocidad en Número(n) de pasos por segundos. Es decir la Frecuencia de paso.
CCastrop1012 0:3a420fc22672 57 void RunStep(long n); // Se mueve el motor la cantidad de pasos ingresada
CCastrop1012 0:3a420fc22672 58 void Run(float t); // Gira el motor durante el tiempo ingresado, si es 0 indefinidamente hasta llamada a Stop().
CCastrop1012 0:3a420fc22672 59 void RunRound(int n); // Girar n vueltas
CCastrop1012 0:3a420fc22672 60 void Ustep(int resolucion, PinName M0, PinName M1, PinName M2);
CCastrop1012 0:3a420fc22672 61 // Configura los pasos a 1/2, 1/4, 1/8, 1/16, 1/32
CCastrop1012 0:3a420fc22672 62 long getStepOnHold(void);
CCastrop1012 0:3a420fc22672 63
CCastrop1012 0:3a420fc22672 64 long StepOnHold; // Pasos faltantes por ejecutar
CCastrop1012 0:3a420fc22672 65 long StepsBySecond; // Pasos por segundo
CCastrop1012 0:3a420fc22672 66
CCastrop1012 0:3a420fc22672 67 private:
CCastrop1012 0:3a420fc22672 68
CCastrop1012 0:3a420fc22672 69 void moveMotor(void);
CCastrop1012 0:3a420fc22672 70
CCastrop1012 0:3a420fc22672 71 DigitalOut Dir;
CCastrop1012 0:3a420fc22672 72 DigitalOut Step;
CCastrop1012 0:3a420fc22672 73 int NPasos;
CCastrop1012 0:3a420fc22672 74 DigitalIn encodin;
CCastrop1012 0:3a420fc22672 75 DigitalIn PosInicial;
CCastrop1012 0:3a420fc22672 76 int EncodPulses;
CCastrop1012 0:3a420fc22672 77
CCastrop1012 0:3a420fc22672 78 DigitalOut* EnablePin;
CCastrop1012 0:3a420fc22672 79 DigitalOut* M0;
CCastrop1012 0:3a420fc22672 80 DigitalOut* M1;
CCastrop1012 0:3a420fc22672 81 DigitalOut* M2;
CCastrop1012 0:3a420fc22672 82
CCastrop1012 0:3a420fc22672 83 Ticker Move; /// Timer de interrupcion
CCastrop1012 0:3a420fc22672 84 float TStep; /// periodo del paso TStep = 1/StepsBySecond;
CCastrop1012 0:3a420fc22672 85
CCastrop1012 0:3a420fc22672 86 int entradas; /// registra cada 2 ingresos a la interrupcion
CCastrop1012 0:3a420fc22672 87 bool _moveMotorStopped; // en 1 cuando se da la orden al motor de detenerse
CCastrop1012 0:3a420fc22672 88 };
CCastrop1012 0:3a420fc22672 89
CCastrop1012 0:3a420fc22672 90
CCastrop1012 0:3a420fc22672 91
CCastrop1012 0:3a420fc22672 92
CCastrop1012 0:3a420fc22672 93 class TraccionD
CCastrop1012 0:3a420fc22672 94 {
CCastrop1012 0:3a420fc22672 95
CCastrop1012 0:3a420fc22672 96 public:
CCastrop1012 0:3a420fc22672 97
CCastrop1012 0:3a420fc22672 98 TraccionD(PinName _StepMI, PinName _DirMI, PinName _StepMD, PinName _DirMD, int _NPasos, float _r, float _L); // para giro declarar primero la frecuencia de paso
CCastrop1012 0:3a420fc22672 99
CCastrop1012 0:3a420fc22672 100 void Forward(); // Da un sentido de giro al motor
CCastrop1012 0:3a420fc22672 101 void Back(); // Genera un sentido de giro contrario al de Forward
CCastrop1012 0:3a420fc22672 102 void Left(); // Configura el sentido de giro de ambos motores de manera contraria para girar hacia la izquierda
CCastrop1012 0:3a420fc22672 103 void Right(); // Configura el sentido de giro de ambos motores de manera contraria e inverso al de Left() para girar hacia la derecha
CCastrop1012 0:3a420fc22672 104 void Stop(); // Detiene el motor dejando el movimiento libre. Pin Enable = 0
CCastrop1012 0:3a420fc22672 105 void StopT(); // Detiene el motor truncando o enclavando el movimiento(Lo mantiene quieto).
CCastrop1012 0:3a420fc22672 106 void StepFreq(long n);//maximo~350 // Configura la Velocidad en Número(n) de pasos por segundos. Es decir la Frecuencia de paso.
CCastrop1012 0:3a420fc22672 107 void RunStep(long n); // Se mueve el motor la cantidad de pasos ingresada
CCastrop1012 0:3a420fc22672 108 void Run(float t); // Gira el motor durante el tiempo ingresado, si es 0 indefinidamente hasta llamada a Stop().
CCastrop1012 0:3a420fc22672 109 void RunRound(int n); // Girar n vueltas
CCastrop1012 0:3a420fc22672 110 void Giro(long grados, bool sentido); // IMPORTANTE: Para llamar esta funcino PRIMERO se debe definir la frecuencia de paso
CCastrop1012 0:3a420fc22672 111 // Gira el movil la cantidad de grados indicados en sentido indicado.
CCastrop1012 0:3a420fc22672 112 // en función del radio de las llantas y el radio del eje que une las llantas.
CCastrop1012 0:3a420fc22672 113 // ejemplo: (90, Horario) o (120, AntiHorario)
CCastrop1012 0:3a420fc22672 114
CCastrop1012 0:3a420fc22672 115 long getStepOnHold(void);
CCastrop1012 0:3a420fc22672 116
CCastrop1012 0:3a420fc22672 117
CCastrop1012 0:3a420fc22672 118 private:
CCastrop1012 0:3a420fc22672 119
CCastrop1012 0:3a420fc22672 120 void moveMotor(void); // Funcion que es ejecutada cada interupcion del Ticker Move
CCastrop1012 0:3a420fc22672 121
CCastrop1012 0:3a420fc22672 122 // Configuracion de los pines
CCastrop1012 0:3a420fc22672 123 DigitalOut StepMI,DirMI;
CCastrop1012 0:3a420fc22672 124 DigitalOut StepMD, DirMD;
CCastrop1012 0:3a420fc22672 125 int NPasos;
CCastrop1012 0:3a420fc22672 126 float r; // Radio de la llanta
CCastrop1012 0:3a420fc22672 127 float L; // Longitud desde del eje medido entre las 2 llantas dividido en 2.
CCastrop1012 0:3a420fc22672 128 float Rl; // Relacion(Rl) de distacia entre los dos Radios(r y L)
CCastrop1012 0:3a420fc22672 129 long StepOnHold; // Pasos faltantes por ejecutar
CCastrop1012 0:3a420fc22672 130 long StepsBySecond; // Pasos por segundo
CCastrop1012 0:3a420fc22672 131
CCastrop1012 0:3a420fc22672 132 DigitalOut* EnablePinM1;
CCastrop1012 0:3a420fc22672 133 DigitalOut* EnablePinM2;
CCastrop1012 0:3a420fc22672 134
CCastrop1012 0:3a420fc22672 135 Ticker Move; /// Timer de interrupcion
CCastrop1012 0:3a420fc22672 136 float TStep; /// periodo del paso TStep = 1/StepsBySecond;
CCastrop1012 0:3a420fc22672 137
CCastrop1012 0:3a420fc22672 138 int entradas; /// registra cada 2 ingresos a la interrupcion
CCastrop1012 0:3a420fc22672 139
CCastrop1012 0:3a420fc22672 140
CCastrop1012 0:3a420fc22672 141
CCastrop1012 0:3a420fc22672 142
CCastrop1012 0:3a420fc22672 143
CCastrop1012 0:3a420fc22672 144 };
CCastrop1012 0:3a420fc22672 145 #endif
CCastrop1012 0:3a420fc22672 146
CCastrop1012 0:3a420fc22672 147
CCastrop1012 0:3a420fc22672 148
CCastrop1012 0:3a420fc22672 149
CCastrop1012 0:3a420fc22672 150
CCastrop1012 0:3a420fc22672 151
CCastrop1012 0:3a420fc22672 152
CCastrop1012 0:3a420fc22672 153
CCastrop1012 0:3a420fc22672 154
CCastrop1012 0:3a420fc22672 155
CCastrop1012 0:3a420fc22672 156
CCastrop1012 0:3a420fc22672 157
CCastrop1012 0:3a420fc22672 158
CCastrop1012 0:3a420fc22672 159
CCastrop1012 0:3a420fc22672 160