MotorDriver.h
Go to the documentation of this file.
00001 /*
00002   MotorDriver.h
00003   2014 Copyright (c) Seeed Technology Inc.  All right reserved.
00004 
00005   Author:lawliet.zou@gmail.com
00006   2014-02-11
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 */
00022 #ifndef __MOTORDRIVER_H__
00023 #define __MOTORDRIVER_H__
00024 
00025 #include "mbed.h"
00026 #include "SoftwarePWM.h"
00027 
00028 /**************Motor ID**********************/
00029 #define MOTORA                  0
00030 #define MOTORB                  1
00031 
00032 #define LOW                     0
00033 #define HIGH                    1
00034 
00035 #define MOTOR_POSITION_LEFT     0
00036 #define MOTOR_POSITION_RIGHT    1
00037 #define MOTOR_CLOCKWISE         0
00038 #define MOTOR_ANTICLOCKWISE     1
00039 
00040 #define USE_DC_MOTOR            0
00041 
00042 #define MOTOR_PERIOD            10000 //10ms
00043 
00044 struct MotorStruct
00045 {
00046   uint8_t speed;
00047   uint8_t direction;
00048   uint8_t position;
00049 };
00050 
00054 class MotorDriver
00055 {
00056 
00057 public:
00058 
00067   MotorDriver(PinName int1, PinName int2, PinName int3, PinName int4, PinName speedA, PinName speedB): _int1(int1), _int2(int2), _int3(int3), _int4(int4), _speedA(speedA), _speedB(speedB)
00068   {
00069     _int1 = 0;
00070     _int2 = 0;
00071     _int3 = 0;
00072     _int4 = 0;
00073   };
00074 
00077   void init();
00078 
00083   void configure(uint8_t position, uint8_t motorID);
00084 
00089   void setSpeed(uint8_t speed, uint8_t motorID);
00090 
00095   void setDirection(uint8_t direction, uint8_t motorID);
00096 
00101   void rotate(uint8_t direction, uint8_t motor_position);
00102 
00107   void rotateWithID(uint8_t direction, uint8_t motorID);
00108 
00111   void goForward();
00112 
00115   void goBackward();
00116 
00119   void goLeft();
00120 
00123   void goRight();
00124 
00127   void stop();
00128 
00132   void stop(uint8_t motorID);
00133 
00136   MotorStruct motorA;
00137 
00140   MotorStruct motorB;
00141 
00142 private:
00143 
00144   DigitalOut  _int1;
00145   DigitalOut  _int2;
00146   DigitalOut  _int3;
00147   DigitalOut  _int4;
00148   SoftwarePWM _speedA;
00149   SoftwarePWM _speedB;
00150 };
00151 #endif


rosserial_mbed
Author(s): Gary Servin
autogenerated on Sat Oct 7 2017 03:08:46