Example for a Magnevation Board used previously on a OOPICII

Fork of Motordriver by Christopher Hasler

Committer:
Degs
Date:
Mon Feb 11 21:44:17 2013 +0000
Revision:
6:81b393c33b77
Parent:
5:3110b9209d3c
Motordriver adapted for the Magnevation Board used previously with OOPICII

Who changed what in which revision?

UserRevisionLine numberNew contents of line
littlexc 1:3da7302dc9ae 1 /*motor driver libary modified from the following libary,
littlexc 1:3da7302dc9ae 2 *
littlexc 1:3da7302dc9ae 3 * mbed simple H-bridge motor controller
Degs 6:81b393c33b77 4 * Copyright (c) 2007-2010, S Ford
littlexc 1:3da7302dc9ae 5 *
Degs 6:81b393c33b77 6 * by Derek Calland modified for a Magnevation PWM Driver Board based on LMD18200T H-Bridge Driver IC's
littlexc 1:3da7302dc9ae 7 *
Degs 6:81b393c33b77 8 * from Christopher Hasler originally from Simon Ford's libary,
littlexc 1:3da7302dc9ae 9 *
littlexc 1:3da7302dc9ae 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
littlexc 1:3da7302dc9ae 11 * of this software and associated documentation files (the "Software"), to deal
littlexc 1:3da7302dc9ae 12 * in the Software without restriction, including without limitation the rights
littlexc 1:3da7302dc9ae 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
littlexc 1:3da7302dc9ae 14 * copies of the Software, and to permit persons to whom the Software is
littlexc 1:3da7302dc9ae 15 * furnished to do so, subject to the following conditions:
littlexc 1:3da7302dc9ae 16 *
littlexc 1:3da7302dc9ae 17 * The above copyright notice and this permission notice shall be included in
littlexc 1:3da7302dc9ae 18 * all copies or substantial portions of the Software.
littlexc 1:3da7302dc9ae 19 *
littlexc 1:3da7302dc9ae 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
littlexc 1:3da7302dc9ae 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
littlexc 1:3da7302dc9ae 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
littlexc 1:3da7302dc9ae 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
littlexc 1:3da7302dc9ae 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
littlexc 1:3da7302dc9ae 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
littlexc 1:3da7302dc9ae 26 * THE SOFTWARE.
littlexc 1:3da7302dc9ae 27 */
littlexc 0:edc152f119b7 28
littlexc 0:edc152f119b7 29 #include "motordriver.h"
littlexc 1:3da7302dc9ae 30
littlexc 0:edc152f119b7 31 #include "mbed.h"
littlexc 1:3da7302dc9ae 32
Degs 6:81b393c33b77 33 Motor::Motor(PinName pwm, PinName fwdrev, PinName brake, bool direction, bool stop): ///Class Implementation
Degs 6:81b393c33b77 34 _pwm(pwm), _fwdrev(fwdrev), _brake(brake)
Degs 6:81b393c33b77 35 {
Degs 6:81b393c33b77 36 _direction = direction; //Set each motor to rotate in clockwise or counter clockwise
Degs 6:81b393c33b77 37 _stop = stop; //Stop all motion
littlexc 0:edc152f119b7 38
littlexc 0:edc152f119b7 39 // Set initial condition of PWM
littlexc 0:edc152f119b7 40 _pwm.period(0.001);
littlexc 0:edc152f119b7 41 _pwm = 0;
littlexc 0:edc152f119b7 42
littlexc 0:edc152f119b7 43 // Initial condition of output enables
Degs 6:81b393c33b77 44 _fwdrev = fwdrev; //sets output to drive Motor in a direction
Degs 6:81b393c33b77 45 /* check the motor to see what direction this is from Magnevation Board */
littlexc 1:3da7302dc9ae 46
Degs 6:81b393c33b77 47 //Initial condition of Brake
Degs 6:81b393c33b77 48 _brake = brake; //sets brake to ON/OFF condition to Magnevation Board
littlexc 0:edc152f119b7 49 }
littlexc 1:3da7302dc9ae 50
Degs 6:81b393c33b77 51 float Motor::speed(float speed, bool direction, bool stop)
Degs 6:81b393c33b77 52 {
Degs 6:81b393c33b77 53 _fwdrev = direction;
Degs 6:81b393c33b77 54 _brake = stop; //Sets brake to ON/OFF condition to Magnevation Board
Degs 6:81b393c33b77 55 _pwm = abs(speed);
Degs 6:81b393c33b77 56 return speed;
littlexc 0:edc152f119b7 57 }
littlexc 0:edc152f119b7 58
Degs 6:81b393c33b77 59 float Motor::stop(float speed, bool stop)
Degs 6:81b393c33b77 60 {
Degs 6:81b393c33b77 61 if (speed == 0.0) {
Degs 6:81b393c33b77 62 wait(0.02);
Degs 6:81b393c33b77 63 _brake = stop;
Degs 6:81b393c33b77 64 }
Degs 6:81b393c33b77 65 _pwm = abs(speed);
Degs 6:81b393c33b77 66 return speed;
littlexc 0:edc152f119b7 67 }
littlexc 1:3da7302dc9ae 68
littlexc 4:5fb1296c0d60 69