-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotosphere-maker.ino
148 lines (124 loc) · 2.82 KB
/
photosphere-maker.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
#include <AccelStepper.h>
#include <Servo.h>
#define stepsPerRev 2048.0 // 4096
#define outerTeeth 107.0
#define innerTeeth 15.0
#define servoOffset 40
AccelStepper pan(AccelStepper::FULL4WIRE, 8, 10, 9, 11);
Servo servoL;
Servo servoR;
struct Step {
float deg;
float tiltAngle;
int delayMs;
};
float stepsPerTTRev;
int step = 0;
bool started = false;
void setup() {
Serial.begin(9600);
float ratio = outerTeeth / innerTeeth;
stepsPerTTRev = stepsPerRev * ratio;
pan.setCurrentPosition(0);
pan.setMaxSpeed(350.0);
pan.setAcceleration(100.0);
servoL.attach(6);
servoR.attach(7);
servoL.write(90);
servoR.write(90);
delay(2000);
servoL.detach();
servoR.detach();
delay(10000);
Start();
}
// Yes, yes. We could create a complicated loop to step through the steps,
// but this is way more understandable.
#define TOTAL_STEPS 33
Step steps[] = {
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ 30.0, 90 },
{ -10.0, 55 }, // Offset slightly to align with the 'dot'
{ 40.0, 55 },
{ 40.0, 55 },
{ 40.0, 55 },
{ 40.0, 55 },
{ 40.0, 55 },
{ 40.0, 55 },
{ 40.0, 55 },
{ 40.0, 55 },
{ 10.0, 55 }, // Offset slightly to misalign with the 'dot'! This is so we can get a nice still image after tilting.
{ -10.0, 125 }, // Now align again. With new tilt value.
{ 40.0, 125 },
{ 40.0, 125 },
{ 40.0, 125 },
{ 40.0, 125 },
{ 40.0, 125 },
{ 40.0, 125 },
{ 40.0, 125 },
{ 360.0, 23 },
{ 360.0, 157 }
};
void Tilt(int angle) {
Serial.print("Tilt: ");
Serial.println(angle);
servoL.write(abs(angle - 180));
servoR.write(angle);
}
void Pan(float angle) {
Serial.print("Pan: ");
Serial.println(angle);
float req = (stepsPerTTRev / 360.0) * angle;
pan.move(req);
}
void Stop() {
started = false;
step = 0;
pan.stop();
Tilt(steps[step].tiltAngle);
delay(1500);
servoL.detach();
servoR.detach();
Serial.println("Stopped");
}
void Start() {
started = true;
servoL.attach(6);
servoR.attach(7);
Tilt(steps[step].tiltAngle);
Pan(steps[step].deg);
}
void loop() {
pan.run();
while (Serial.available() > 0) { // Something is in the serial buffer
String str = Serial.readString();
if (str == "stop") {
Stop();
}
if (str == "start") {
Start();
}
}
if (started == true) {
if (abs(pan.distanceToGo()) > 0) { return; } // Still need to move
delay(100);
step++; // Movement done do next move
if (step > TOTAL_STEPS) { return Stop(); } // Reached the end
Serial.print("Step: ");
Serial.print(step);
Serial.print(" - ");
Serial.println(TOTAL_STEPS);
Tilt(steps[step].tiltAngle);
Pan(steps[step].deg);
Serial.println("");
}
}