MotorDriver.cpp
Go to the documentation of this file.
1 /*
2  MotorDriver.cpp
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 
23 #include "MotorDriver.h"
24 
26 {
27  stop();
28  /*Configure the motor A to control the wheel at the left side.*/
30  /*Configure the motor B to control the wheel at the right side.*/
32  setSpeed(0, MOTORA);
33  setSpeed(0, MOTORB);
36 }
37 void MotorDriver::configure(uint8_t position, uint8_t motorID)
38 {
39  if (motorID == MOTORA)motorA.position = position;
40  else motorB.position = position;
41 }
42 
43 void MotorDriver::setSpeed(uint8_t speed, uint8_t motorID)
44 {
45  if (motorID == MOTORA) motorA.speed = speed;
46  else if (motorID == MOTORB) motorB.speed = speed;
47 }
48 void MotorDriver::setDirection(uint8_t direction, uint8_t motorID)
49 {
50  if (motorID == MOTORA)motorA.direction = direction;
51  else if (motorID == MOTORB)motorB.direction = direction;
52 }
53 
54 void MotorDriver::rotate(uint8_t direction, uint8_t motor_position)
55 {
56  if (motor_position == motorA.position)
57  {
58  rotateWithID(direction, MOTORA);
59  }
60  if (motor_position == motorB.position)
61  {
62  rotateWithID(direction, MOTORB);
63  }
64 }
65 
66 void MotorDriver::rotateWithID(uint8_t direction, uint8_t motorID)
67 {
68  if (motorID == MOTORA)
69  {
71  _int1 = (MOTOR_CLOCKWISE == direction) ? LOW : HIGH;
72  _int2 = !_int1;
73  }
74  else if (motorID == MOTORB)
75  {
77  _int3 = (MOTOR_CLOCKWISE == direction) ? LOW : HIGH;
78  _int4 = !_int3;
79  }
80 }
81 
83 {
86 }
88 {
91 }
93 {
96 }
98 {
101 }
102 
104 {
105  _speedA.Disable();
106  _speedB.Disable();
107 }
108 
109 void MotorDriver::stop(uint8_t motorID)
110 {
111  if (motorID == MOTORA)_speedA.Disable();
112  else if (motorID == MOTORB)_speedB.Disable();
113 }
114 
#define MOTOR_ANTICLOCKWISE
Definition: MotorDriver.h:38
void rotateWithID(uint8_t direction, uint8_t motorID)
Definition: MotorDriver.cpp:66
void Disable()
Definition: SoftwarePWM.cpp:35
void goRight()
Definition: MotorDriver.cpp:97
uint8_t direction
Definition: MotorDriver.h:47
MotorStruct motorB
Definition: MotorDriver.h:140
DigitalOut _int1
Definition: MotorDriver.h:144
#define MOTOR_POSITION_RIGHT
Definition: MotorDriver.h:36
#define MOTOR_CLOCKWISE
Definition: MotorDriver.h:37
#define MOTORB
Definition: MotorDriver.h:30
void goBackward()
Definition: MotorDriver.cpp:87
void configure(uint8_t position, uint8_t motorID)
Definition: MotorDriver.cpp:37
DigitalOut _int2
Definition: MotorDriver.h:145
void Enable(int StartPos, int Period)
Definition: SoftwarePWM.cpp:29
void setSpeed(uint8_t speed, uint8_t motorID)
Definition: MotorDriver.cpp:43
uint8_t position
Definition: MotorDriver.h:48
#define MOTORA
Definition: MotorDriver.h:29
#define MOTOR_POSITION_LEFT
Definition: MotorDriver.h:35
#define LOW
Definition: MotorDriver.h:32
void setDirection(uint8_t direction, uint8_t motorID)
Definition: MotorDriver.cpp:48
DigitalOut _int3
Definition: MotorDriver.h:146
#define MOTOR_PERIOD
Definition: MotorDriver.h:42
#define HIGH
Definition: MotorDriver.h:33
void goLeft()
Definition: MotorDriver.cpp:92
void goForward()
Definition: MotorDriver.cpp:82
SoftwarePWM _speedA
Definition: MotorDriver.h:148
uint8_t speed
Definition: MotorDriver.h:46
SoftwarePWM _speedB
Definition: MotorDriver.h:149
MotorStruct motorA
Definition: MotorDriver.h:136
void rotate(uint8_t direction, uint8_t motor_position)
Definition: MotorDriver.cpp:54
DigitalOut _int4
Definition: MotorDriver.h:147


rosserial_mbed
Author(s): Gary Servin
autogenerated on Mon Jun 10 2019 14:53:26