Dependents:   Card_activated_robot MagicChassis Capstone Collision_Avoidance_Robot-Car ... more

Committer:
farbodjam
Date:
Tue Oct 04 10:17:16 2011 +0000
Revision:
0:541fb1742c8b

        

Who changed what in which revision?

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