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