-
Notifications
You must be signed in to change notification settings - Fork 0
/
MotorClass.cpp
49 lines (40 loc) · 915 Bytes
/
MotorClass.cpp
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
#include "MotorClass.h"
#include <Servo.h>
Motor::Motor(int pin, int offset)
{
_pin = pin;
_fixedOffset = offset;
_variance = offset;
}
void Motor::begin()
{
_ESC.attach(_pin);
_ESC.writeMicroseconds(0);
}
void Motor::initialize()
{
_ESC.writeMicroseconds(LOW_THROTTLE);
_throttle = LOW_THROTTLE;
_status = LOW_THROTTLE;
}
void Motor::control(int variance)
{
if (variance+_fixedOffset <= _variance+RESOLUTION || variance+_fixedOffset >= _variance+RESOLUTION)
{
_ESC.writeMicroseconds(_throttle+variance+_fixedOffset);
_variance = variance+_fixedOffset;
_status = _throttle+_variance;
}
}
void Motor::speedAdjust(int setting)
{
if (setting+_variance >= _status+RESOLUTION || setting+_variance <= _status-RESOLUTION) {
_ESC.writeMicroseconds(setting+_variance);
_throttle = setting;
_status = setting+_variance;
}
}
int Motor::status()
{
return _status;
}