CarlsenBot working

Dependencies:   Servo mbed

Committer:
pyeh9
Date:
Wed May 01 16:00:53 2013 +0000
Revision:
0:cdd566529530
CarlsenBot Working commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pyeh9 0:cdd566529530 1 /* mbed simple H-bridge motor controller
pyeh9 0:cdd566529530 2 * Copyright (c) 2007-2010, sford, http://mbed.org
pyeh9 0:cdd566529530 3 *
pyeh9 0:cdd566529530 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
pyeh9 0:cdd566529530 5 * of this software and associated documentation files (the "Software"), to deal
pyeh9 0:cdd566529530 6 * in the Software without restriction, including without limitation the rights
pyeh9 0:cdd566529530 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pyeh9 0:cdd566529530 8 * copies of the Software, and to permit persons to whom the Software is
pyeh9 0:cdd566529530 9 * furnished to do so, subject to the following conditions:
pyeh9 0:cdd566529530 10 *
pyeh9 0:cdd566529530 11 * The above copyright notice and this permission notice shall be included in
pyeh9 0:cdd566529530 12 * all copies or substantial portions of the Software.
pyeh9 0:cdd566529530 13 *
pyeh9 0:cdd566529530 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pyeh9 0:cdd566529530 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pyeh9 0:cdd566529530 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pyeh9 0:cdd566529530 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pyeh9 0:cdd566529530 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pyeh9 0:cdd566529530 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pyeh9 0:cdd566529530 20 * THE SOFTWARE.
pyeh9 0:cdd566529530 21 */
pyeh9 0:cdd566529530 22
pyeh9 0:cdd566529530 23 #ifndef MBED_MOTOR_H
pyeh9 0:cdd566529530 24 #define MBED_MOTOR_H
pyeh9 0:cdd566529530 25
pyeh9 0:cdd566529530 26 #include "mbed.h"
pyeh9 0:cdd566529530 27
pyeh9 0:cdd566529530 28 /** Interface to control a standard DC motor
pyeh9 0:cdd566529530 29 *
pyeh9 0:cdd566529530 30 * with an H-bridge using a PwmOut and 2 DigitalOuts
pyeh9 0:cdd566529530 31 */
pyeh9 0:cdd566529530 32 class Motor {
pyeh9 0:cdd566529530 33 public:
pyeh9 0:cdd566529530 34
pyeh9 0:cdd566529530 35 /** Create a motor control interface
pyeh9 0:cdd566529530 36 *
pyeh9 0:cdd566529530 37 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
pyeh9 0:cdd566529530 38 * @param fwd A DigitalOut, set high when the motor should go forward
pyeh9 0:cdd566529530 39 * @param rev A DigitalOut, set high when the motor should go backwards
pyeh9 0:cdd566529530 40 */
pyeh9 0:cdd566529530 41 Motor(PinName pwm, PinName fwd, PinName rev);
pyeh9 0:cdd566529530 42 Motor(PinName pwm, PinName fwd, PinName rev, I2C *i);
pyeh9 0:cdd566529530 43 /** Set the speed of the motor
pyeh9 0:cdd566529530 44 *
pyeh9 0:cdd566529530 45 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0
pyeh9 0:cdd566529530 46 */
pyeh9 0:cdd566529530 47 void speed(float speed);
pyeh9 0:cdd566529530 48
pyeh9 0:cdd566529530 49 // my changes
pyeh9 0:cdd566529530 50 I2C *_i2c;
pyeh9 0:cdd566529530 51 int ticks;
pyeh9 0:cdd566529530 52 char deviceAddress;
pyeh9 0:cdd566529530 53 int motorID; // for debugging
pyeh9 0:cdd566529530 54 bool is_reversed; // set this bit for a reversed motor, i.e. motor x2
pyeh9 0:cdd566529530 55
pyeh9 0:cdd566529530 56 void move(int pos); // move to tick = pos
pyeh9 0:cdd566529530 57 void getTicks();
pyeh9 0:cdd566529530 58 void resetTicks();
pyeh9 0:cdd566529530 59 void init(char, int, bool);
pyeh9 0:cdd566529530 60
pyeh9 0:cdd566529530 61 private:
pyeh9 0:cdd566529530 62
pyeh9 0:cdd566529530 63
pyeh9 0:cdd566529530 64 protected:
pyeh9 0:cdd566529530 65
pyeh9 0:cdd566529530 66 PwmOut _pwm;
pyeh9 0:cdd566529530 67 DigitalOut _fwd;
pyeh9 0:cdd566529530 68 DigitalOut _rev;
pyeh9 0:cdd566529530 69
pyeh9 0:cdd566529530 70 };
pyeh9 0:cdd566529530 71
pyeh9 0:cdd566529530 72 #endif