MotorDriver.h
Go to the documentation of this file.
1 /*
2  MotorDriver.h
3  2014 Copyright (c) Seeed Technology Inc. All right reserved.
4 
5  Author:lawliet.zou@gmail.com
6  2014-02-11
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #ifndef __MOTORDRIVER_H__
23 #define __MOTORDRIVER_H__
24 
25 #include "mbed.h"
26 #include "SoftwarePWM.h"
27 
28 /**************Motor ID**********************/
29 #define MOTORA 0
30 #define MOTORB 1
31 
32 #define LOW 0
33 #define HIGH 1
34 
35 #define MOTOR_POSITION_LEFT 0
36 #define MOTOR_POSITION_RIGHT 1
37 #define MOTOR_CLOCKWISE 0
38 #define MOTOR_ANTICLOCKWISE 1
39 
40 #define USE_DC_MOTOR 0
41 
42 #define MOTOR_PERIOD 10000 //10ms
43 
45 {
46  uint8_t speed;
47  uint8_t direction;
48  uint8_t position;
49 };
50 
55 {
56 
57 public:
58 
67  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)
68  {
69  _int1 = 0;
70  _int2 = 0;
71  _int3 = 0;
72  _int4 = 0;
73  };
74 
77  void init();
78 
83  void configure(uint8_t position, uint8_t motorID);
84 
89  void setSpeed(uint8_t speed, uint8_t motorID);
90 
95  void setDirection(uint8_t direction, uint8_t motorID);
96 
101  void rotate(uint8_t direction, uint8_t motor_position);
102 
107  void rotateWithID(uint8_t direction, uint8_t motorID);
108 
111  void goForward();
112 
115  void goBackward();
116 
119  void goLeft();
120 
123  void goRight();
124 
127  void stop();
128 
132  void stop(uint8_t motorID);
133 
137 
141 
142 private:
143 
144  DigitalOut _int1;
145  DigitalOut _int2;
146  DigitalOut _int3;
147  DigitalOut _int4;
150 };
151 #endif
MotorStruct
Definition: MotorDriver.h:44
MotorDriver::init
void init()
Definition: MotorDriver.cpp:25
MotorDriver::_speedB
SoftwarePWM _speedB
Definition: MotorDriver.h:149
MotorDriver::configure
void configure(uint8_t position, uint8_t motorID)
Definition: MotorDriver.cpp:37
MotorDriver::MotorDriver
MotorDriver(PinName int1, PinName int2, PinName int3, PinName int4, PinName speedA, PinName speedB)
Definition: MotorDriver.h:67
MotorDriver::_int4
DigitalOut _int4
Definition: MotorDriver.h:147
MotorStruct::direction
uint8_t direction
Definition: MotorDriver.h:47
MotorStruct::position
uint8_t position
Definition: MotorDriver.h:48
MotorDriver::goRight
void goRight()
Definition: MotorDriver.cpp:97
MotorDriver::stop
void stop()
Definition: MotorDriver.cpp:103
MotorDriver::motorB
MotorStruct motorB
Definition: MotorDriver.h:140
MotorDriver::goLeft
void goLeft()
Definition: MotorDriver.cpp:92
MotorDriver::_int1
DigitalOut _int1
Definition: MotorDriver.h:144
MotorDriver::_speedA
SoftwarePWM _speedA
Definition: MotorDriver.h:148
MotorDriver::_int2
DigitalOut _int2
Definition: MotorDriver.h:145
MotorDriver::goBackward
void goBackward()
Definition: MotorDriver.cpp:87
MotorDriver::motorA
MotorStruct motorA
Definition: MotorDriver.h:136
MotorDriver::setSpeed
void setSpeed(uint8_t speed, uint8_t motorID)
Definition: MotorDriver.cpp:43
MotorDriver::rotate
void rotate(uint8_t direction, uint8_t motor_position)
Definition: MotorDriver.cpp:54
MotorStruct::speed
uint8_t speed
Definition: MotorDriver.h:46
MotorDriver
Definition: MotorDriver.h:54
MotorDriver::setDirection
void setDirection(uint8_t direction, uint8_t motorID)
Definition: MotorDriver.cpp:48
MotorDriver::_int3
DigitalOut _int3
Definition: MotorDriver.h:146
MotorDriver::goForward
void goForward()
Definition: MotorDriver.cpp:82
SoftwarePWM.h
MotorDriver::rotateWithID
void rotateWithID(uint8_t direction, uint8_t motorID)
Definition: MotorDriver.cpp:66
SoftwarePWM
Definition: SoftwarePWM.h:55


rosserial_mbed
Author(s): Gary Servin
autogenerated on Wed Mar 2 2022 00:58:08