Based on PS3_BlueUSB with reference to http://blog.goo.ne.jp/roboz80/e/10e7bf38d3a63b996ca2894e9fb5e3b6

Dependencies:   TextLCD mbed

Committer:
kenbumono
Date:
Tue Jul 05 08:25:40 2011 +0000
Revision:
0:44619612f575

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenbumono 0:44619612f575 1 /*motor driver libary modified from the following libary,
kenbumono 0:44619612f575 2 *
kenbumono 0:44619612f575 3 * mbed simple H-bridge motor controller
kenbumono 0:44619612f575 4 * Copyright (c) 2007-2010, sford
kenbumono 0:44619612f575 5 *
kenbumono 0:44619612f575 6 * by Christopher Hasler.
kenbumono 0:44619612f575 7 *
kenbumono 0:44619612f575 8 * from sford's libary,
kenbumono 0:44619612f575 9 *
kenbumono 0:44619612f575 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
kenbumono 0:44619612f575 11 * of this software and associated documentation files (the "Software"), to deal
kenbumono 0:44619612f575 12 * in the Software without restriction, including without limitation the rights
kenbumono 0:44619612f575 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
kenbumono 0:44619612f575 14 * copies of the Software, and to permit persons to whom the Software is
kenbumono 0:44619612f575 15 * furnished to do so, subject to the following conditions:
kenbumono 0:44619612f575 16 *
kenbumono 0:44619612f575 17 * The above copyright notice and this permission notice shall be included in
kenbumono 0:44619612f575 18 * all copies or substantial portions of the Software.
kenbumono 0:44619612f575 19 *
kenbumono 0:44619612f575 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
kenbumono 0:44619612f575 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
kenbumono 0:44619612f575 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
kenbumono 0:44619612f575 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
kenbumono 0:44619612f575 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kenbumono 0:44619612f575 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
kenbumono 0:44619612f575 26 * THE SOFTWARE.
kenbumono 0:44619612f575 27 */
kenbumono 0:44619612f575 28
kenbumono 0:44619612f575 29 #ifndef MBED_MOTOR_H
kenbumono 0:44619612f575 30 #define MBED_MOTOR_H
kenbumono 0:44619612f575 31
kenbumono 0:44619612f575 32 #include "mbed.h"
kenbumono 0:44619612f575 33
kenbumono 0:44619612f575 34 /** Interface to control a standard DC motor
kenbumono 0:44619612f575 35 * with an H-bridge using a PwmOut and 2 DigitalOuts
kenbumono 0:44619612f575 36 */
kenbumono 0:44619612f575 37 class Motor {
kenbumono 0:44619612f575 38 public:
kenbumono 0:44619612f575 39
kenbumono 0:44619612f575 40 /** Create a motor control interface
kenbumono 0:44619612f575 41 *
kenbumono 0:44619612f575 42 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
kenbumono 0:44619612f575 43 * @param fwd A DigitalOut, set high when the motor should go forward
kenbumono 0:44619612f575 44 * @param rev A DigitalOut, set high when the motor should go backwards
kenbumono 0:44619612f575 45 * @param set if the motor driver is able to do braking 0 false 1 true.
kenbumono 0:44619612f575 46 */
kenbumono 0:44619612f575 47 Motor(PinName pwm, PinName fwd, PinName rev, bool brakeable = false);
kenbumono 0:44619612f575 48
kenbumono 0:44619612f575 49 /** Set the speed of the motor
kenbumono 0:44619612f575 50 *
kenbumono 0:44619612f575 51 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0.
kenbumono 0:44619612f575 52 * @return the applied speed to the motor after checking to ensure motor doesn't switch from forward to reverse without stopping.
kenbumono 0:44619612f575 53 */
kenbumono 0:44619612f575 54 float speed(float speed);
kenbumono 0:44619612f575 55
kenbumono 0:44619612f575 56 /** Set the the motor to coast
kenbumono 0:44619612f575 57 *
kenbumono 0:44619612f575 58 * @param void
kenbumono 0:44619612f575 59 * @return motor coasts until another instruction is recived.
kenbumono 0:44619612f575 60 */
kenbumono 0:44619612f575 61
kenbumono 0:44619612f575 62 void coast(void);
kenbumono 0:44619612f575 63
kenbumono 0:44619612f575 64 /** Set the motor to dynamicaly brake
kenbumono 0:44619612f575 65 *
kenbumono 0:44619612f575 66 * @param float 0 - 1.0 provides some control over how hard the motor brakes.
kenbumono 0:44619612f575 67 * @return duty applied to motor driver. -1 is error, motor driver can't brake.
kenbumono 0:44619612f575 68 */
kenbumono 0:44619612f575 69
kenbumono 0:44619612f575 70 float stop(float duty);
kenbumono 0:44619612f575 71 /** return the current state of the motor
kenbumono 0:44619612f575 72 *
kenbumono 0:44619612f575 73 * @param void
kenbumono 0:44619612f575 74 * @return state of motor, -1 to 1 is speed, -2 is braking, 2 is coasting. -3 is error.
kenbumono 0:44619612f575 75 */
kenbumono 0:44619612f575 76 float state(void) const;
kenbumono 0:44619612f575 77
kenbumono 0:44619612f575 78 protected:
kenbumono 0:44619612f575 79 mutable PwmOut _pwm;
kenbumono 0:44619612f575 80 mutable DigitalOut _fwd;
kenbumono 0:44619612f575 81 mutable DigitalOut _rev;
kenbumono 0:44619612f575 82 bool _brakeable; // cna the motor driver break
kenbumono 0:44619612f575 83 int _sign; //prevents throwing the motor from full foward to full reverse and stuff melting.
kenbumono 0:44619612f575 84
kenbumono 0:44619612f575 85 };
kenbumono 0:44619612f575 86
kenbumono 0:44619612f575 87
kenbumono 0:44619612f575 88
kenbumono 0:44619612f575 89
kenbumono 0:44619612f575 90
kenbumono 0:44619612f575 91 #endif