Skip to content

Commit 24ed23b

Browse files
authored
Merge pull request #8 from ClutchplateDude/master
V1.5.24 - Updates
2 parents 66ae59b + 9fd4644 commit 24ed23b

File tree

11 files changed

+215
-410
lines changed

11 files changed

+215
-410
lines changed

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
1515
=======================================================================================================================================
1616
*/
17-
String version = "V1.5.23";
17+
String version = "V1.5.24";
1818

1919
boolean north = true; // change this to 'false' if youre in the southern hemisphere
2020

21-
float speed = 1.000; // Use this value to slightly increase or decrese tracking speed. The values from the "CAL" menu will be added to this.
22-
2321
// The radius of the surface that the belt runs on (in V1 of the ring) was 168.24mm.
2422
// Belt moves 40mm for one stepper revolution (2mm pitch, 20 teeth).
25-
// RA wheel is 2 x PI x 168.24mm circumference = 1057.1mm
26-
// One RA revolution needs 26.43 (1057.1mm / 40mm) stepper revolutions
27-
// Which means 108245 steps (26.43 x 4096) moves 360 degrees
28-
// So there are 300.1 steps/degree (108245 / 360)
29-
int RAStepsPerDegree = 300; // adjust this value to calibrate RA movement
23+
// RA wheel is 2 x PI x 168.24mm (V2:180mm) circumference = 1057.1mm (V2:1131mm)
24+
// One RA revolution needs 26.43 (1057.1mm / 40mm) stepper revolutions (V2: 28.27 (1131mm/40mm))
25+
// Which means 108245 steps (26.43 x 4096) moves 360 degrees (V2: 115812 steps (28.27 x 4096)
26+
// So there are 300.1 steps/degree (108245 / 360) (V2: 322 (115812 / 360))
27+
28+
int RAStepsPerDegree = 300; // V1 Ring has a ridge that the belt runs on and the ring runs on the bearings
29+
// int RAStepsPerDegree = 322; // V2 Ring has belt in a groove and runs on bearings
3030

3131
// Belt moves 40mm for one stepper revolution (2mm pitch, 20 teeth).
3232
// DEC wheel is 2 x PI x 90mm circumference which is 565.5mm
@@ -39,6 +39,8 @@ int DECStepsPerDegree = 161; // Number of steps needed to move DEC motor 1 d
3939
// This code drives the steppers in halfstep mode for TRK and DEC, and full step for RA
4040
float StepsPerRevolution = 4096;
4141

42+
float speed = 1.000; // Use this value to slightly increase or decrese tracking speed. The values from the "CAL" menu will be added to this.
43+
4244
int RAspeed = 400; // You can change the speed and acceleration of the steppers here. Max. Speed = 600. High speeds tend to make
4345
int RAacceleration = 600; // these cheap steppers unprecice
4446
int DECspeed = 800;

Software/Arduino code/OpenAstroTracker/a_inits.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,14 @@ AccelStepper stepperDEC(HALFSTEP, motorPin11, motorPin13, motorPin12, motorPin14
5656
// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
5757
AccelStepper stepperTRK(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
5858

59-
// Use another AccelStepper to run the RA motor as well for use with Stellarium... hmmmm....
60-
AccelStepper stepperGUIDE(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
61-
6259
String inString = "";
6360

6461
bool inStartup = true; // Start with a guided startup
6562

6663
// Serial control variables
6764
bool inSerialControl = false; // When the serial port is in control
6865
bool serialIsSlewing = false; // When the serial port is slewing the tracker
66+
bool slewingToHome = false; // When the serial port is slewing to home/park.
6967
bool quitSerialOnNextButtonRelease = false; // Used to detect SELECT button to quit Serial mode.
7068
String logString;
7169
boolean isPulseGuiding = true;

Software/Arduino code/OpenAstroTracker/b2_daytime.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ class DayTime {
3535
hours = (int)(ms % 24);
3636
}
3737

38+
DayTime(float timeInHours) {
39+
hours = floor(timeInHours);
40+
timeInHours = (timeInHours - hours) * 60;
41+
mins = floor(timeInHours);
42+
timeInHours = (timeInHours - mins) * 60;
43+
secs = floor(timeInHours);
44+
}
45+
3846
int getHours() {
3947
return hours;
4048
}

Software/Arduino code/OpenAstroTracker/b_setup.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ void setup() {
3030
stepperDEC.setAcceleration(DECacceleration);
3131
stepperTRK.setMaxSpeed(10);
3232
stepperTRK.setAcceleration(2500);
33-
stepperGUIDE.setMaxSpeed(50);
34-
stepperGUIDE.setAcceleration(100);
3533

3634
// Read persisted values
3735
inputcal = EEPROM.read(0);

Software/Arduino code/OpenAstroTracker/c5_calcStepperPos.ino

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ void handleDECandRACalculations()
4444
// Can we get there without physical issues? (not doing anything with this yet)
4545
isUnreachable = ((targetRA != -moveRA) || (targetDEC != moveDEC));
4646

47+
// if (stepperRA.currentPosition() != int(targetRA)) {
48+
// Serial.println("Moving RA from " + String(stepperRA.currentPosition()) + " to " + targetRA);
49+
// }
50+
// if (stepperDEC.currentPosition() != (targetDEC)) {
51+
// Serial.println("Moving DEC from " + String(stepperDEC.currentPosition()) + " to " + targetDEC);
52+
// }
53+
4754
// Show time: tell the steppers where to go!
4855
stepperRA.moveTo(targetRA);
4956
stepperDEC.moveTo(targetDEC);
@@ -65,11 +72,10 @@ void doCalculations() {
6572
// Run speed for steppers is steps/second
6673
// What are these magic numbers??? 335.14? 288? 3590?
6774
//trackingSpeed = ((((335.1417 / 288.0) * StepsPerRevolution) / 3590)) - 1 + float(speedCalibration);
68-
69-
// The tracker simply needs to rotate at 15degrees/hour, adjusted for sidereal
75+
76+
// The tracker simply needs to rotate at 15degrees/hour, adjusted for sidereal
7077
// time (i.e. the 15degrees is per 23h56m04s. 3590/3600 is the same ratio).
71-
// And multiplied by 2 because TRK stepper is halfstepped, whereas RA stepper is fullstepped.
72-
trackingSpeed = speedCalibration * 2 * RAStepsPerDegree * 15.0f / 3590.0f;
78+
trackingSpeed = speedCalibration * RAStepsPerDegree * 15.0f / 3590.0f;
7379
stepperTRK.setSpeed(trackingSpeed);
7480

7581
RADisplayTime.set(RATime);

Software/Arduino code/OpenAstroTracker/c6_moveTo.ino

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,56 @@
11

2+
float currentRA() {
3+
float targetRA = RATime.getTotalHours();
4+
// Serial.print("TargetRA: " + String(targetRA, 4));
5+
if (!stepperRA.isRunning()) {
6+
return targetRA;
7+
}
8+
float degreesToGo = 1.0 * stepperRA.distanceToGo() / RAStepsPerDegree;
9+
// Serial.print(" Deg2Go: " + String(degreesToGo , 4));
10+
float hoursToGo = degreesToGo / 15.0;
11+
// Serial.print(" Hrs2Go: " + String(hoursToGo , 4));
12+
float currentHour = targetRA - hoursToGo;
13+
// Serial.println(" CurHrs: " + String(currentHour, 4));
14+
return currentHour;
15+
}
16+
17+
float currentDEC() {
18+
float targetDEC = 1.0 * degreeDEC + minDEC / 60.0 + secDEC / 3600.0;
19+
// Serial.print("TargetDEC: " + String(targetDEC, 4));
20+
if (!stepperDEC.isRunning()) {
21+
return targetDEC;
22+
}
23+
float degreesToGo = 1.0 * stepperDEC.distanceToGo() / DECStepsPerDegree;
24+
// Serial.print(" Deg2Go: " + String(degreesToGo , 4));
25+
float currentDegree = targetDEC - degreesToGo;
26+
// Serial.println(" CurDeg: " + String(currentDegree, 4));
27+
return currentDegree;
28+
}
29+
230
void displayStepperPosition() {
331
lcdMenu.setCursor(0, 1);
432
String disp ;
5-
if (totalDECMove > 0) {
33+
if (totalDECMove > 0) {
634
float decDist = 100.0 - 100.0 * abs(stepperDEC.distanceToGo()) / totalDECMove;
7-
sprintf(scratchBuffer, "DEC: %d%%", (int)decDist);
8-
//disp = "DEC:" + String((int)floor(decDist)) + "% ";
35+
// float dec = currentDEC();
36+
// DayTime dt(dec);
37+
// int degree = dt.getHours() + (north ? 90 : -90);
38+
// Serial.println("DEC: " + String(dec, 4) + " DT: " + String(degree) + " " + String(dt.getMinutes()) + " " + String(dt.getSeconds()));
39+
// sprintf(scratchBuffer, "D: %02d@%02d'%02d\" %d%%", degree, dt.getMinutes(), dt.getSeconds(), (int)decDist);
40+
sprintf(scratchBuffer, "D: %d%%", (int)decDist);
941
disp = String(scratchBuffer);
1042
}
1143
else {
1244
disp = "D:" + String(stepperDEC.currentPosition());
1345
}
1446
if (totalRAMove > 0) {
1547
float raDist = 100.0 - 100.0 * abs(stepperRA.distanceToGo()) / totalRAMove;
16-
sprintf(scratchBuffer, "RA: %d%%", (int)raDist);
48+
// float ra = currentRA();
49+
// DayTime dt(ra);
50+
// dt.addTime(HACorrection);
51+
// Serial.println("RA: " + String(ra, 4) + " DT: " + dt.ToString());
52+
// sprintf(scratchBuffer, "R: %02d@%02d'%02d\" %d%%", dt.getHours(), dt.getMinutes(), dt.getSeconds(), (int)raDist);
53+
sprintf(scratchBuffer, "R: %d%%", (int)raDist);
1754
disp = disp + String(scratchBuffer);
1855
}
1956
else {
@@ -108,7 +145,9 @@ void startMoveSteppersToTargetAsync() {
108145
totalRAMove = 1.0f * abs(stepperRA.distanceToGo());
109146
}
110147

111-
// Move stepper motors to target (non-blocking)
148+
// Move stepper motors to target (non-blocking).
149+
// Returns true if the motor is still running.
150+
// Returns false when the motors are stopped (reached target).
112151
bool moveSteppersToTargetAsync() {
113152
bool stillRunning = false;
114153
if (stepperDEC.isRunning() || stepperRA.isRunning()) {

Software/Arduino code/OpenAstroTracker/c70_menuRA.ino

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,78 @@
1+
bool movingToTarget = false;
2+
3+
void processRAKeys(int key)
4+
{
5+
switch (key)
6+
{
7+
case btnUP:
8+
{
9+
if (RAselect == 0)
10+
RATime.addHours(1);
11+
if (RAselect == 1)
12+
RATime.addMinutes(1);
13+
if (RAselect == 2)
14+
RATime.addSeconds(1);
15+
16+
// slow down key repetitions
17+
delay(150);
18+
waitForButtonRelease = false;
19+
}
20+
break;
21+
22+
case btnDOWN:
23+
{
24+
if (RAselect == 0)
25+
RATime.addHours(-1);
26+
if (RAselect == 1)
27+
RATime.addMinutes(-1);
28+
if (RAselect == 2)
29+
RATime.addSeconds(-1);
30+
31+
// slow down key repetitions
32+
delay(150);
33+
waitForButtonRelease = false;
34+
}
35+
break;
36+
37+
case btnLEFT:
38+
{
39+
RAselect = adjustWrap(RAselect, 1, 0, 2);
40+
}
41+
break;
42+
43+
case btnSELECT:
44+
{
45+
if (movingToTarget) {
46+
stopSteppers();
47+
}
48+
else {
49+
startMoveSteppersToTargetAsync();
50+
}
51+
movingToTarget = !movingToTarget ;
52+
}
53+
break;
54+
55+
case btnRIGHT:
56+
{
57+
lcdMenu.setNextActive();
58+
}
59+
break;
60+
}
61+
62+
if (movingToTarget) {
63+
if (!moveSteppersToTargetAsync()) {
64+
movingToTarget = false;
65+
}
66+
}
67+
}
68+
69+
void printRASubmenu() {
70+
if (!movingToTarget) {
71+
lcdMenu.printMenu(formatRA(&RADisplayTime, RAselect));
72+
}
73+
}
74+
75+
176
/*
277
WIP for complete OO-ification of code.
378
@@ -134,62 +209,3 @@
134209
}
135210
};
136211
*/
137-
138-
void processRAKeys(int key)
139-
{
140-
switch (key)
141-
{
142-
case btnUP:
143-
{
144-
if (RAselect == 0)
145-
RATime.addHours(1);
146-
if (RAselect == 1)
147-
RATime.addMinutes(1);
148-
if (RAselect == 2)
149-
RATime.addSeconds(1);
150-
151-
// slow down key repetitions
152-
delay(150);
153-
waitForButtonRelease = false;
154-
}
155-
break;
156-
157-
case btnDOWN:
158-
{
159-
if (RAselect == 0)
160-
RATime.addHours(-1);
161-
if (RAselect == 1)
162-
RATime.addMinutes(-1);
163-
if (RAselect == 2)
164-
RATime.addSeconds(-1);
165-
166-
// slow down key repetitions
167-
delay(150);
168-
waitForButtonRelease = false;
169-
}
170-
break;
171-
172-
case btnLEFT:
173-
{
174-
RAselect = adjustWrap(RAselect, 1, 0, 2);
175-
}
176-
break;
177-
178-
case btnSELECT:
179-
{
180-
moveSteppersToTarget();
181-
}
182-
break;
183-
184-
case btnRIGHT:
185-
{
186-
lcdMenu.setNextActive();
187-
}
188-
break;
189-
}
190-
}
191-
192-
void printRASubmenu()
193-
{
194-
lcdMenu.printMenu(formatRA(&RADisplayTime, RAselect));
195-
}

Software/Arduino code/OpenAstroTracker/c71_menuDEC.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
bool movingToTarget = false;
21

32
void processDECKeys(int key) {
43

Software/Arduino code/OpenAstroTracker/c725_menuHOME.ino

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
void processHomeKeys(int key) {
22
switch (key) {
33
case btnSELECT: {
4-
// TRK stepper is half-stepped so we divide the steps by two to get full steps, which is what RA is stepped at.
5-
tracking = 0;
6-
stepperRA.moveTo(0 - stepperTRK.currentPosition() / 2);
7-
stepperDEC.moveTo(0);
8-
9-
moveSteppersToTarget();
10-
11-
// Set TRK stepper position to start counting from here again
12-
stepperTRK.setCurrentPosition(0);
13-
stepperRA.setCurrentPosition(0);
14-
tracking = 1;
15-
16-
// In order for RA coordinates to work correctly, we need to
17-
// offset HATime by elapsed time since last HA set.
18-
unsigned long elapsedMs = millis() - lastHAset;
19-
HATime.addSeconds(elapsedMs / 1000);
20-
lastHAset = millis();
4+
moveToHomePositionsAsync() ;
5+
while (moveSteppersToTargetAsync()) {
6+
}
7+
moveToHomePositionCompleted();
218
}
229
break;
2310

@@ -26,6 +13,38 @@ void processHomeKeys(int key) {
2613
}
2714
break;
2815
}
16+
17+
}
18+
19+
// Calculate the target RA, DEC and HA adjustments that need to be made and set the motor targets.
20+
void moveToHomePositionsAsync() {
21+
tracking = 0;
22+
float trackedSeconds = stepperTRK.currentPosition() / trackingSpeed; // steps/steps/s
23+
// Serial.println("Pos: " + String(stepperTRK.currentPosition()) + " Secs:" + String(trackedSeconds , 3));
24+
25+
// In order for RA coordinates to work correctly, we need to
26+
// offset HATime by elapsed time since last HA set and also
27+
// adjust RA by the elapsed time and set it to zero.
28+
RATime.set(0, 0, 0);
29+
RATime.addSeconds(trackedSeconds);
30+
HATime.addSeconds(trackedSeconds);
31+
HACorrection.set(HATime);
32+
HACorrection.addTime(-h, -m, -s);
33+
lastHAset = millis();
34+
35+
// Set DEC to 90degrees
36+
degreeDEC = minDEC = secDEC = 0;
37+
38+
// Calculate new RA stepper target (and DEC)
39+
handleDECandRACalculations();
40+
}
41+
42+
// This must be called when the move to home is completed.
43+
void moveToHomePositionCompleted() {
44+
// Set TRK stepper position to start counting from here again
45+
stepperTRK.setCurrentPosition(0);
46+
stepperRA.setCurrentPosition(0);
47+
tracking = 1;
2948
}
3049

3150
void printHomeSubmenu() {

0 commit comments

Comments
 (0)