Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: maple_motores maple_heading_pid maple_chotobot_rf_motores motores ... more
motoresDC.h@0:b1e9ffb92a0a, 2015-12-22 (annotated)
- Committer:
- tabris2015
- Date:
- Tue Dec 22 20:52:05 2015 +0000
- Revision:
- 0:b1e9ffb92a0a
- Child:
- 1:5715aefb07ca
Library for using dual H-bridges with pwm and direction control like l298n, l293d and others
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tabris2015 | 0:b1e9ffb92a0a | 1 | /** motoresDC class |
| tabris2015 | 0:b1e9ffb92a0a | 2 | * libreria para controlar un driver dual de motores DC |
| tabris2015 | 0:b1e9ffb92a0a | 3 | * funciona con drivers como el L293D o el L298N |
| tabris2015 | 0:b1e9ffb92a0a | 4 | * se necesitan 6 pines del microcontrolador |
| tabris2015 | 0:b1e9ffb92a0a | 5 | * uno para la velocidad (PWM) y 2 para el sentido (digital) |
| tabris2015 | 0:b1e9ffb92a0a | 6 | * esta librería esta basada en la libreria RedBot de Sparkfun |
| tabris2015 | 0:b1e9ffb92a0a | 7 | |
| tabris2015 | 0:b1e9ffb92a0a | 8 | */ |
| tabris2015 | 0:b1e9ffb92a0a | 9 | #ifndef MBED_MOTORESDC_H |
| tabris2015 | 0:b1e9ffb92a0a | 10 | #define MBED_MOTORESDC_H |
| tabris2015 | 0:b1e9ffb92a0a | 11 | |
| tabris2015 | 0:b1e9ffb92a0a | 12 | #include "mbed.h" |
| tabris2015 | 0:b1e9ffb92a0a | 13 | |
| tabris2015 | 0:b1e9ffb92a0a | 14 | class MotoresDC |
| tabris2015 | 0:b1e9ffb92a0a | 15 | { |
| tabris2015 | 0:b1e9ffb92a0a | 16 | public: |
| tabris2015 | 0:b1e9ffb92a0a | 17 | /**inicia la clase con los pines del driver**/ |
| tabris2015 | 0:b1e9ffb92a0a | 18 | MotoresDC(PinName MI_vel, PinName MI_s1, PinName MI_s2, |
| tabris2015 | 0:b1e9ffb92a0a | 19 | PinName MD_vel, PinName MD_s1, PinName MD_s2); |
| tabris2015 | 0:b1e9ffb92a0a | 20 | // metodos publicos // |
| tabris2015 | 0:b1e9ffb92a0a | 21 | /* funcion para conducir ambos motores en la misma direccion */ |
| tabris2015 | 0:b1e9ffb92a0a | 22 | void conducir(float velocidad); |
| tabris2015 | 0:b1e9ffb92a0a | 23 | void conducir(float velocidad, int duracion); |
| tabris2015 | 0:b1e9ffb92a0a | 24 | /* funcion para conducir motores en sentido contrario */ |
| tabris2015 | 0:b1e9ffb92a0a | 25 | void pivotar(float velocidad); |
| tabris2015 | 0:b1e9ffb92a0a | 26 | void pivotar(float velocidad, int duracion); |
| tabris2015 | 0:b1e9ffb92a0a | 27 | |
| tabris2015 | 0:b1e9ffb92a0a | 28 | /* funciones para conducir motores independientemente */ |
| tabris2015 | 0:b1e9ffb92a0a | 29 | void motorIzq(float velocidad); |
| tabris2015 | 0:b1e9ffb92a0a | 30 | void motorDer(float velocidad); |
| tabris2015 | 0:b1e9ffb92a0a | 31 | /* funciones para conducir motores independientemente con duracion */ |
| tabris2015 | 0:b1e9ffb92a0a | 32 | void motorIzq(float velocidad, int duracion); |
| tabris2015 | 0:b1e9ffb92a0a | 33 | void motorDer(float velocidad, int duracion); |
| tabris2015 | 0:b1e9ffb92a0a | 34 | /* funciones para detener los motores */ |
| tabris2015 | 0:b1e9ffb92a0a | 35 | void detener(void); |
| tabris2015 | 0:b1e9ffb92a0a | 36 | void frenar(void); |
| tabris2015 | 0:b1e9ffb92a0a | 37 | |
| tabris2015 | 0:b1e9ffb92a0a | 38 | void detenerIzq(void); |
| tabris2015 | 0:b1e9ffb92a0a | 39 | void detenerDer(void); |
| tabris2015 | 0:b1e9ffb92a0a | 40 | void frenarIzq(void); |
| tabris2015 | 0:b1e9ffb92a0a | 41 | void frenarDer(void); |
| tabris2015 | 0:b1e9ffb92a0a | 42 | /* --------------- */ |
| tabris2015 | 0:b1e9ffb92a0a | 43 | // metodos y atributos privados // |
| tabris2015 | 0:b1e9ffb92a0a | 44 | private: |
| tabris2015 | 0:b1e9ffb92a0a | 45 | /* velocidad izquierda */ |
| tabris2015 | 0:b1e9ffb92a0a | 46 | PwmOut _MI_vel; |
| tabris2015 | 0:b1e9ffb92a0a | 47 | /* sentido de giro */ |
| tabris2015 | 0:b1e9ffb92a0a | 48 | DigitalOut _MI_s1; // motor izq |
| tabris2015 | 0:b1e9ffb92a0a | 49 | DigitalOut _MI_s2; |
| tabris2015 | 0:b1e9ffb92a0a | 50 | /* velocidad derecha */ |
| tabris2015 | 0:b1e9ffb92a0a | 51 | PwmOut _MD_vel; |
| tabris2015 | 0:b1e9ffb92a0a | 52 | /* sentido de giro */ |
| tabris2015 | 0:b1e9ffb92a0a | 53 | DigitalOut _MD_s1; |
| tabris2015 | 0:b1e9ffb92a0a | 54 | DigitalOut _MD_s2; |
| tabris2015 | 0:b1e9ffb92a0a | 55 | |
| tabris2015 | 0:b1e9ffb92a0a | 56 | /* funciones */ |
| tabris2015 | 0:b1e9ffb92a0a | 57 | void _izqAdelante(float velocidad); |
| tabris2015 | 0:b1e9ffb92a0a | 58 | void _izqAtras(float velocidad); |
| tabris2015 | 0:b1e9ffb92a0a | 59 | void _derAdelante(float velocidad); |
| tabris2015 | 0:b1e9ffb92a0a | 60 | void _derAtras(float velocidad); |
| tabris2015 | 0:b1e9ffb92a0a | 61 | |
| tabris2015 | 0:b1e9ffb92a0a | 62 | }; |
| tabris2015 | 0:b1e9ffb92a0a | 63 | #endif |