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