-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCMotor.h
99 lines (80 loc) · 3.25 KB
/
DCMotor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef DCMotor__h
#define DCMotor__h
/* DCMotor
A small DC motor control class.
IMPORTANT NOTICE: This library is based on code from the SNAPI library, which is under The RobotGroup-Multiplo
Pacifist License (RMPL). This license is (or may be) not compatible with the GNU Lesser General Public
License (LGPL), so this notice constitutes an special written exception from Multiplo, to allow deployment
under the LGPL, in order to be compiled with the Arduino libraries and still hold compatibility between
both licenses.
But this does not affects the SNAPI original license in any way, and DOES NOT AUTHORIZES ANY THIRD PARTY
TO USE OR REDISTRIBUTE THE SNAPI LIBRARY UNDER THE LGPL. In other words: This exception ONLY AFFECTS the
library when compiled with Arduino libraries, if and only if, this license (the RMPL) results in some
inconpatibility with the LGPL (so in this last case, then LGPL applies):
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
Any way, we strongly believe in peace, so we would not like to see our work in any non-civil or military
project. But, due to the possible incompatibilty with the LGPL licenses, this may be only a recommendation
and an expression of our wishes. But, if some clever guy can determine that LGPL and RMPL are compatible
licenses, then RMPL applies here. You can contact us at: info_t1@multiplo.com.ar
*/
#include "Arduino.h"
const float dcMotMaxSpeed = 255.0;
const float dcMotMinSpeed = -dcMotMaxSpeed;
class DCMotor
{
private:
bool clockwise, braked;
float speed, prevSpeed, zeroZone;
int enable_pin, d0_pin, d1_pin;
public:
inline DCMotor(const int enable_pin,
const int d0_pin, const int d1_pin,
const bool clockwise = true) : clockwise(clockwise),
braked(false),
speed(0.0), prevSpeed(0.0), zeroZone(0.1),
enable_pin(enable_pin),
d0_pin(d0_pin), d1_pin(d1_pin)
{
pinMode(enable_pin, OUTPUT);
pinMode(d0_pin, OUTPUT);
pinMode(d1_pin, OUTPUT);
digitalWrite(enable_pin, LOW);
digitalWrite(d0_pin, LOW);
digitalWrite(d1_pin, LOW);
}
void setSpeed(const float value);
void brake();
void setClockwise(const bool value);
inline float getZeroZone() const
{
return zeroZone;
}
inline void setZeroZone(const float value)
{
zeroZone = value;
}
inline bool getClockwise() const
{
return clockwise;
}
inline float getSpeed() const
{
return speed;
}
inline float getPrevSpeed() const
{
return prevSpeed;
}
inline bool isBraked() const
{
return braked;
}
};
#endif