-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.h
146 lines (131 loc) · 4.23 KB
/
utilities.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Delays around HP-LED bursts
// Units: milliseconds
int baselineWindow = 3000; // 3 seconds
// Total HP-LED trigger pulse length (ON + OFF) in us
// 0.2 - 6 ms
// 200 - 6000 us
float HPpulseLength = 6000;
// Duty cycle of pulse in %
float HPdutyCycle = 50;
// Number of pulses per burst (850)
int HPcount = 850;
// may need 240 ms (calculated in excel)
unsigned long HPcooldown = HPpulseLength*5;
// Will store last time HP-LED pin was updated
unsigned long HPledPreviousHIGHMicros = 0;
unsigned long HPledPreviousLOWMicros = 0;
unsigned long HPledWaitPreviousMicros = 0;
long HPledIntervalHigh = HPpulseLength*(HPdutyCycle/100);
long HPledIntervalLow = HPpulseLength - HPledIntervalHigh;
unsigned long HPcurrentMicros = 0;
// Used to set the HP-LED
int HPledState = LOW;
// Total pulse length (ON + OFF) in us
// 1 - 100 Hz (FPS)
// 1000000 - 100000 us
// 60 FPS, 1000000*(1/60) us
// 60 FPS, 1000000*(1/60) us
float CAMexposure = 0.001;
float CAMpulseLength = 0.001 * 1000000;
// Duty cycle of pulse in %
float CAMdutyCycle = 99;
// non-imaging window after burst: X*seconds - (baseline+burst)
// 1*1000 = 1 second
int captureWindow = (1*1000)-(baselineWindow + HPcount*HPpulseLength*1000);
// Number of frames
// int CAMframes = (1000*captureWindow)/(int) CAMpulseLength;
int CAMframesBase = 30000;
int CAMframesRecov = 30000;
// Will store last time Camera pin was updated
unsigned long CAMPreviousHIGHMicros = 0;
unsigned long CAMPreviousLOWMicros = 0;
unsigned long CAMWaitPreviousMicros = 0;
long CAMIntervalHigh = CAMpulseLength*(CAMdutyCycle/100);
long CAMIntervalLow = CAMpulseLength - CAMIntervalHigh ;
unsigned long CAMcurrentMicros = 0;
// Used to set the Camera trigger
int CAMState = LOW;
unsigned long currentMicros = 0;
/* waitMicro(dur)
* Waits/delays for a given number of microseconds
*/
void waitMicro(int dur){
unsigned long currentMicros = micros();
unsigned long WaitPreviousMicros = currentMicros;
while(currentMicros - WaitPreviousMicros < dur){
currentMicros = micros();
}
}
/* baseline(window)
* Turn on baseline LED for a certain # of microseconds
*/
void baselineON(){
digitalWrite(PIN_BLLED, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
}
void baselineOFF(){
digitalWrite(PIN_BLLED, LOW);
digitalWrite(LED_BUILTIN, LOW);
}
/* burst(total, duty, count)
* Sends burst of pulses to HPLED
*/
void burst(int count){
int i = 0;
HPledState = HIGH;
HPcurrentMicros = micros();
HPledPreviousHIGHMicros = HPcurrentMicros;
digitalWrite(PIN_HPLED, HPledState); // Start with turning ON
while (i < count){
// Save the current time at the start of every loop
HPcurrentMicros = micros();
if(HPledState == LOW){ // Check to see if it's time to turn ON
if (HPcurrentMicros - HPledPreviousLOWMicros >= HPledIntervalLow) {
i++;
if(i >= count){break;}
// Save the last time LED turned OFF
HPledPreviousHIGHMicros = HPcurrentMicros;
HPledState = HIGH;
}
}
else{ // Check to see if it's time to turn OFF
if (HPcurrentMicros - HPledPreviousHIGHMicros >= HPledIntervalHigh) {
// Save the last time LED turned ON
HPledPreviousLOWMicros = HPcurrentMicros;
HPledState = LOW;
}
}
digitalWrite(PIN_HPLED, HPledState);
}
}
/* capture(frames)
* Sends burst of pulses to Camera trigger
*/
void capture(int frames){
int i = 0;
CAMState = HIGH;
CAMcurrentMicros = micros();
CAMPreviousHIGHMicros = CAMcurrentMicros;
digitalWrite(PIN_CAMTRIG, CAMState); // Start with turning ON
while (i < frames){
// Save the current time at the start of every loop
CAMcurrentMicros = micros();
if(CAMState == LOW){ // Check to see if it's time to turn ON
if (CAMcurrentMicros - CAMPreviousLOWMicros >= CAMIntervalLow) {
i++;
if(i >= frames){break;}
// Save the last time LED turned OFF
CAMPreviousHIGHMicros = CAMcurrentMicros;
CAMState = HIGH;
}
}
else{ // Check to see if it's time to turn OFF
if (CAMcurrentMicros - CAMPreviousHIGHMicros >= CAMIntervalHigh) {
// Save the last time LED turned ON
CAMPreviousLOWMicros = CAMcurrentMicros;
CAMState = LOW;
}
}
digitalWrite(PIN_CAMTRIG, CAMState);
}
}