Example for a Magnevation Board used previously on a OOPICII

Fork of Motordriver by Christopher Hasler

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motordriver.h Source File

motordriver.h

00001 /*motor driver libary modified from the following libary,
00002 *
00003 * mbed simple H-bridge motor controller
00004 * Copyright (c) 2007-2010, sford
00005 *
00006 *by Derek Calland modified for a Magnevation PWM Driver Board based on LMD18200T H-Bridge Driver IC's
00007 *
00008 *from SFord's libary, and some comments program structure from Christopher Haslers
00009 *
00010 * Permission is hereby granted, free of charge, to any person obtaining a copy
00011 * of this software and associated documentation files (the "Software"), to deal
00012 * in the Software without restriction, including without limitation the rights
00013 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00014 * copies of the Software, and to permit persons to whom the Software is
00015 * furnished to do so, subject to the following conditions:
00016 *
00017 * The above copyright notice and this permission notice shall be included in
00018 * all copies or substantial portions of the Software.
00019 *
00020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00023 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00024 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00025 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00026 * THE SOFTWARE.
00027 */
00028 
00029 #ifndef MBED_MOTOR_H
00030 #define MBED_MOTOR_H
00031 
00032 #include "mbed.h"
00033 
00034 /** Interface to control a standard DC motor
00035 * with an H-bridge using a PwmOut and 2 DigitalOuts
00036 * Specifically for the Magnevation Board - refer to comments
00037 */
00038 
00039 class Motor   ///Class Declaration
00040 {
00041 public:
00042 
00043     /** Create a motor control interface
00044     *
00045     * @param pwm, A PwmOut pin driving the H-bridge enable line to control the speed
00046     * @param fwdrev, A DigitalOut pin note Forward and Reverse is relative to how you connect the motor(s)
00047     * and Refer to Figure 4 pages 6 & 7 in Instrument LMD18200 data sheet.
00048     * @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.
00049     */
00050     Motor(PinName pwm, PinName fwdrev, PinName brake, bool direction, bool stop); /** Create Motor instance */
00051     
00052     /** Set the speed of the motor
00053     *
00054     * @param speed The speed of the motor as a normalised value between 0.0 and 1.0.
00055     * @param fwdrev Magnevation board sets direction on a pin so does not need -1.0 to 0.0.
00056     * @param stop The Magnevation Board has a brake facility and incorporates the Current Limiting features of the LMD18200.
00057     * @return the applied speed to the motor after checking to ensure motor doesn't switch from forward to reverse without stopping.
00058     */
00059     float speed(float speed, bool fwdrev, bool stop);
00060 
00061     /** Set the the motor to coast
00062     *
00063     * In a practical world you would not neccessarily leave anything 'coasting' and acting as a dc generator
00064     * always better to have a drive under control at all times so I haven't included this
00065     * from the origanal class constructor for the Magnevation Board.
00066     */
00067 
00068     /** Set the motor to dynamicaly brake
00069     *
00070     * The Magnevation Board has a brake facility and incorporates the Current Limiting features
00071     * of the LMD18200.
00072     */
00073 
00074     float stop(float speed, bool stop);
00075     /** return the current state of the motor
00076     */
00077 
00078 protected:
00079     PwmOut _pwm;
00080     DigitalOut _fwdrev;
00081     DigitalOut _brake;
00082     bool _direction;
00083     bool _stop;
00084 
00085 };
00086 
00087 #endif