Add Force Brake

Committer:
aberk
Date:
Thu Sep 02 16:32:57 2010 +0000
Revision:
0:f05e09f8f5d9
Child:
1:c75b234558af
Added period(...) method to allow the period on the PwmOut pin to be changed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aberk 0:f05e09f8f5d9 1 /* mbed simple H-bridge motor controller
aberk 0:f05e09f8f5d9 2 * Copyright (c) 2007-2010, sford
aberk 0:f05e09f8f5d9 3 *
aberk 0:f05e09f8f5d9 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
aberk 0:f05e09f8f5d9 5 * of this software and associated documentation files (the "Software"), to deal
aberk 0:f05e09f8f5d9 6 * in the Software without restriction, including without limitation the rights
aberk 0:f05e09f8f5d9 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
aberk 0:f05e09f8f5d9 8 * copies of the Software, and to permit persons to whom the Software is
aberk 0:f05e09f8f5d9 9 * furnished to do so, subject to the following conditions:
aberk 0:f05e09f8f5d9 10 *
aberk 0:f05e09f8f5d9 11 * The above copyright notice and this permission notice shall be included in
aberk 0:f05e09f8f5d9 12 * all copies or substantial portions of the Software.
aberk 0:f05e09f8f5d9 13 *
aberk 0:f05e09f8f5d9 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
aberk 0:f05e09f8f5d9 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
aberk 0:f05e09f8f5d9 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
aberk 0:f05e09f8f5d9 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
aberk 0:f05e09f8f5d9 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
aberk 0:f05e09f8f5d9 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
aberk 0:f05e09f8f5d9 20 * THE SOFTWARE.
aberk 0:f05e09f8f5d9 21 */
aberk 0:f05e09f8f5d9 22
aberk 0:f05e09f8f5d9 23 #include "Motor.h"
aberk 0:f05e09f8f5d9 24
aberk 0:f05e09f8f5d9 25 Motor::Motor(PinName pwm, PinName fwd, PinName rev):
aberk 0:f05e09f8f5d9 26 _pwm(pwm), _fwd(fwd), _rev(rev) {
aberk 0:f05e09f8f5d9 27
aberk 0:f05e09f8f5d9 28 // Set initial condition of PWM
aberk 0:f05e09f8f5d9 29 _pwm.period(0.001);
aberk 0:f05e09f8f5d9 30 _pwm = 0;
aberk 0:f05e09f8f5d9 31
aberk 0:f05e09f8f5d9 32 // Initial condition of output enables
aberk 0:f05e09f8f5d9 33 _fwd = 0;
aberk 0:f05e09f8f5d9 34 _rev = 0;
aberk 0:f05e09f8f5d9 35 }
aberk 0:f05e09f8f5d9 36
aberk 0:f05e09f8f5d9 37 void Motor::speed(float speed) {
aberk 0:f05e09f8f5d9 38 _fwd = (speed > 0.0);
aberk 0:f05e09f8f5d9 39 _rev = (speed < 0.0);
aberk 0:f05e09f8f5d9 40 _pwm = abs(speed);
aberk 0:f05e09f8f5d9 41 }
aberk 0:f05e09f8f5d9 42
aberk 0:f05e09f8f5d9 43 void Motor::period(float period){
aberk 0:f05e09f8f5d9 44
aberk 0:f05e09f8f5d9 45 _pwm.period(period);
aberk 0:f05e09f8f5d9 46
aberk 0:f05e09f8f5d9 47 }