![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
55+
Dependencies: BEAR_Protocol_Edited BufferedSerial Debug MaxSonar PID Process QEI UI iSerial mbed
Fork of CleaningMachine_Betago by
motor/Motor.h@1:45f1573d65a1, 2016-03-21 (annotated)
- Committer:
- palmdotax
- Date:
- Mon Mar 21 20:21:12 2016 +0000
- Revision:
- 1:45f1573d65a1
aaaaa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
palmdotax | 1:45f1573d65a1 | 1 | /* mbed simple H-bridge motor controller |
palmdotax | 1:45f1573d65a1 | 2 | * Copyright (c) 2007-2010, sford |
palmdotax | 1:45f1573d65a1 | 3 | * |
palmdotax | 1:45f1573d65a1 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
palmdotax | 1:45f1573d65a1 | 5 | * of this software and associated documentation files (the "Software"), to deal |
palmdotax | 1:45f1573d65a1 | 6 | * in the Software without restriction, including without limitation the rights |
palmdotax | 1:45f1573d65a1 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
palmdotax | 1:45f1573d65a1 | 8 | * copies of the Software, and to permit persons to whom the Software is |
palmdotax | 1:45f1573d65a1 | 9 | * furnished to do so, subject to the following conditions: |
palmdotax | 1:45f1573d65a1 | 10 | * |
palmdotax | 1:45f1573d65a1 | 11 | * The above copyright notice and this permission notice shall be included in |
palmdotax | 1:45f1573d65a1 | 12 | * all copies or substantial portions of the Software. |
palmdotax | 1:45f1573d65a1 | 13 | * |
palmdotax | 1:45f1573d65a1 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
palmdotax | 1:45f1573d65a1 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
palmdotax | 1:45f1573d65a1 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
palmdotax | 1:45f1573d65a1 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
palmdotax | 1:45f1573d65a1 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
palmdotax | 1:45f1573d65a1 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
palmdotax | 1:45f1573d65a1 | 20 | * THE SOFTWARE. |
palmdotax | 1:45f1573d65a1 | 21 | */ |
palmdotax | 1:45f1573d65a1 | 22 | |
palmdotax | 1:45f1573d65a1 | 23 | #ifndef MBED_MOTOR_H |
palmdotax | 1:45f1573d65a1 | 24 | #define MBED_MOTOR_H |
palmdotax | 1:45f1573d65a1 | 25 | |
palmdotax | 1:45f1573d65a1 | 26 | #include "mbed.h" |
palmdotax | 1:45f1573d65a1 | 27 | |
palmdotax | 1:45f1573d65a1 | 28 | #define BRAKE_HIGH 1 |
palmdotax | 1:45f1573d65a1 | 29 | #define BRAKE_LOW 0 |
palmdotax | 1:45f1573d65a1 | 30 | |
palmdotax | 1:45f1573d65a1 | 31 | /** Interface to control a standard DC motor |
palmdotax | 1:45f1573d65a1 | 32 | * with an H-bridge using a PwmOut and 2 DigitalOuts |
palmdotax | 1:45f1573d65a1 | 33 | */ |
palmdotax | 1:45f1573d65a1 | 34 | class Motor { |
palmdotax | 1:45f1573d65a1 | 35 | public: |
palmdotax | 1:45f1573d65a1 | 36 | |
palmdotax | 1:45f1573d65a1 | 37 | /** Create a motor control interface |
palmdotax | 1:45f1573d65a1 | 38 | * |
palmdotax | 1:45f1573d65a1 | 39 | * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed |
palmdotax | 1:45f1573d65a1 | 40 | * @param fwd A DigitalOut, set high when the motor should go forward |
palmdotax | 1:45f1573d65a1 | 41 | * @param rev A DigitalOut, set high when the motor should go backwards |
palmdotax | 1:45f1573d65a1 | 42 | */ |
palmdotax | 1:45f1573d65a1 | 43 | Motor(PinName pwm, PinName fwd, PinName rev); |
palmdotax | 1:45f1573d65a1 | 44 | |
palmdotax | 1:45f1573d65a1 | 45 | /** Set the speed of the motor |
palmdotax | 1:45f1573d65a1 | 46 | * |
palmdotax | 1:45f1573d65a1 | 47 | * @param speed The speed of the motor as a normalised value between -1.0 and 1.0 |
palmdotax | 1:45f1573d65a1 | 48 | */ |
palmdotax | 1:45f1573d65a1 | 49 | void speed(float speed); |
palmdotax | 1:45f1573d65a1 | 50 | |
palmdotax | 1:45f1573d65a1 | 51 | /** Set the period of the pwm duty cycle. |
palmdotax | 1:45f1573d65a1 | 52 | * |
palmdotax | 1:45f1573d65a1 | 53 | * Wrapper for PwmOut::period() |
palmdotax | 1:45f1573d65a1 | 54 | * |
palmdotax | 1:45f1573d65a1 | 55 | * @param seconds - Pwm duty cycle in seconds. |
palmdotax | 1:45f1573d65a1 | 56 | */ |
palmdotax | 1:45f1573d65a1 | 57 | void period(float period); |
palmdotax | 1:45f1573d65a1 | 58 | |
palmdotax | 1:45f1573d65a1 | 59 | /** Brake the H-bridge to GND or VCC. |
palmdotax | 1:45f1573d65a1 | 60 | * |
palmdotax | 1:45f1573d65a1 | 61 | * Defaults to breaking to VCC. |
palmdotax | 1:45f1573d65a1 | 62 | * |
palmdotax | 1:45f1573d65a1 | 63 | * Brake to GND => inA = inB = 0 |
palmdotax | 1:45f1573d65a1 | 64 | * Brake to VCC => inA = inB = 1 |
palmdotax | 1:45f1573d65a1 | 65 | */ |
palmdotax | 1:45f1573d65a1 | 66 | void brake(int highLow = BRAKE_HIGH); |
palmdotax | 1:45f1573d65a1 | 67 | |
palmdotax | 1:45f1573d65a1 | 68 | protected: |
palmdotax | 1:45f1573d65a1 | 69 | PwmOut _pwm; |
palmdotax | 1:45f1573d65a1 | 70 | DigitalOut _fwd; |
palmdotax | 1:45f1573d65a1 | 71 | DigitalOut _rev; |
palmdotax | 1:45f1573d65a1 | 72 | |
palmdotax | 1:45f1573d65a1 | 73 | }; |
palmdotax | 1:45f1573d65a1 | 74 | |
palmdotax | 1:45f1573d65a1 | 75 | #endif |
palmdotax | 1:45f1573d65a1 | 76 |