Based on myBlueUSB reference ver. http://mbed.org/users/networker/programs/myBlueUSB/lsm1ui

Dependencies:   mbed myUSBHost AvailableMemory rfcomm myBlueUSB sdp

Committer:
kenbumono
Date:
Tue Jul 05 08:25:59 2011 +0000
Revision:
0:8d8481ed6d49

        

Who changed what in which revision?

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