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:
4:5fb1296c0d60
Motordriver adapted for the Magnevation Board used previously with OOPICII

Who changed what in which revision?

UserRevisionLine numberNew contents of line
littlexc 0:edc152f119b7 1 /*motor driver libary modified from the following libary,
Degs 6:81b393c33b77 2 *
littlexc 0:edc152f119b7 3 * mbed simple H-bridge motor controller
littlexc 0:edc152f119b7 4 * Copyright (c) 2007-2010, sford
Degs 6:81b393c33b77 5 *
Degs 6:81b393c33b77 6 *by Derek Calland modified for a Magnevation PWM Driver Board based on LMD18200T H-Bridge Driver IC's
Degs 6:81b393c33b77 7 *
Degs 6:81b393c33b77 8 *from SFord's libary, and some comments program structure from Christopher Haslers
littlexc 0:edc152f119b7 9 *
littlexc 0:edc152f119b7 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
littlexc 0:edc152f119b7 11 * of this software and associated documentation files (the "Software"), to deal
littlexc 0:edc152f119b7 12 * in the Software without restriction, including without limitation the rights
littlexc 0:edc152f119b7 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
littlexc 0:edc152f119b7 14 * copies of the Software, and to permit persons to whom the Software is
littlexc 0:edc152f119b7 15 * furnished to do so, subject to the following conditions:
littlexc 0:edc152f119b7 16 *
littlexc 0:edc152f119b7 17 * The above copyright notice and this permission notice shall be included in
littlexc 0:edc152f119b7 18 * all copies or substantial portions of the Software.
littlexc 0:edc152f119b7 19 *
littlexc 0:edc152f119b7 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
littlexc 0:edc152f119b7 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
littlexc 0:edc152f119b7 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
littlexc 0:edc152f119b7 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
littlexc 0:edc152f119b7 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
littlexc 0:edc152f119b7 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
littlexc 0:edc152f119b7 26 * THE SOFTWARE.
littlexc 0:edc152f119b7 27 */
Degs 6:81b393c33b77 28
littlexc 0:edc152f119b7 29 #ifndef MBED_MOTOR_H
littlexc 0:edc152f119b7 30 #define MBED_MOTOR_H
Degs 6:81b393c33b77 31
littlexc 0:edc152f119b7 32 #include "mbed.h"
Degs 6:81b393c33b77 33
Degs 6:81b393c33b77 34 /** Interface to control a standard DC motor
littlexc 0:edc152f119b7 35 * with an H-bridge using a PwmOut and 2 DigitalOuts
Degs 6:81b393c33b77 36 * Specifically for the Magnevation Board - refer to comments
littlexc 0:edc152f119b7 37 */
littlexc 0:edc152f119b7 38
Degs 6:81b393c33b77 39 class Motor ///Class Declaration
Degs 6:81b393c33b77 40 {
Degs 6:81b393c33b77 41 public:
Degs 6:81b393c33b77 42
Degs 6:81b393c33b77 43 /** Create a motor control interface
Degs 6:81b393c33b77 44 *
Degs 6:81b393c33b77 45 * @param pwm, A PwmOut pin driving the H-bridge enable line to control the speed
Degs 6:81b393c33b77 46 * @param fwdrev, A DigitalOut pin note Forward and Reverse is relative to how you connect the motor(s)
Degs 6:81b393c33b77 47 * and Refer to Figure 4 pages 6 & 7 in Instrument LMD18200 data sheet.
Degs 6:81b393c33b77 48 * @param brake, A DigitalOut pin the Magnevation driver board is able to perform a brake i.e. 0 false brake ON, 1 true brake OFF.
Degs 6:81b393c33b77 49 */
Degs 6:81b393c33b77 50 Motor(PinName pwm, PinName fwdrev, PinName brake, bool direction, bool stop); /** Create Motor instance */
Degs 6:81b393c33b77 51
Degs 6:81b393c33b77 52 /** Set the speed of the motor
Degs 6:81b393c33b77 53 *
Degs 6:81b393c33b77 54 * @param speed The speed of the motor as a normalised value between 0.0 and 1.0.
Degs 6:81b393c33b77 55 * @param fwdrev Magnevation board sets direction on a pin so does not need -1.0 to 0.0.
Degs 6:81b393c33b77 56 * @param stop The Magnevation Board has a brake facility and incorporates the Current Limiting features of the LMD18200.
Degs 6:81b393c33b77 57 * @return the applied speed to the motor after checking to ensure motor doesn't switch from forward to reverse without stopping.
Degs 6:81b393c33b77 58 */
Degs 6:81b393c33b77 59 float speed(float speed, bool fwdrev, bool stop);
Degs 6:81b393c33b77 60
Degs 6:81b393c33b77 61 /** Set the the motor to coast
Degs 6:81b393c33b77 62 *
Degs 6:81b393c33b77 63 * In a practical world you would not neccessarily leave anything 'coasting' and acting as a dc generator
Degs 6:81b393c33b77 64 * always better to have a drive under control at all times so I haven't included this
Degs 6:81b393c33b77 65 * from the origanal class constructor for the Magnevation Board.
Degs 6:81b393c33b77 66 */
Degs 6:81b393c33b77 67
Degs 6:81b393c33b77 68 /** Set the motor to dynamicaly brake
Degs 6:81b393c33b77 69 *
Degs 6:81b393c33b77 70 * The Magnevation Board has a brake facility and incorporates the Current Limiting features
Degs 6:81b393c33b77 71 * of the LMD18200.
Degs 6:81b393c33b77 72 */
Degs 6:81b393c33b77 73
Degs 6:81b393c33b77 74 float stop(float speed, bool stop);
Degs 6:81b393c33b77 75 /** return the current state of the motor
Degs 6:81b393c33b77 76 */
Degs 6:81b393c33b77 77
Degs 6:81b393c33b77 78 protected:
Degs 6:81b393c33b77 79 PwmOut _pwm;
Degs 6:81b393c33b77 80 DigitalOut _fwdrev;
Degs 6:81b393c33b77 81 DigitalOut _brake;
Degs 6:81b393c33b77 82 bool _direction;
Degs 6:81b393c33b77 83 bool _stop;
Degs 6:81b393c33b77 84
littlexc 0:edc152f119b7 85 };
littlexc 0:edc152f119b7 86
littlexc 0:edc152f119b7 87 #endif