pid for dror

Dependencies:   mbed mypidror1 Map

Committer:
noamnahum
Date:
Fri Dec 27 17:29:23 2019 +0000
Revision:
0:1825e249cba5
changes;

Who changed what in which revision?

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