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 
MotorDriver::init
void init()
Definition: MotorDriver.cpp:25
MotorDriver::_speedB
SoftwarePWM _speedB
Definition: MotorDriver.h:149
SoftwarePWM::Disable
void Disable()
Definition: SoftwarePWM.cpp:35
MotorDriver::configure
void configure(uint8_t position, uint8_t motorID)
Definition: MotorDriver.cpp:37
MotorDriver::_int4
DigitalOut _int4
Definition: MotorDriver.h:147
MOTOR_PERIOD
#define MOTOR_PERIOD
Definition: MotorDriver.h:42
HIGH
#define HIGH
Definition: MotorDriver.h:33
MotorStruct::direction
uint8_t direction
Definition: MotorDriver.h:47
MotorStruct::position
uint8_t position
Definition: MotorDriver.h:48
MotorDriver.h
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
MOTOR_ANTICLOCKWISE
#define MOTOR_ANTICLOCKWISE
Definition: MotorDriver.h:38
MOTORA
#define MOTORA
Definition: MotorDriver.h:29
SoftwarePWM::Enable
void Enable(int StartPos, int Period)
Definition: SoftwarePWM.cpp:29
MotorDriver::_int1
DigitalOut _int1
Definition: MotorDriver.h:144
MotorDriver::_speedA
SoftwarePWM _speedA
Definition: MotorDriver.h:148
MOTOR_POSITION_LEFT
#define MOTOR_POSITION_LEFT
Definition: MotorDriver.h:35
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
MOTOR_CLOCKWISE
#define MOTOR_CLOCKWISE
Definition: MotorDriver.h:37
MotorDriver::setDirection
void setDirection(uint8_t direction, uint8_t motorID)
Definition: MotorDriver.cpp:48
LOW
#define LOW
Definition: MotorDriver.h:32
MOTORB
#define MOTORB
Definition: MotorDriver.h:30
MotorDriver::_int3
DigitalOut _int3
Definition: MotorDriver.h:146
MOTOR_POSITION_RIGHT
#define MOTOR_POSITION_RIGHT
Definition: MotorDriver.h:36
MotorDriver::goForward
void goForward()
Definition: MotorDriver.cpp:82
MotorDriver::rotateWithID
void rotateWithID(uint8_t direction, uint8_t motorID)
Definition: MotorDriver.cpp:66


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