Control a robot over the internet using UDP and a Wifly module (WiFi).

Dependencies:   Motor TextLCD WiflyInterface mbed-rtos mbed

Committer:
apatel336
Date:
Thu Oct 17 13:27:56 2013 +0000
Revision:
0:c0dc3a76f3d4
Initial Release

Who changed what in which revision?

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