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