-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdriveControl.h
72 lines (57 loc) · 1.86 KB
/
driveControl.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
/*
* driveControl class interface
*
* This class instantiates two motorControl objects to be able to
* coordinate the movement of a two-wheel-drive robot. It declares some
* shorthand functions to make movement control simpler for the user.
*
* motor{Left|Right}
* motorControl object for the each motor
*
* speed{Left|Right}
* Current speed of each motor (PWM voltage 0-255)
*
* dir{Left|Right}
* The current direction of motion for each motor, either FWD or REV
*
* duration
* Number of milliseconds to perform the given move for
*
* timer
* Tracks milliseconds since start of the current move
*
* isIdle
* Whether the previous move has completed. Always set true when
* starting a move, set to false when the move's duration elapses or
* halt() is called with no arguments.
*/
#ifndef DRIVECONTROL_H
#define DRIVECONTROL_H
#include <Arduino.h>
#include "motorControl.h"
class driveControl {
public:
driveControl(int mtrLeftFwdPin, int mtrLeftRevPin, float scaleLeft,
int mtrRightFwdPin, int mtrRightRevPin, float scaleRight);
void loop();
bool getIsIdle();
void forward(uint32_t duration, int speed);
void reverse(uint32_t duration, int speed);
void turnLeft(uint32_t duration, int speed);
void turnRight(uint32_t duration, int speed);
void halt();
void halt(uint32_t duration);
private:
void move(uint32_t duration, int speedLeft, int speedRight,
spin_t dirLeft, spin_t dirRight);
motorControl motorLeft;
motorControl motorRight;
int speedLeft;
int speedRight;
spin_t dirLeft;
spin_t dirRight;
uint32_t duration;
uint32_t timer;
bool isIdle;
};
#endif