-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmotorControl.h
67 lines (52 loc) · 1.47 KB
/
motorControl.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
/*
* motorControl class interface
*
* Given a speed (0-255) and direction of rotation (CW or CCW), output
* proper signals to an L293D H-Bridge IC for controlling a DC motor.
*
* tgtPwms
* The desired (target) PWM value for each pin
*
* curPwms
* What PWM value is actually being driven at the moment
*
* deltas
* Difference b/t current tgtPwm value and the prev one
*
* curSpin
* Are we currently trying to go forward or backward?
*
* NOTE
* Pin numbers should be given in ther order {FWD, REV}, where FWD
* indicates the pin that moves the wheel forward when driven HIGH,
* and likewise for REV.
*/
#ifndef MOTORCONTROL_H
#define MOTORCONTROL_H
/*
* Forward output corresponds to the pin that pushes that motor forward
* e.g. the motor on the starboard side has clockwise being forward
*/
enum spin_t {
FWD,
REV
};
class motorControl {
public:
motorControl(int fwdPin, int revPin);
motorControl(int fwdPin, int revPin, float scalar);
void loop();
void setVelocity(int speed, spin_t spin);
void halt();
private:
void initMotor(int fwdPin, int revPin, float scalar);
const uint32_t RAMP_TIME = 5; // ms to go from speed A to speed B
uint32_t accelTimer;
spin_t spin;
float scalar; // Usually 1.0
int fwdPin, revPin,
tgtPwmFwd, tgtPwmRev,
curPwmFwd, curPwmRev,
deltaFwd, deltaRev;
};
#endif