Robot project.

Dependencies:   HCSR04 PID QEI mbed

Committer:
srsmitherman
Date:
Thu Dec 12 17:30:49 2013 +0000
Revision:
1:82463f25fd3c
Initial publish.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
srsmitherman 1:82463f25fd3c 1 /*
srsmitherman 1:82463f25fd3c 2 * @file DRV8833.h
srsmitherman 1:82463f25fd3c 3 * @author Oskar Lopez de Gamboa
srsmitherman 1:82463f25fd3c 4 *
srsmitherman 1:82463f25fd3c 5 * @section LICENSE
srsmitherman 1:82463f25fd3c 6 *
srsmitherman 1:82463f25fd3c 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
srsmitherman 1:82463f25fd3c 8 * and associated documentation files (the "Software"), to deal in the Software without restriction,
srsmitherman 1:82463f25fd3c 9 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
srsmitherman 1:82463f25fd3c 10 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
srsmitherman 1:82463f25fd3c 11 * furnished to do so, subject to the following conditions:
srsmitherman 1:82463f25fd3c 12 *
srsmitherman 1:82463f25fd3c 13 * The above copyright notice and this permission notice shall be included in all copies or
srsmitherman 1:82463f25fd3c 14 * substantial portions of the Software.
srsmitherman 1:82463f25fd3c 15 *
srsmitherman 1:82463f25fd3c 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
srsmitherman 1:82463f25fd3c 17 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
srsmitherman 1:82463f25fd3c 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
srsmitherman 1:82463f25fd3c 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
srsmitherman 1:82463f25fd3c 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
srsmitherman 1:82463f25fd3c 21 *
srsmitherman 1:82463f25fd3c 22 * @section DESCRIPTION
srsmitherman 1:82463f25fd3c 23 *
srsmitherman 1:82463f25fd3c 24 * mbed simple DRV8833 H-bridge motor controller
srsmitherman 1:82463f25fd3c 25 *
srsmitherman 1:82463f25fd3c 26 *
srsmitherman 1:82463f25fd3c 27 * PWM a un puente en H(DRV8833) conectado a los motores.
srsmitherman 1:82463f25fd3c 28 * El comportamiento del driver es el siguiente:
srsmitherman 1:82463f25fd3c 29 *
srsmitherman 1:82463f25fd3c 30 * x_PWM1 x_PWM2 Mode
srsmitherman 1:82463f25fd3c 31 * 0 0 Coast/Fast decay
srsmitherman 1:82463f25fd3c 32 * 0 1 Reverse
srsmitherman 1:82463f25fd3c 33 * 1 0 Forward
srsmitherman 1:82463f25fd3c 34 * 1 1 Brake/slow decay
srsmitherman 1:82463f25fd3c 35 *10/12/2013
srsmitherman 1:82463f25fd3c 36 */
srsmitherman 1:82463f25fd3c 37 #ifndef MBED_DRV8833
srsmitherman 1:82463f25fd3c 38 #define MBED_DRV8833
srsmitherman 1:82463f25fd3c 39
srsmitherman 1:82463f25fd3c 40 #include "mbed.h"
srsmitherman 1:82463f25fd3c 41
srsmitherman 1:82463f25fd3c 42 #define COAST 1
srsmitherman 1:82463f25fd3c 43 #define BRAKE 0
srsmitherman 1:82463f25fd3c 44
srsmitherman 1:82463f25fd3c 45 /** Interface to control a standard DC motor
srsmitherman 1:82463f25fd3c 46 * with an DRV8833 H-bridge motor controller
srsmitherman 1:82463f25fd3c 47 * using 2 PwmOuts
srsmitherman 1:82463f25fd3c 48 */
srsmitherman 1:82463f25fd3c 49 class DRV8833 {
srsmitherman 1:82463f25fd3c 50 public:
srsmitherman 1:82463f25fd3c 51
srsmitherman 1:82463f25fd3c 52 /** Creates a DRV8833(H-bridge motor controller) control interface
srsmitherman 1:82463f25fd3c 53 *
srsmitherman 1:82463f25fd3c 54 * @param pwm1 A PwmOut pin, tied to the AIN1 Logic input, controls state of AOUT1
srsmitherman 1:82463f25fd3c 55 * @param pwm2 A PwmOut pin, tied to the AIN2 Logic input controls state of AOUT2
srsmitherman 1:82463f25fd3c 56 *
srsmitherman 1:82463f25fd3c 57 */
srsmitherman 1:82463f25fd3c 58 DRV8833(PinName pwm1, PinName pwm2);
srsmitherman 1:82463f25fd3c 59
srsmitherman 1:82463f25fd3c 60 /** Set the speed of the motor
srsmitherman 1:82463f25fd3c 61 *
srsmitherman 1:82463f25fd3c 62 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
srsmitherman 1:82463f25fd3c 63 */
srsmitherman 1:82463f25fd3c 64 void speed(float speed);
srsmitherman 1:82463f25fd3c 65
srsmitherman 1:82463f25fd3c 66 /** Set the period of the pwm duty cycle.
srsmitherman 1:82463f25fd3c 67 *
srsmitherman 1:82463f25fd3c 68 * Wrapper for PwmOut::period()
srsmitherman 1:82463f25fd3c 69 *
srsmitherman 1:82463f25fd3c 70 * @param seconds - Pwm duty cycle in seconds.
srsmitherman 1:82463f25fd3c 71 */
srsmitherman 1:82463f25fd3c 72 void period(float period);
srsmitherman 1:82463f25fd3c 73
srsmitherman 1:82463f25fd3c 74 /** Return the speed.
srsmitherman 1:82463f25fd3c 75 *
srsmitherman 1:82463f25fd3c 76 * Returns float of the speed.
srsmitherman 1:82463f25fd3c 77 */
srsmitherman 1:82463f25fd3c 78 float getSpeed(void);
srsmitherman 1:82463f25fd3c 79
srsmitherman 1:82463f25fd3c 80 /** Return the period.
srsmitherman 1:82463f25fd3c 81 *
srsmitherman 1:82463f25fd3c 82 * Returns float of the period.
srsmitherman 1:82463f25fd3c 83 */
srsmitherman 1:82463f25fd3c 84 float getPeriod(void);
srsmitherman 1:82463f25fd3c 85
srsmitherman 1:82463f25fd3c 86 /** Brake the H-bridge coast or brake.
srsmitherman 1:82463f25fd3c 87 *
srsmitherman 1:82463f25fd3c 88 * Defaults to coast.
srsmitherman 1:82463f25fd3c 89 * @param mode - Braking mode.COAST(default)or BRAKE.
srsmitherman 1:82463f25fd3c 90 *
srsmitherman 1:82463f25fd3c 91 */
srsmitherman 1:82463f25fd3c 92 void brake(int mode = COAST);
srsmitherman 1:82463f25fd3c 93
srsmitherman 1:82463f25fd3c 94 protected:
srsmitherman 1:82463f25fd3c 95 PwmOut _pwm1;
srsmitherman 1:82463f25fd3c 96 PwmOut _pwm2;
srsmitherman 1:82463f25fd3c 97 float _speed;
srsmitherman 1:82463f25fd3c 98 float _period;
srsmitherman 1:82463f25fd3c 99
srsmitherman 1:82463f25fd3c 100 };
srsmitherman 1:82463f25fd3c 101
srsmitherman 1:82463f25fd3c 102 #endif