-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker.ino
164 lines (118 loc) · 4.26 KB
/
tracker.ino
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <Time.h>
#include <math.h>
char fileName[] = __FILE__;
// in the hardware subfolder of the Arduino IDE installation folder, create platform.txt:
// compiler.cpp.extra_flags=-D__PATH__="{build.source.path}"
char pathName[] = __PATH__;
char temp[2000];
boolean trackerRun = false;
boolean constantAngular = true;
//time_t frameTime = 1;
//time_t frameInc = 1;
/********************************************************************************/
#include "stepper.h"
const double pi = 3.14159265;
//float totalMinutes = 1; // for timed frames
int totalFrames = 125;
int stepsPerFrame = 1;
int rotsPerFrame = 1;
float targetHeight = 10.0;
const double targetOrigin = 24.0;
double targetBase;
double targetAngle;
int trackerMax = horizMaximum;
int trackerMin = horizMinimum;
bool trackerSpan = false;
#include "wifi.h"
#include "http.h"
#include "httpWifi.h"
//-----------------------------------------
void setup()
{
Serial.begin(9600);
wifiSetup();
httpSetup();
httpWifiSetup();
stepperSetup();
// shutter pin
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
}
//----------------------------------------------
void loop()
{
server.handleClient();
//ArduinoOTA.handle();
wifiOTA();
wifiDNS();
// don't do anything unless horizStep and rotateStep have been set
if (horizStep <= 0 || rotateStep < 0 ) {
return; // loop will restart
}
// make sure move fits within margins
if ( horizMove < horizMinimum ) horizMove = horizMinimum;
if ( horizMove > horizMaximum ) horizMove = horizMaximum;
if (horizMove != horizStep) { // horiz move
if ( horizMove > horizStep ) {
stepperMove(stepperHoriz, 1, DOUBLE);
horizStep++;
} else {
stepperMove(stepperHoriz, -1, DOUBLE);
horizStep--;
}
} else if ( rotateMove != rotateStep ) { // rotate move, don't try to overlap with horiz
// take the shorter way around
if (abs(rotateMove - rotateStep) > rotateMaximum/2) {
if ( rotateMove > rotateStep ) {
rotateStep += rotateMaximum;
} else {
rotateMove += rotateMaximum;
}
}
if ( rotateMove > rotateStep ) { // -1/1 for flat gear, 1/-1 for worm gear
stepperMove(stepperRotate, -1);
rotateStep++;
}
if ( rotateMove < rotateStep ) {
stepperMove(stepperRotate, 1);
rotateStep--;
}
}
if ( horizMove == horizStep && rotateMove == rotateStep ) { // got where it was going....
if (trackerRun) { // automatic increment mode
// timed mode
//if ( millis() < frameTime ) return; // not time for a frame, restart loop
//frameTime += frameInc;
// capture image
delay(100); // settling time. maybe more?
digitalWrite(2, HIGH);
delay(100); // 100ms pulse to trigger remote
digitalWrite(2, LOW);
delay(4000); // depends on how long CHDK takes. Might need to increase
// setup next one
// SOHCAHTOA
// SOHCAHTOA
// SOHCAHTOA
if (constantAngular) { // constant Angular Motion
rotateMove = rotateMove + rotsPerFrame;
targetAngle = rotateMove * 2.0 * pi / rotateMaximum;
targetBase = targetHeight / tan(targetAngle);
horizMove = (targetOrigin - targetBase) * stepsInch + 0.5;
} else { // constant Linear Motion
horizMove = horizStep + stepsPerFrame;
targetBase = targetOrigin - (horizMove / stepsInch);
targetAngle = atan2(targetHeight, targetBase);
rotateMove = rotateMaximum * targetAngle / 2.0 / pi + 0.5;
}
if ( horizMove > trackerMax || horizMove < trackerMin ) { // reached the end, shut it down
horizMove = horizStep;
rotateMove = rotateStep;
trackerRun = false;
}
}
if ( !trackerRun ) { // single motion mode
rotateStep = rotateStep % rotateMaximum;
rotateMove = rotateStep;
}
}
}