Committer:
littlexc
Date:
Fri Nov 19 12:15:33 2010 +0000
Revision:
0:774d7a3e63ae
Child:
1:3ece560dd2da
revisions to return types

Who changed what in which revision?

UserRevisionLine numberNew contents of line
littlexc 0:774d7a3e63ae 1 /*motor driver libary modified from the following libary,
littlexc 0:774d7a3e63ae 2 *
littlexc 0:774d7a3e63ae 3 * mbed simple H-bridge motor controller
littlexc 0:774d7a3e63ae 4 * Copyright (c) 2007-2010, sford
littlexc 0:774d7a3e63ae 5 *
littlexc 0:774d7a3e63ae 6 * by Christopher Hasler.
littlexc 0:774d7a3e63ae 7 *
littlexc 0:774d7a3e63ae 8 * from sford's libary,
littlexc 0:774d7a3e63ae 9 *
littlexc 0:774d7a3e63ae 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
littlexc 0:774d7a3e63ae 11 * of this software and associated documentation files (the "Software"), to deal
littlexc 0:774d7a3e63ae 12 * in the Software without restriction, including without limitation the rights
littlexc 0:774d7a3e63ae 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
littlexc 0:774d7a3e63ae 14 * copies of the Software, and to permit persons to whom the Software is
littlexc 0:774d7a3e63ae 15 * furnished to do so, subject to the following conditions:
littlexc 0:774d7a3e63ae 16 *
littlexc 0:774d7a3e63ae 17 * The above copyright notice and this permission notice shall be included in
littlexc 0:774d7a3e63ae 18 * all copies or substantial portions of the Software.
littlexc 0:774d7a3e63ae 19 *
littlexc 0:774d7a3e63ae 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
littlexc 0:774d7a3e63ae 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
littlexc 0:774d7a3e63ae 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
littlexc 0:774d7a3e63ae 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
littlexc 0:774d7a3e63ae 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
littlexc 0:774d7a3e63ae 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
littlexc 0:774d7a3e63ae 26 * THE SOFTWARE.
littlexc 0:774d7a3e63ae 27 */
littlexc 0:774d7a3e63ae 28
littlexc 0:774d7a3e63ae 29 #ifndef MBED_MOTORCS_H
littlexc 0:774d7a3e63ae 30 #define MBED_MOTORCS_H
littlexc 0:774d7a3e63ae 31
littlexc 0:774d7a3e63ae 32 #include "mbed.h"
littlexc 0:774d7a3e63ae 33
littlexc 0:774d7a3e63ae 34 /** Interface to control a standard DC motor
littlexc 0:774d7a3e63ae 35 * with an H-bridge using a PwmOut and 2 DigitalOuts plus analog input from current sense.
littlexc 0:774d7a3e63ae 36 */
littlexc 0:774d7a3e63ae 37 class Motor {
littlexc 0:774d7a3e63ae 38 public:
littlexc 0:774d7a3e63ae 39
littlexc 0:774d7a3e63ae 40 /** Create a motor control interface
littlexc 0:774d7a3e63ae 41 *
littlexc 0:774d7a3e63ae 42 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
littlexc 0:774d7a3e63ae 43 * @param fwd A DigitalOut, set high when the motor should go forward
littlexc 0:774d7a3e63ae 44 * @param rev A DigitalOut, set high when the motor should go backwards
littlexc 0:774d7a3e63ae 45 * @param brakeable, set if the motor driver is able to do braking 0 false 1 true. (addition)
littlexc 0:774d7a3e63ae 46 * @param ain, analog in conected to current sense pin.
littlexc 0:774d7a3e63ae 47 * @param ohms, value of resistor on current sense pin.
littlexc 0:774d7a3e63ae 48 * @param limit, maximum current possible, in amps. ie, 1 = 1A, 0.1 = 100mA
littlexc 0:774d7a3e63ae 49 8 @param cutby. the amount the system cuts the speed by in the event of a current spike above limit.
littlexc 0:774d7a3e63ae 50 */
littlexc 0:774d7a3e63ae 51 Motor(PinName pwm, PinName fwd, PinName rev, PinName ain, float ohms, float limit, float cutby, int brakeable);
littlexc 0:774d7a3e63ae 52
littlexc 0:774d7a3e63ae 53 /** Set the speed of the motor (addition)
littlexc 0:774d7a3e63ae 54 *
littlexc 0:774d7a3e63ae 55 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
littlexc 0:774d7a3e63ae 56 * @return speed applied after limiting due to current.
littlexc 0:774d7a3e63ae 57 */
littlexc 0:774d7a3e63ae 58 float speedcs(float speed);
littlexc 0:774d7a3e63ae 59
littlexc 0:774d7a3e63ae 60 /** Set the the motor to coast
littlexc 0:774d7a3e63ae 61 *
littlexc 0:774d7a3e63ae 62 * @param void motor coasts until another instruction is recived
littlexc 0:774d7a3e63ae 63 */
littlexc 0:774d7a3e63ae 64
littlexc 0:774d7a3e63ae 65 void coastcs(void);
littlexc 0:774d7a3e63ae 66
littlexc 0:774d7a3e63ae 67 /** Set the motor to dynamicaly brake (addition)
littlexc 0:774d7a3e63ae 68 *
littlexc 0:774d7a3e63ae 69 * @param float duty 0 - 1.0 provides some control over how hard the motor brakes.
littlexc 0:774d7a3e63ae 70 * @return returns duty applied due to current limiting.
littlexc 0:774d7a3e63ae 71 */
littlexc 0:774d7a3e63ae 72
littlexc 0:774d7a3e63ae 73 float stopcs(float duty);
littlexc 0:774d7a3e63ae 74
littlexc 0:774d7a3e63ae 75 /** read the current
littlexc 0:774d7a3e63ae 76 *
littlexc 0:774d7a3e63ae 77 * @param void returns (analog in * 0.303)/ohms.
littlexc 0:774d7a3e63ae 78 */
littlexc 0:774d7a3e63ae 79 float current(void);
littlexc 0:774d7a3e63ae 80
littlexc 0:774d7a3e63ae 81 protected:
littlexc 0:774d7a3e63ae 82 //pins
littlexc 0:774d7a3e63ae 83 PwmOut _pwm;
littlexc 0:774d7a3e63ae 84 DigitalOut _fwd;
littlexc 0:774d7a3e63ae 85 DigitalOut _rev;
littlexc 0:774d7a3e63ae 86 AnalogIn _ain;
littlexc 0:774d7a3e63ae 87 //variables
littlexc 0:774d7a3e63ae 88 int Brakeable; // (addition)
littlexc 0:774d7a3e63ae 89 int sign; //prevents throwing the motor from full foward to full reverse and stuff melting.
littlexc 0:774d7a3e63ae 90 float ohms;
littlexc 0:774d7a3e63ae 91 float currentlimit;
littlexc 0:774d7a3e63ae 92 float modifyspeed;
littlexc 0:774d7a3e63ae 93 //functions
littlexc 0:774d7a3e63ae 94 };
littlexc 0:774d7a3e63ae 95
littlexc 0:774d7a3e63ae 96 #endif