motor library

Dependents:   Biorobotics_g15

Committer:
boydmartherus
Date:
Fri Sep 20 12:51:10 2019 +0000
Revision:
0:a208f016a596
motor+pulse+flip?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
boydmartherus 0:a208f016a596 1 /* mbed simple H-bridge motor controller
boydmartherus 0:a208f016a596 2 * Copyright (c) 2007-2010, sford, http://mbed.org
boydmartherus 0:a208f016a596 3 *
boydmartherus 0:a208f016a596 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
boydmartherus 0:a208f016a596 5 * of this software and associated documentation files (the "Software"), to deal
boydmartherus 0:a208f016a596 6 * in the Software without restriction, including without limitation the rights
boydmartherus 0:a208f016a596 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
boydmartherus 0:a208f016a596 8 * copies of the Software, and to permit persons to whom the Software is
boydmartherus 0:a208f016a596 9 * furnished to do so, subject to the following conditions:
boydmartherus 0:a208f016a596 10 *
boydmartherus 0:a208f016a596 11 * The above copyright notice and this permission notice shall be included in
boydmartherus 0:a208f016a596 12 * all copies or substantial portions of the Software.
boydmartherus 0:a208f016a596 13 *
boydmartherus 0:a208f016a596 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
boydmartherus 0:a208f016a596 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
boydmartherus 0:a208f016a596 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
boydmartherus 0:a208f016a596 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
boydmartherus 0:a208f016a596 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
boydmartherus 0:a208f016a596 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
boydmartherus 0:a208f016a596 20 * THE SOFTWARE.
boydmartherus 0:a208f016a596 21 */
boydmartherus 0:a208f016a596 22
boydmartherus 0:a208f016a596 23 #ifndef MBED_MOTOR_H
boydmartherus 0:a208f016a596 24 #define MBED_MOTOR_H
boydmartherus 0:a208f016a596 25
boydmartherus 0:a208f016a596 26 #include "mbed.h"
boydmartherus 0:a208f016a596 27
boydmartherus 0:a208f016a596 28 /** Interface to control a standard DC motor
boydmartherus 0:a208f016a596 29 *
boydmartherus 0:a208f016a596 30 * with an H-bridge using a PwmOut and 2 DigitalOuts
boydmartherus 0:a208f016a596 31 */
boydmartherus 0:a208f016a596 32 class Motor {
boydmartherus 0:a208f016a596 33 public:
boydmartherus 0:a208f016a596 34
boydmartherus 0:a208f016a596 35 /** Create a motor control interface
boydmartherus 0:a208f016a596 36 *
boydmartherus 0:a208f016a596 37 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
boydmartherus 0:a208f016a596 38 * @param fwd A DigitalOut, set high when the motor should go forward
boydmartherus 0:a208f016a596 39 * @param rev A DigitalOut, set high when the motor should go backwards
boydmartherus 0:a208f016a596 40 */
boydmartherus 0:a208f016a596 41 Motor(PinName pwm, PinName fwd, PinName rev);
boydmartherus 0:a208f016a596 42
boydmartherus 0:a208f016a596 43 /** Set the speed of the motor
boydmartherus 0:a208f016a596 44 *
boydmartherus 0:a208f016a596 45 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
boydmartherus 0:a208f016a596 46 */
boydmartherus 0:a208f016a596 47 void speed(float speed);
boydmartherus 0:a208f016a596 48
boydmartherus 0:a208f016a596 49 protected:
boydmartherus 0:a208f016a596 50 PwmOut _pwm;
boydmartherus 0:a208f016a596 51 DigitalOut _fwd;
boydmartherus 0:a208f016a596 52 DigitalOut _rev;
boydmartherus 0:a208f016a596 53
boydmartherus 0:a208f016a596 54 };
boydmartherus 0:a208f016a596 55
boydmartherus 0:a208f016a596 56 #endif