motor drive libary to use speed control, coasting and dynamic braking. NOTE, dynamic braking my result in large currents. this may or may not set the motor driver on fire/break it/other undesired effects. so read the data sheet folks.

Dependents:   motordrivertestprogram Initialmbedrobotprogram mbedrobot ipod ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motordriver.h Source File

motordriver.h

00001 /*motor driver libary modified from the following libary,
00002 *  
00003 * mbed simple H-bridge motor controller
00004 * Copyright (c) 2007-2010, sford
00005 * 
00006 * by Christopher Hasler.
00007 * 
00008 * from sford's libary,
00009 *
00010 * Permission is hereby granted, free of charge, to any person obtaining a copy
00011 * of this software and associated documentation files (the "Software"), to deal
00012 * in the Software without restriction, including without limitation the rights
00013 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00014 * copies of the Software, and to permit persons to whom the Software is
00015 * furnished to do so, subject to the following conditions:
00016 *
00017 * The above copyright notice and this permission notice shall be included in
00018 * all copies or substantial portions of the Software.
00019 *
00020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00023 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00024 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00025 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00026 * THE SOFTWARE.
00027 */
00028  
00029 #ifndef MBED_MOTOR_H
00030 #define MBED_MOTOR_H
00031  
00032 #include "mbed.h"
00033  
00034 /** Interface to control a standard DC motor 
00035 * with an H-bridge using a PwmOut and 2 DigitalOuts
00036 */
00037 class Motor {
00038     public:
00039  
00040 /** Create a motor control interface    
00041 *
00042 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
00043 * @param fwd A DigitalOut, set high when the motor should go forward
00044 * @param rev A DigitalOut, set high when the motor should go backwards
00045 * @param set if the motor driver is able to do braking 0 false 1 true.
00046 */
00047         Motor(PinName pwm, PinName fwd, PinName rev, int brakeable);
00048   
00049 /** Set the speed of the motor 
00050 * 
00051 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0.
00052 * @return the applied speed to the motor after checking to ensure motor doesn't switch from forward to reverse without stopping.
00053 */
00054         float speed(float speed);
00055         
00056 /** Set the the motor to coast
00057 * 
00058 * @param void 
00059 * @return motor coasts until another instruction is recived.
00060 */        
00061   
00062         void coast(void);
00063 
00064 /** Set the motor to dynamicaly brake
00065 * 
00066 * @param float 0 - 1.0 provides some control over how hard the motor brakes. 
00067 * @return duty applied to motor driver. -1 is error, motor driver can't brake.
00068 */
00069 
00070         float stop(float duty);
00071 /** return the current state of the motor
00072 *
00073 * @param void
00074 * @return state of motor, -1 to 1 is speed, -2 is braking, 2 is coasting. -3 is error. 
00075 */
00076         float state(void);
00077         
00078     protected:
00079         PwmOut _pwm;
00080         DigitalOut _fwd;
00081         DigitalOut _rev;
00082         int Brakeable; // cna the motor driver break
00083         int sign; //prevents throwing the motor from full foward to full reverse and stuff melting.
00084  
00085 };
00086 
00087 
00088 
00089 
00090 
00091 #endif