otamesi

Dependencies:   mbed

Committer:
seangshim
Date:
Sat Feb 16 05:40:24 2019 +0000
Revision:
41:7c537a922510
Parent:
0:a01fda36fde8
Child:
7:1c1b782263cf
nei

Who changed what in which revision?

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