-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestMotor.h
126 lines (104 loc) · 2.76 KB
/
testMotor.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
*
*/
#ifndef TESTMOTOR_H
#define TESTMOTOR_H
#include <Arduino.h>
#include "motorControl.h"
extern uint32_t MILLIS;
const int mtrLeftFwdPin = 4;
const int mtrLeftRevPin = 5;
const int mtrRightFwdPin = 2;
const int mtrRightRevPin = 3;
motorControl leftMotor(mtrLeftFwdPin, mtrLeftRevPin);
motorControl rightMotor(mtrRightFwdPin, mtrRightRevPin);
/*
*
*/
bool wait(uint32_t delay_ms) {
static uint32_t timer = MILLIS;
if (MILLIS - timer >= delay_ms) {
timer = MILLIS;
return true;
}
else {return false;}
}
/*
*
*/
void testMotor() {
static int testNum = 0;
leftMotor.loop();
rightMotor.loop();
switch (testNum) {
/* Straight FWD */
case 0:
leftMotor.setVelocity(70, FWD);
rightMotor.setVelocity(70, FWD);
if (wait(1000)) {
Serial.println("Switching to 1");
leftMotor.setVelocity(0, FWD);
rightMotor.setVelocity(0, FWD);
++testNum;
}
break;
/* Straight back */
case 1:
if (wait(500)) {
Serial.println("Switching to 2");
leftMotor.setVelocity(70, REV);
rightMotor.setVelocity(70, REV);
++testNum;
}
break;
case 2:
if (wait(1000)) {
Serial.println("Switching to 3");
leftMotor.setVelocity(0, REV);
rightMotor.setVelocity(0, REV);
++testNum;
}
break;
/* Turn left */
case 3:
if (wait(500)) {
Serial.println("Switching to 4");
leftMotor.setVelocity(70, FWD);
rightMotor.setVelocity(70, REV);
++testNum;
}
break;
case 4:
if (wait(1000)) {
Serial.println("Switching to 5");
leftMotor.setVelocity(0, FWD);
rightMotor.setVelocity(0, REV);
++testNum;
}
break;
/* Turn right */
case 5:
if (wait(500)) {
Serial.println("Switching to 6");
leftMotor.setVelocity(70, REV);
rightMotor.setVelocity(70, FWD);
++testNum;
}
break;
case 6:
if (wait(1000)) {
Serial.println("Switching to 7");
leftMotor.setVelocity(0, FWD);
rightMotor.setVelocity(0, REV);
++testNum;
}
break;
case 7:
if (wait(500)) {
Serial.println("Switching to 0");
testNum = 0;
}
break;
} // switch
}
#endif